Algorithms | Sorting | Question 9

Suppose we are sorting an array of eight integers using heapsort, and we have just finished some heapify (either maxheapify or minheapify) operations. The array now looks like this:
16 14 15 10 12 27 28
How many heapify operations have been performed on root of heap?
(A) 1
(B) 2
(C) 3 or 4
(D) 5 or 6


Answer: (B)

Explanation: In Heapsort, we first build a heap, then we do following operations till the heap size becomes 1.
a) Swap the root with last element
b) Call heapify for root
c) reduce the heap size by 1.

In this question, it is given that heapify has been called few times and we see that last two elements in given array are the 2 maximum elements in array. So situation is clear, it is maxheapify whic has been called 2 times.

Quiz of this Question




Recommended Posts:



0 Average Difficulty : 0/5.0
No votes yet.