You are on page 1of 6

Answer:

50000000, nlogn/10000, jn-4, 2n, nn-1

____________________

Question 2a
You have to build Min heap for the given array elements along with their respective array positions;
Array = { 2,4,7,6,9,12,8,14,30}
Solution:

4 7

6 9 8 12

14 30

Question 2b
You have to perform Heap sort on the tree that you have built in Q.No.2a. Illustrate all steps of Heap
sort one-by-one in sequential way. Also show all elements in sorted order in an array.

Solution:

Step-1:
Remove smallest number

6 7

14 9 8 12

30

Array = { 2,4,7,6,9,12,8,14,30}

Step: 2:

Remove smallest number

6
14 7

30 9 8 12

Array = { 2,4,7,6,9,12,8,14,30}

Step- 3:

Remove smallest number

14 8

30 9 12

Array = { 2,4,7,6,9,12,8,14,30}

Step-4:

Remove smallest number


8

14 12

30 9

Array = { 2,4,7,6,9,12,8,14,30}

Step-5:

Remove smallest number

14 12

30

Array = { 2,4,7,6,9,12,8,14,30}

Step-6:

Remove smallest number


12

14 30

Array = { 2,4,7,6,9,12,8,14,30}

Step-7:

Remove smallest number

14

30
Array = { 2,4,7,6,9,12,8,14,30}

Step: 8 Remove smallest number

30

Array = { 2,4,7,6,9,12,8,14,30}
Step 9: Remove 30’s node

Array = { 2,4,7,6,9,12,8,14,30}
And hence Array is sorted
_______________________

You might also like