Heap sort
A sorting algorithm that builds a heap and removes the root over and over. O(n log n) and in place.
Example
With a max-heap of [3, 9, 1], out come 9, 3 and 1, left at the end one by one: [1, 3, 9].
Test yourself: Heap sort
Heap sort
Heap sort builds a ___-heap to sort from smallest to largest.
The maximum comes out first and is left at the end of the array: in [5, 1, 3], 5 goes to index 2, then 3 to 1.
Heap sort
With the max-heap [9, 5, 7, 1], after heap sort's first round, 9 is at index ___.
It's swapped with the last, 1: [1, 5, 7, 9]. Then 1 is sunk in the 3-element heap: [7, 5, 1, 9].
Heap sort
Heap sort with 1,024 elements makes about ___ sinking rounds of up to 10 levels.
n − 1 rounds, each of up to log₂ 1,024 = 10 levels: at most about 10,230 steps, plus building.
0/3
â–¶ Play