Medium · O(n log n)
Heap Sort quiz
Answer the questions in your own time, change a pick whenever you like, then hand in to see your score and why each answer is right. Nothing is saved or sent.
Questions (10)
- Viewing
- Answered
- Not answered
In the array [7, 2, 9, 4, 3, 8, 1] viewed as a tree, which values are the children of the 9 at index 2?
heapSort runs on 7 values. In which order does its first phase call siftDown on roots?
What does [7, 2, 9, 4, 3, 8, 1] look like once the build phase is done?
From the heap [9, 4, 8, 2, 3, 7, 1], the sort phase swaps the root with the last value and calls siftDown(values, 0, 6). What is the array afterwards?
Why does the build loop start at floor(size / 2) - 1 instead of size - 1?
Building the heap bottom-up is O(n), not O(n log n). Why?
Which statement about heap sort's cost is true?
siftDown runs on [1, 7, 7] with size = 3. The two children are equal. What is the array afterwards?
Sort [2, 2, 1], labelling the equal values 2a (index 0) and 2b (index 1). In which order do they end up?
A priority queue backed by a binary heap pops its biggest item. Which steps does that take?
Progress
0 / 10 questions0%
10 questions left
Quiz details
- Total questions
- 10
- Answered
- 0
- Not answered
- 10
Take it further
- AnimationSorting
Heap Sort Animation
The array and the binary tree it stands for, side by side: every sink moves both at once, the heap shrinks and the sorted tail locks in
Free
