GATE | GATE CS 2020 | Question 57

Consider the array representation of a binary min-heap containing 1023 elements. The minimum number of comparisons required to find the maximum in the heap is _________ .

Note – This question was Numerical Type.
(A) 510
(B) 511
(C) 512
(D) 255


Answer: (B)

Explanation: In a Min-heap having n elements, there are ceil(n/2) leaf nodes.
So, there will be ceil(1023/2) = ceil(511.5) = 512 elements as external nodes.

Now, in general, to find maximum of n elements you need (n-1) comparisons.
Just compare first two and then select the larger and compare with next one, select the larger and compare with next one etc.

Therefore, we need 511 (=512 – 1) minimum number of comparisons required to find the maximum in the given heap.

Option (B) is correct.

Quiz of this Question

My Personal Notes arrow_drop_up
Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.