We'll revisit heap sort when we cover a variety of sorting algorithms, a few labs from now.
A binary heap is not a binary search tree. Students sometimes confuse the two, however. A useful exercise is to list the differences and similarities between them. Below is a table, a start on this list. Work with your partner on extending it. (We assume for simplicity that the larger values are at the right of the BST and at the top of the heap.)
|always completely balanced||possibly unbalanced|
|max value is the root||max value is furthest right|
|min value can be at any leaf||min value is furthest left|
A table, by the way, is also a good way to organize the various choices for data structures and running times we've seen so far.
Submit the following files as
kAryHeapTest.java(JUnit tests for homework)
- HFJ: Chapter 16