Consider a complete binary tree where the left and the right subtrees of the root are max-heaps. The lower bound for the number of operations to convert the tree to a heap is
Topic-wise GATE CS PYQs with verified steps
GATE CSE 2015 Set 2 · Q17
Time
Select one answerSingle correct
Solution
Official answer: A) (log n)
Binary HeapsIn a complete binary tree where both the left and right subtrees of the root already satisfy the max-heap property, converting the whole tree into a max-heap requires performing a single max-heapify (or sift-down) operation at the root:
The height of a complete binary tree with nodes is .
In the worst case (e.g., when the value at the root is smaller than all elements in both subtrees), the root element must be sifted down along a path from the root to a leaf node.
The number of level comparisons and swaps along this path is proportional to the tree height , requiring operations.
Hence, the lower bound for the number of operations in the worst case is (Option A).
Try the question first, then check your work.
Examiner trap
Only the root violates the heap property; converting it to a heap requires a single heapify operation along the height of the complete binary tree.
This Binary Heaps previous year question is Q17 of the GATE CSE 2015 Set 2 paper. Find more GATE CSE PYQs on Binary Heaps in Programming and Data Structures, or browse all GATE CSE PYQs.
Free diagnostic
Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related Binary Heaps PYQs now with no account.
An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.
Binary Heaps has 15 GATE CSE PYQs across 13 papers from 2011 to 2026. 6 of them are 1-mark MCQs like this one, and it is the only one in GATE CSE 2015 Set 2.
How GATE tests Binary HeapsIndependent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.