GateAI
Binary Heaps

GATE CSE 2015 Set 1 · Q32

MCQ2 marksMedium

Time

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

GATE CSE 2015 Set 1 Q32 diagram

Select one answerSingle correct

Pick an option to check

Solution

Step-by-step verified solution

Official answer: B) 40, 35, 20, 10, 30, 16, 17, 8, 4, 15

Binary Heaps

To insert an element into a binary max-heap stored in a 1-indexed array:

  1. Initial Array: [40, 30, 20, 10, 15, 16, 17, 8, 4] with size n=9n = 9.

  2. Append the new element: Insert 3535 at index 1010:

    Array[10]=35\text{Array}[10] = 35
  3. Up-heapify (Bubble-up):

    • Compare with its parent at index ⌊10/2⌋=5\lfloor 10/2 \rfloor = 5 (which has value 1515): Since 35>1535 > 15, swap Array[10]\text{Array}[10] and Array[5]\text{Array}[5]. Now Array[5]=35\text{Array}[5] = 35 and Array[10]=15\text{Array}[10] = 15.

    • Compare with its new parent at index ⌊5/2⌋=2\lfloor 5/2 \rfloor = 2 (which has value 3030): Since 35>3035 > 30, swap Array[5]\text{Array}[5] and Array[2]\text{Array}[2]. Now Array[2]=35\text{Array}[2] = 35 and Array[5]=30\text{Array}[5] = 30.

    • Compare with its new parent at index ⌊2/2⌋=1\lfloor 2/2 \rfloor = 1 (which has value 4040): Since 35≤4035 \le 40, the max-heap property is satisfied, and the process terminates.

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

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

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

Where do you stand for GATE?

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.

One GATE CSE PYQ every morning

An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.

Binary Heaps in GATE CSE

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 Heaps

More from GATE CSE 2015 Set 1

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2015 Set 1 · Q32 · MCQ

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

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.