CS241: n-ary trees & game trees

  1. In the news just in case you don't know the world is changing...
  2. Tree sort or heap sort questions?
  3. Where are we? ...
  4. How to master the material
    1. Algorithms
      1. Internalize the concept (e.g. divide the list in two, big things on the right, little things on the right)
      2. Choose a representation (data structure)
      3. Understand the details (e.g. chose a pivot, use two indices, one at the pivot (which is either just to the left of the known small elements, or just to the right of the known big elements), the other just to the center of the "other" known region)
      4. Write (and test!) the code.
    2. Data structures
      1. Internalize the concept (e.g. a binary tree is either empty or...)
      2. Choose a representation (e.g. a heap is best represented as a list!)
      3. Understand the methods necessary to implement it
      4. Write (and test) the code!
    3. Theoretical analysis
      1. Internalize the definition (e.g. O(f(n))
      2. Understand what it implies (e.g. that O(n^2) means if you double n, running time will quadruple)
      3. Test sorts to see if the empirical results match up with the theoretical predictions.
  5. In-class group project? Implement a heap that extends AbstractHeap and implements Heapish; i.e.
    public class Heap extends AbstractHeap implements Heapish {...}
    Where those are defined as:
    public interface Heapish {
    
        public void insert(int x);
    
        public int removeRoot();
    
        public boolean isEmpty();
    }
    
    
    
    abstract class AbstractHeap {
        static final int MAX = 100;   
        protected int[] list = new int[MAX]; // the tree (so to speak)
        protected int insertIndex=1; // Next insert index - 0 is not used!
        
        AbstractHeap(){}  // to avoid errors in Heap constructors
    
        int parent(int currentIndex) {
            return currentIndex / 2;
        }
    
        int leftChild(int currentIndex) {
            return currentIndex * 2;
        }
    
        int rightChild(int currentIndex) {
            return leftChild(currentIndex) + 1;
        }
    }
  6. n-ary trees