0
21kviews
Sort the following data in descending order using Heap sort 20, 14, 50, 3, 5, 7, 11, 8, 12, 15 Show all the steps. Write an algorithm for heap sort.

Mumbai University > Information Technology > Sem 3 > Data Structure and Algorithm analysis

Marks: 10 M

Year: Dec 2014

1 Answer
0
1.2kviews

Heap sort is made up of two phases:

Phase 1: Build a heap using the given elements.

Phase 2: Continuous deletion of root element from the heap.

As we know that in a max-heap, the root element is always the maximum value element of the heap, so after every deletion we would be obtaining the new maximum value at the top.

enter image description here

enter image description here

Phase 2:  (The nodes deleted will be the descending order heap-sort)

Phase 2: (The nodes deleted will be the descending order heap-sort)

enter image description here

enter image description here

(Note: Do not go by the length of this sum. Understand the method and you can do it very quickly.)

Algorithm for Heap Sort:

Step 1: For k= 0 to N-1 (where N is the number of values)

Insert_into_heap(arr,N, arr[k])

Step 2: Repeat while N>0

Delete_from_heap (arr,N);

Increase N by 1;

Step 3: END

Please log in to add an answer.