Skip to content
Related Articles
Open in App
Not now

Related Articles

Algorithms | Sorting | Question 9

Improve Article
Save Article
  • Difficulty Level : Hard
  • Last Updated : 22 Dec, 2021
Improve Article
Save Article

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 which has been called 2 times.

Quiz of this Question

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!