CS241: Spring 2017 -- Theta, n^2 sorts, and Fibonacci

  1. Quiz!
  2. pseudo-code
    1. selection sort -- Idea: for i from top to bottom, find the element that goes at i, then swap it there
                      for i=0..n-2 {
                          find the index of the element that belongs at list[i]*
                          swap it there
                      }
      
                      *finding the index: given int[] list, int findIndexOfWhatGoesHere
                      maxIndex = findIndexOfWhatGoesHere;
                      for i=findIndexOfWhatGoesHere..n-1
                          if list[i] > list[maxIndex]
                              maxIndex = i;
                          
    2. insertion sort -- Idea: start with a list of length one. Given an ordered list, add each element, one at a time, preserving order
                      for i=1..n-1 {
                          goesHereIndex = find the index where list[i] belongs*
                          move the elements from goesHereIndex..i-1 down one (to make space for list[i]) (put list[i] in your pocket first!)
                          list[goesHereIndex] = pocket
                      }
                          
                      *finding the location is a sorted list where a particular new value, v, goes (assuming biggest value at the top)
                      for (i=0..end of list)
                          if (v > list[i])
                              return i;
                      return end of list
                          
  3. Conway's leftovers?
    1. Running until the state is constant, or alternating -- how to?
    2. Primitives and Objects; what's the difference?
    3. Deep copy/shallow copy
    4. Example
  4. ArrayList vs. array
  5. You can trade space for time (and vice-versa). E.g. calculating Fibonacci numbers.
  6. Problem: evaluate an arbitrary infix expression.
  7. How could you modify your Conway's Life program so it could handle larger scenarios... like 1,000,000 x 1,000,000?