CS241: Spring 2017 -- Theta, bubble sort, and Fibonacci

  1. The big picture: what's the plan?
    1. Acquire Java programming skill, expertise in common algorithms and data structures
      ...by implementing various algorithms using various data structures
    2. Learn to analyze the running times of those algorithms
      ...and verify, empirically, that the theoretical analysis are correct.
  2. A silly (ridiculously slow) sort: random sort for a list of n elements
        while the list is out of order (ooo){
                int i = rand(n); 
                int j = rand(n); 
                swap the ith and jth values in the list
        }
            
  3. A simple (not quite as slow) sort: Bubble sort for a list of n elements
        iterate n-1 times {
            for the ith element (from first to last-1) {
                if (out of order (relative to the next element) 
                    swap ith and ith+1th values, ith and next value?
            }
        }
            
  4. How many operations will it take to bubble sort a list of n elements?
  5. What is the running time of an algorithm? How to talk about it explicitly.
    1. Theoretical: An intro to theta notation, by way of big-O notation.
      The running time of an algorithm, A, executed on input of length n, is denoted TAn.
      A is said to be O(f(n)) if there exist positive constants c, and n0 such that TAn < c * f(n), for all n > n0.
    2. Empirical: Time the algorithm!
  6. You can trade space for time (and vice-versa). E.g. calculating Fibonacci numbers.
  1. Quiz!
  2. Conway's life Lab 2
    1. debugging (why you want to write displayNbrs(), and how to)
    2. what else do you need to know?
  3. Example: magic squares (with clicks to highlight/switch rows/cols)
    1. mousePressed
    2. highlighting a square
    3. random walk
    4. initializing the members of the array -- avoid null pointer exceptions!!
  4. Hijacking the psvm Thread to do animation
  5. Using a JPanel with public void paintComponent(Graphics) inside a JFrame (with a BorderLayout!!) to get double buffering by default