GateAI
Binary Heaps

GATE CSE 2023 · Q12

MCQ1 markEasy

Time

Which one of the following sequences when stored in an array at locations A[1],…,A[10]A[1], \ldots, A[10] forms a max-heap?

Select one answerSingle correct

Pick an option to check

Solution

Step-by-step verified solution

Official answer: B) 23, 17, 14, 7, 13, 10, 1, 5, 6, 12

Binary Heaps

In a 1-indexed binary max-heap stored in an array A[1…10]A[1 \dots 10], the max-heap property requires that for every child at index ii (2≤i≤102 \le i \le 10), its parent at index ⌊i/2⌋\lfloor i/2 \rfloor must satisfy:

A[⌊i/2⌋]≥A[i]A[\lfloor i/2 \rfloor] \ge A[i]

Equivalently, for each parent index ii:

  • Left child is at index 2i2i, so A[i]≥A[2i]A[i] \ge A[2i]

  • Right child is at index 2i+12i+1, so A[i]≥A[2i+1]A[i] \ge A[2i+1]

Let us check the given options:

  • Option A: A=[23,17,10,6,13,14,1,5,7,12]A = [23, 17, 10, 6, 13, 14, 1, 5, 7, 12] For i=3i = 3, A[3]=10A[3] = 10, its left child is A[6]=14A[6] = 14. Since A[6]>A[3]A[6] > A[3] (14>1014 > 10), the max-heap property is violated.

  • Option B: A=[23,17,14,7,13,10,1,5,6,12]A = [23, 17, 14, 7, 13, 10, 1, 5, 6, 12] Checking all parent-child relationships:

    • i=1i = 1: A[1]=23≥A[2]=17A[1] = 23 \ge A[2]=17 and A[1]=23≥A[3]=14A[1] = 23 \ge A[3]=14

    • i=2i = 2: A[2]=17≥A[4]=7A[2] = 17 \ge A[4]=7 and A[2]=17≥A[5]=13A[2] = 17 \ge A[5]=13

    • i=3i = 3: A[3]=14≥A[6]=10A[3] = 14 \ge A[6]=10 and A[3]=14≥A[7]=1A[3] = 14 \ge A[7]=1

    • i=4i = 4: A[4]=7≥A[8]=5A[4] = 7 \ge A[8]=5 and A[4]=7≥A[9]=6A[4] = 7 \ge A[9]=6

    • i=5i = 5: A[5]=13≥A[10]=12A[5] = 13 \ge A[10]=12

    All conditions are satisfied, so (B) is a valid max-heap.

  • Option C: A=[23,17,14,6,13,10,1,5,7,15]A = [23, 17, 14, 6, 13, 10, 1, 5, 7, 15] For i=5i = 5, A[5]=13A[5] = 13, its child is A[10]=15A[10] = 15. Since 15>1315 > 13, it violates the max-heap property.

  • Option D: A=[23,14,17,1,10,13,16,12,7,5]A = [23, 14, 17, 1, 10, 13, 16, 12, 7, 5] For i=4i = 4, A[4]=1A[4] = 1, its left child is A[8]=12A[8] = 12. Since 12>112 > 1, it violates the max-heap property.

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 Q12 of the GATE CSE 2023 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. 6 of them are 1-mark MCQs like this one, and GATE CSE 2023 has 2.

How GATE tests Binary Heaps

More from GATE CSE 2023

Share this solution

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

GateAI solution cardGATE CSE 2023 · Q12 · MCQ

Which one of the following sequences when stored in an array at locations A[1], , A[10] forms a max-heap?

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.