Consider a max heap, represented by the array: 40, 30, 20, 10, 15, 16, 17, 8, 4. Now consider that a value 35 is inserted into this heap. After insertion, the new heap is
Topic-wise GATE CS PYQs with verified steps
GATE CSE 2015 Set 1 · Q32
Time

Select one answerSingle correct
Solution
Official answer: B) 40, 35, 20, 10, 30, 16, 17, 8, 4, 15
Binary HeapsTo insert an element into a binary max-heap stored in a 1-indexed array:
Initial Array:
[40, 30, 20, 10, 15, 16, 17, 8, 4] with size .
Append the new element: Insert at index :
Up-heapify (Bubble-up):
Compare with its parent at index (which has value ): Since , swap and . Now and .
Compare with its new parent at index (which has value ): Since , swap and . Now and .
Compare with its new parent at index (which has value ): Since , the max-heap property is satisfied, and the process terminates.
Final Array Representation:
40, 35, 20, 10, 30, 16, 17, 8, 4, 15
Therefore, option (B) is correct.
Try the question first, then check your work.
Examiner trap
Insert the new element at the next available position (index 10) and restore the max-heap property by repeatedly swapping it with its parent as long as it is greater than the parent.
This Binary Heaps previous year question is Q32 of the GATE CSE 2015 Set 1 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. 5 of them are 2-mark MCQs like this one, and it is the only one in GATE CSE 2015 Set 1.
How GATE tests Binary HeapsIndependent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.