The GATE Grind

GATE 2020 CS – Question 57

Programming and Data Structures · Binary Heaps · 2 marks · Numerical answer

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 ______.

Practise this question in The GATE Grind →

Show answer and explanation

Correct answer: 511 to 511

Explanation

In a min-heap the maximum must be a leaf. With 1023 elements there are 512 leaves, and finding the maximum among 512 items takes 511 comparisons.