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 ________?
Correct Answer:
511
Solution:
In min-heap maximum element is always present at one of the leaf nodes.
Since there are 1023 elements. So, there will be log2[1023] = 512 elements in the leaf of min-heap.
As the min-heap is stored in the array, In the worst case n-1 comparisons are required to search the element.
So, here (512-1) = 511 comparisons are required to find the maximum element.