Lecture 06: Practice Problems

1. Min-Heap or Max-Heap?

If array A = [1, 2, 3, 4, 5], is it a Max-Heap?

Show Answer

No.

A[1]=1. Children are 2, 3. Both are larger. This is actually a Min-Heap!

2. Heapsort Stability

Is Heapsort stable?

Show Answer

No.

The structure of the heap does not preserve the order of equal elements during build or extraction.

3. Top-k Complexity

What is the complexity of finding the k largest numbers in an unsorted array of size n?

Show Answer

O(n log k).

Iterate through n elements. Maintain a Min-Heap of size k. Operations take log k.