Heap Sort
Heap Sort
STRUCTURES
MAHESH GOYANI
MAHATMA GANDHI INSTITUE OF TECHNICAL EDUCATION & RESEARCH CENTER
[email protected]
The root of the binary tree holds the largest key in the heap. This type of
heap is usually called Descending Heap or Mere Heap or Max Heap.
74
33
42
67
42
33
67
44
42
33
44 42
49
67
74
49
23 44
33 42
49 49
74
23 74
PAR = LOC / 2
HA [LOC] = DATA
Exit
HA [1] = DATA
Exit
10 10
20 80 20 80
40 60 85 99 40 60 85 99
50 700 65 50 700 65 15
20 80 15 80
40 60 85 99 40 20 85 99
50 700 65 15 50 700 65 60
16
5 11
3 18
16
18 11
3 5 18
16 11
10
20 80
40 60 85 99
50 700 65
10 65
20 80 20 80
40 60 85 99 40 60 85 99
50 700 65 50 700 65
65 20
20 80 40 80
40 60 85 99 50 60 85 99
700 50 700 65
11 26 14 2 19 32 7
32
26 19
11 7 14 2
32
26 19
11 7 14 2
32
19
26 14
11 7 2
32
26
19 14
11 7 2
32 26
19 14
11 7 2
32 26
14
19 2
11 7
32 26
19
14 2
11 7
32 26 19
14 2
11 7
The heap sort is the slowest of the O(n log n) sorting algorithms
But unlike the merge and quick sorts it doesn't require massive recursion
or multiple arrays to work. This makes it the most attractive option for very large
data sets of millions of items.