Professional Documents
Culture Documents
Heap Sort
In this sorting algorithm we first build a heap using the
given elements
If we want to sort the elements in ascending order we
create a Min Heap
And to sort the element in descending order we create a Max
Heap
Once the heap is created we delete the root node from the
heap and put the last node in the root position and repeat the
steps till we have covered all the elements
2
Heap Sort
Note: when sorting in ascending pattern
3
Example
Sort the following given in ascending order
25 53 74 51 45 68 63 79 35 33
4
Heap Sort
Note: when sorting in descending pattern
5
Example
Sort the following given in Descending order
51 78 2 76 45 71 68 52 39 57
6
Activity:
Sort the given below in ascending and descending
using Heap Sort
23 2 8 14 25 11 12 0
8 15 0 33 13 1 42 5 39 56