CS241: Spring 2015 -- Lecture 16, selectionSort and DynamicProgramming

  1. What goes in an abstract class?
    1. Common variables - variables every subclass need
    2. Common methods - methods every subclass needs
    3. Abstract methods - methods every subclass must implement (since they are different in different subclasses)
    4. Constructors - if more than one subclass will do the same thing in constructors
  2. A lovely bug in selection sort (on testing, debugging, and following advice!)
        iterate n-1 times (i ranging from 0 to n-1) {
            swap ith and indexOfSmallest from i to n-1
            }
        }
    In more detail:
        iterate n-1 times (for i=0 to n-1) {
            indexOfSmallest = findSmallestFromIthDown(i)
            swap ith and indexOfSmallest from i to n-1
            }
        }
                    
        int findSmallestFromIthDown(int i) {
            ...
        }            
            
  3. Counting operations.
    1. bubble sort
    2. selection sort
    3. insertion sort
  4. You can trade space for time (and vice-versa). E.g. calculating Fibonacci numbers.