GateAI
Binary Heaps

GATE CSE 2015 Set 3 · Q19

MCQ1 markMedium

Time

Consider the following array of elements. ⟨89,19,50,17,12,15,2,5,7,11,6,9,100⟩\langle 89, 19, 50, 17, 12, 15, 2, 5, 7, 11, 6, 9, 100 \rangle The minimum number of interchanges needed to convert it into a max-heap is

Select one answerSingle correct

Pick an option to check

Solution

Step-by-step verified solution

Official answer: D) 3

Binary Heaps

Consider the 1-indexed array of size n=13n = 13:

A=[89,19,50,17,12,15,2,5,7,11,6,9,100]A = [89, 19, 50, 17, 12, 15, 2, 5, 7, 11, 6, 9, 100]

To build a max-heap using standard bottom-up heap construction, we run MAX-HEAPIFY on internal nodes from index i=⌊n/2⌋=6i = \lfloor n/2 \rfloor = 6 down to 11:

  1. At index 6 (value 15):

    • Left child is at index 1212 (value 99).

    • Right child is at index 1313 (value 100100).

    • The maximum among {15,9,100}\{15, 9, 100\} is 100100 at index 13.

    • Interchange 1: Swap A[6]A[6] and A[13]A[13].

    • Array becomes: [89,19,50,17,12,100,2,5,7,11,6,9,15][89, 19, 50, 17, 12, \mathbf{100}, 2, 5, 7, 11, 6, 9, \mathbf{15}]

  2. 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).

  3. At index 3 (value 50):

    • Left child is at index 66 (value 100100).

    • Right child is at index 77 (value 22).

    • The maximum is 100100 at index 6.

    • Interchange 2: Swap A[3]A[3] and A[6]A[6].

    • Array becomes: [89,19,100,17,12,50,2,5,7,11,6,9,15][89, 19, \mathbf{100}, 17, 12, \mathbf{50}, 2, 5, 7, 11, 6, 9, 15]

    • At index 6 (value 50), children are index 12 (value 9) and index 13 (value 15), which satisfies the max-heap property.

  4. At index 2 (value 19):

    • Children are index 4 (value 17) and index 5 (value 12): satisfies max-heap property (no swap).

  5. At index 1 (value 89):

    • Left child is at index 22 (value 1919).

    • Right child is at index 33 (value 100100).

    • The maximum is 100100 at index 3.

    • Interchange 3: Swap A[1]A[1] and A[3]A[3].

    • Array becomes: [100,19,89,17,12,50,2,5,7,11,6,9,15][\mathbf{100}, 19, \mathbf{89}, 17, 12, 50, 2, 5, 7, 11, 6, 9, 15]

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

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

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 it is the only one in GATE CSE 2015 Set 3.

How GATE tests Binary Heaps

More from GATE CSE 2015 Set 3

Share this solution

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

GateAI solution cardGATE CSE 2015 Set 3 · Q19 · MCQ

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

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