Questions: Heapsort

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

What is the time complexity of the heap-building phase in heapsort (transforming an unsorted array into a max-heap)?

AO(n log n) — each of the n elements must be sifted through up to log n levels
BO(n) — most nodes are near the bottom of the heap with little or no sifting required
CO(n²) — each element must be compared against all previously inserted elements
DO(log n) — only the root requires a full sift-down
Question 2 Multiple Choice

Heapsort guarantees O(n log n) worst-case performance. Why do many standard library sort implementations use quicksort-based algorithms instead?

AQuicksort has better average-case complexity than O(n log n)
BHeapsort's access pattern causes frequent cache misses, making it slower in practice despite its better worst-case guarantee
CQuicksort is in-place while heapsort requires O(n) auxiliary space
DHeapsort is less numerically stable than quicksort for floating-point keys
Question 3 True / False

Heapsort is a stable sorting algorithm — equal elements preserve their relative order from the input in the sorted output.

TTrue
FFalse
Question 4 True / False

Heapsort's extraction phase runs in O(n log n) because each of the n−1 extract-max operations requires an O(log n) sift-down.

TTrue
FFalse
Question 5 Short Answer

Explain why heapsort's O(n log n) worst-case guarantee comes with a real-world performance cost, using the concept of cache locality.

Think about your answer, then reveal below.