The Heapsort Algorithm
- Can be made more efficient
- Start with a sequence of values in an array and "fixing the heap" iteratively
- First fix small subtrees into heaps, then fix larger trees
- Trees of size 1 are automatically heaps
- Begin the fixing procedure with the subtrees whose roots are located in the next-to-lowest level of the tree
- Generalized fixHeap method fixes a subtree with a given root index:
void fixHeap(int rootIndex, int lastIndex)