State after two extractions
Standard · Trace the algorithm · about 8 min
Heap sort runs on [6, 3, 8, 1, 9, 2, 7]. Build-heap gives [9, 6, 8, 1, 3, 2, 7].
Predict where the first max goes, then arrange the array after two rounds of swap and sift.
Example 1
Input:
{"values":[6,3,8,1,9,2,7]}
Output:
[7,6,2,1,3,8,9]
The built max-heap, before the first round.
Constraints
- The trace uses the array shown
Learn the idea first: Heap sort, a visual lesson.
More Heap sort problems
- Stability Warm-up
- Implement heap sort Standard
- The k largest values Standard
- Spot the bug: the heap that never shrinks Standard
- Sort nearly sorted data with a small heap Challenge