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)
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)
ANSWER
The height of the Min-Heap storing 32 keys is .
Official answer: 5Source: Official answer key, GATE 2025 CS1 (IIT Roorkee)
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.
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.
We need the for which .
Check : the range is to . Since lies in , satisfies the bound.
Check : the range is to . Since , is ruled out.
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.
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