Best Case Running Time of HeapSort
For this question, we want to show that the best case running
time of HeapSort is Ω(n log n). That is, we want to
argue that there is no "lucky" case for HeapSort. In comparison,
InsertionSort has a lucky case: if the array is already sorted, then
InsertionSort runs in linear time. Your answer to this question should
convince others that there is no such "lucky" case for HeapSort.
Assume that the items we want to sort are all distinct and are valued 1,
..., n. Let BIG denote the bigger half of these numbers. That is,
BIG = { n/2, n/2 + 1, ..., n }.
Answer the following questions. Provide a brief explanation for each of your
answers.
- When will the items in BIG be removed from the heap
during the execution of HeapSort?
- Initially, how many items in BIG can be at the bottom
level of the heap, after the build heap phase of HeapSort?
(Recall that we are using a max heap.)
- Initially, how many items in BIG can be within the top
(log n)/4 levels of the heap, after the build heap
phase of HeapSort?
- Let X be the items in BIG which are neither in the
bottom level initially nor within the top (log n)/4
levels initially. At least how many items are in X?
- At least how much time will HeapSort spend on items in X?
- Argue that the best case running time of HeapSort
is lower bounded by Ω(n log n).