CS241: Spring 2015 -- Lecture 13, 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.