Heapsort
We will sort the array A[0..n-1] in-place
Build a heap in-place
For i = n-1 to 1
A[i] := delete-max;
25
10
15
12
7
8
3
2
5
9
0 1 2 3 4 5 6 7 8 9
15
10
12
9
7
8
3
2
5
25
12
10
9
5
7
8
3
2
15
25
10
8
9
5
7
2
3
12
15
25
9
8
7
5
2
10
3
12
15
25
Invariants
Heap
Sorted
<
Williams 1964
Previous slide
Next slide
Back to first slide
View graphic version