2015-05-11 Heap

posted May 11, 2015, 11:56 AM by Samuel Konstantinovich   [ updated May 12, 2015, 4:38 AM ]
Goal: A heaping pile of datastructures. 

Homework (due Thursday in class)
A heap of int. 

Start with simple:

public MyHeap() -> creates a max heap
public MyHeap(boolean isMax) -> creates a max-heap when boolean is true, min-heap when the boolean is false
public String toString()
public int remove() -> remove the root and return the value  O(logn)
public void add(int) -> add the int to the heap  O(logn)
public int peek() -> return the value of the root but do not remove it.  O(1)

Don't use generics.