Heap Sort
Builds a max heap, then repeatedly extracts the maximum to produce sorted order.
0 elements
>Ready — Heap Sort
Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Analysis
BEST O(n log n)
AVG O(n log n)
WORST O(n log n)
SPACE O(1)
Heap Sort builds a max heap (every parent larger than its children), then repeatedly swaps the root to the end and re-heapifies. Guarantees O(n log n) with O(1) extra space.