GateAI
Binary Heaps

GATE CSE 2016 Set 2 · Q34

NAT2 marksMedium

Time

A complete binary min-heap is made by including each integer in [1,1023][1, 1023] exactly once. The depth of a node in the heap is the length of the path from the root of the heap to that node. Thus, the root is at depth 0. The maximum depth at which integer 9 can appear is _________.

Your answerNumerical answer

Enter a value to check

Solution

Step-by-step verified solution

Official answer: 8

Binary Heaps

A complete binary tree with N=1023=210−1N = 1023 = 2^{10} - 1 nodes has height h=log⁡2(1023+1)−1=9h = \log_2(1023 + 1) - 1 = 9, meaning nodes are located at depths from 00 to 99.

In a min-heap, every ancestor of a node containing value xx must have a value strictly less than xx.

For the integer 99:

  • The elements strictly smaller than 99 are {1,2,3,4,5,6,7,8}\{1, 2, 3, 4, 5, 6, 7, 8\}, which gives at most 88 distinct values.

  • Therefore, on any path from the root down to the node containing 99, there can be at most 88 ancestors.

Since each step in depth corresponds to one ancestor on the path to the root:

Maximum depth of 9=Maximum number of ancestors=8\text{Maximum depth of 9} = \text{Maximum number of ancestors} = 8

Because the heap has depth up to 9, depth 8 is present, and we can place values 1,2,3,4,5,6,7,81, 2, 3, 4, 5, 6, 7, 8 along the path at depths 0,1,2,3,4,5,6,70, 1, 2, 3, 4, 5, 6, 7 and place 99 at depth 88.

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 Q34 of the GATE CSE 2016 Set 2 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. 2 of them are 2-mark NAT questions like this one, and it is the only one in GATE CSE 2016 Set 2.

How GATE tests Binary Heaps

More from GATE CSE 2016 Set 2

Share this solution

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

GateAI solution cardGATE CSE 2016 Set 2 · Q34 · NAT

A complete binary min-heap is made by including each integer in [1, 1023] exactly once. The depth of a node in the heap is the length of the path from the root of the heap to that node. Thus, the root is at depth 0. The maximum depth at which integer 9 can appear 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.