GateAI
Binary Heaps

GATE CSE 2024 Set 1 · Q41

MCQ2 marksMedium

Time

An array [82, 101, 90, 11, 111, 75, 33, 131, 44, 93] is heapified. Which one of the following options represents the first three elements in the heapified array?

Select one answerSingle correct

Pick an option to check

Solution

Step-by-step verified solution

Official answer: D) 131, 111, 90

Binary Heaps

We use the standard bottom-up max-heap construction algorithm (1-based indexing).

Initial array of size n=10n = 10:

A=[−,82,101,90,11,111,75,33,131,44,93]A = [-, 82, 101, 90, 11, 111, 75, 33, 131, 44, 93]

Heapify is called on non-leaf nodes from index i=⌊10/2⌋=5i = \lfloor 10/2 \rfloor = 5 down to 11:

  1. i=5i = 5 (A[5]=111A[5] = 111):

    • Children: Left child A[10]=93A[10] = 93.

    • Since 111>93111 > 93, no swap needed.

  2. i=4i = 4 (A[4]=11A[4] = 11):

    • Children: Left child A[8]=131A[8] = 131, Right child A[9]=44A[9] = 44.

    • Largest is A[8]=131A[8] = 131. Swap A[4]A[4] and A[8]A[8].

    • Array becomes: [−,82,101,90,131,111,75,33,11,44,93][-, 82, 101, 90, \mathbf{131}, 111, 75, 33, \mathbf{11}, 44, 93].

  3. i=3i = 3 (A[3]=90A[3] = 90):

    • Children: Left child A[6]=75A[6] = 75, Right child A[7]=33A[7] = 33.

    • Since 90>7590 > 75 and 90>3390 > 33, no swap needed.

  4. i=2i = 2 (A[2]=101A[2] = 101):

    • Children: Left child A[4]=131A[4] = 131, Right child A[5]=111A[5] = 111.

    • Largest is A[4]=131A[4] = 131. Swap A[2]A[2] and A[4]A[4].

    • Heapify down at index 44: Children are A[8]=11,A[9]=44A[8] = 11, A[9] = 44. Since 101>44101 > 44, no further swap.

    • Array becomes: [−,82,131,90,101,111,75,33,11,44,93][-, 82, \mathbf{131}, 90, \mathbf{101}, 111, 75, 33, 11, 44, 93].

  5. i=1i = 1 (A[1]=82A[1] = 82):

    • Children: Left child A[2]=131A[2] = 131, Right child A[3]=90A[3] = 90.

    • Largest is A[2]=131A[2] = 131. Swap A[1]A[1] and A[2]A[2].

    • Heapify down at index 22: Children are A[4]=101,A[5]=111A[4] = 101, A[5] = 111. Largest is A[5]=111A[5] = 111. Swap A[2]A[2] and A[5]A[5].

    • Heapify down at index 55: Child is A[10]=93A[10] = 93. Largest is A[10]=93A[10] = 93. Swap A[5]A[5] and A[10]A[10].

    • Array becomes: [−,131,111,90,101,93,75,33,11,44,82][-, \mathbf{131}, \mathbf{111}, \mathbf{90}, 101, 93, 75, 33, 11, 44, 82].

The first three elements of the heapified array are 131, 111, 90, which corresponds to Option (D).

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 Q41 of the GATE CSE 2024 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 GATE CSE 2024 Set 1 has 2.

How GATE tests Binary Heaps

More from GATE CSE 2024 Set 1

Share this solution

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

GateAI solution cardGATE CSE 2024 Set 1 · Q41 · MCQ

An array [82, 101, 90, 11, 111, 75, 33, 131, 44, 93] is heapified. Which one of the following options represents the first three elements in the heapified array?

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.