Consider the following array of elements. 89, 19, 50, 17, 12, 15, 2, 5, 7, 11, 6, 9, 100 The minimum number of interchanges needed to convert it into a max-heap is
Topic-wise GATE CS PYQs with verified steps
GATE CSE 2015 Set 3 · Q19
Time
Select one answerSingle correct
Solution
Official answer: D) 3
Binary HeapsConsider the 1-indexed array of size :
To build a max-heap using standard bottom-up heap construction, we run MAX-HEAPIFY on internal nodes from index down to :
At index 6 (value 15):
Left child is at index (value ).
Right child is at index (value ).
The maximum among is at index 13.
Interchange 1: Swap and .
Array becomes:
At indices 5, 4:
Index 5 (value 12) with children index 10 (value 11) and index 11 (value 6): satisfies max-heap property (no swap).
Index 4 (value 17) with children index 8 (value 5) and index 9 (value 7): satisfies max-heap property (no swap).
At index 3 (value 50):
Left child is at index (value ).
Right child is at index (value ).
The maximum is at index 6.
Interchange 2: Swap and .
Array becomes:
At index 6 (value 50), children are index 12 (value 9) and index 13 (value 15), which satisfies the max-heap property.
At index 2 (value 19):
Children are index 4 (value 17) and index 5 (value 12): satisfies max-heap property (no swap).
At index 1 (value 89):
Left child is at index (value ).
Right child is at index (value ).
The maximum is at index 3.
Interchange 3: Swap and .
Array becomes:
At index 3 (value 89), children are index 6 (value 50) and index 7 (value 2), which satisfies the max-heap property.
Total number of interchanges required = 3.
Hence, the correct option is (D).
Try the question first, then check your work.
Examiner trap
Apply the bottom-up heapify procedure starting from the last non-leaf node up to the root node at index .
This Binary Heaps previous year question is Q19 of the GATE CSE 2015 Set 3 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 3.
How GATE tests Binary HeapsIndependent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.