Arrays and Algorithms


Slides

Slides Here!


Additional Info


In Class Exercises (ICEs)

Part 1: Parson's Problems: One Element At A Time Pattern

Parson's Problems are a type of exercise wherein you're given a jumbled up bunch of lines from a working program and you must rearrange them to recreate the original, working program.  There's some promising research that shows they can teach concepts well, and in less time than traditional code reading / code writing exercises.

We're going to try them here, before you go on to writing a JavaScript program.

  1. Getting used to a "Parsons's Problem"
    Start here.  The program you need to recreate is pretty small.  The real goal is for you to get used to using the Parson's Problem tool itself.
  2. Parson's Problem: Finding an element
    This is a full Parson's Problem for this topic (processing an array one at a time)
  3. Parson's Problem: Printing all the elements in an array

Part 2: Coding: One At A Time Pattern

Start with the example file that was explained in class ( OneAtATime.html ) and modify it so that the page has another textbox and another button.  Make sure that when the button is clicked your click function creates an array of 5-10 integers.  Make sure that some of the numbers appear a couple of times (i.e., make sure to intentionally duplicate some values)

Then, choose one (or more) of the following to do:

  1. Print all items that match the user's input exactly when the user clicks on the button.
    If the user types in 3, you should print out all the array elements that are 3, exactly.
  2. Print all items that do NOT match the user's input when the user clicks on the button.
    If the user types in 3, you should print out all the array elements that are NOT 3
  3. Print all items that are less than what the user entered.
  4. Printing everything within a given range:
    Add a second textbox, and make sure to clearly tell the user that one of the textboxes is for the 'low' end of the range, and the other is for the 'high'  (or 'top')  end of the range.
    Print all items that are between the two numbers that the user typed in.

Part 3: Parson's Problems: Accumulating State Pattern

  1. Parson's Problem: Finding the minimum
  2. Parson's Problem: Summing up all the elements in the array

Part 4: Coding: Accumulating State Pattern

Start with the example file that was explained in class ( AccumulateState.html ) and modify it so that the page does one or more of the following exercises

  1. Calculate the average of the numbers in the array
  2. Find the maximum value in the array
  3. Find the largest two values in the array
  4. Count how many times the largest value appears in the array
    (You may (or may not) need to go through the array a couple of times for this one)