IAE Academy

GATE 2025 CS1 Q.35: solution and answer

GATE 2025 · CS1Q.35 · 1 mark · NAT

The height of any rooted tree is defined as the maximum number of edges in the path from the root node to any leaf node.

Suppose a Min-Heap stores 32 keys. The height of is ______________.
(Answer in integer)

See the question in the paper

Answer and solution

ANSWER

The height of the Min-Heap storing 32 keys is .

Official answer: 5Source: Official answer key, GATE 2025 CS1 (IIT Roorkee)

  1. A Min-Heap storing 32 keys is implemented as a complete binary tree (the standard array-based heap representation), meaning every level is fully filled except possibly the last, which is filled left to right.

  2. For a complete binary tree of height (height = maximum number of edges on any root-to-leaf path), the number of nodes satisfies : the minimum occurs when the last level has just 1 node, the maximum when the last level is completely full.

  3. We need the for which .

  4. Check : the range is to . Since lies in , satisfies the bound.

  5. Check : the range is to . Since , is ruled out.

  6. Equivalently, , confirming the same result: levels through together hold nodes, so the node is the sole node on level , giving a root-to-leaf path of edges.

  7. So the height of the Min-Heap storing 32 keys is .

KEY IDEA

A binary heap is stored as a complete binary tree. For nodes, a complete binary tree of height (height = max edges on a root-to-leaf path) satisfies , equivalently .

WATCH OUT FOR

Confusing "height" (edges, 0 for a single node) with "number of levels" (which would give for ), or using the wrong bound direction () and getting .

From the GATE 2025 CS1 paper. Every question of this paper · Download the full paper · All 26 Trees & heaps questions, with notes

More Trees & heaps questions