Lecture 6
Learning objectives
After this class, you should be able to:
- Given an array, show how
HEAPSORT
will sort it, by showing the state of the heap after each step, using both array and pointer representations. You should be able to show the steps taken by theBUILD-MAX-HEAP
function too.- Analyze the time complexity of
HEAPSORT
. You should be able to analyze the time complexity ofBUILD-MAX-HEAP
too.- Prove the correctness of
HEAPSORT
, and other operations on heaps, using loop invariants.- Given a heap, show how each of the following operations execute, by showing the state of the heap after each step: (i)
HEAP-EXTRACT-MAX
, (ii)HEAP-INCREASE-KEY
, and (iii)MAX-HEAP-INSERT
.
Reading assignment
- Lectures 6-9 slides.
- Review heaps from Data Structures course (See CLR: Section 6.1 - 6.3)
- CLR: Sections 6.4 - 6.5.
- CLR: Section 7.3.
Exercises and review questions
- Questions on current lecture's material
- Exercise 6.4-1.
- Exercise 6.4-2.
- Exercise 6.5-1.
- Give an application for priority queues different from any mentioned in the text.
- Questions on next lecture's material
- (Post your solution on the discussion board) Give an example where quicksort takes the worst possible running time. (Hint: the partition sizes should be very unbalanced.)