Skip to content
Official PYQ · 2025

GATE CS 2025 Set 1 Q25 — Binary Heaps

Explain with AI
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 T\text{T} stores 3232 keys. The height of T\text{T} is ___________. (Answer in integer)
View worked solution

Answer: 5:5

A Min-Heap is represented as a complete binary tree.

The height hh of a rooted tree is defined as the maximum number of edges from the root to any leaf node. For a complete binary tree with NN nodes, the height hh is given by the formula:

h=⌊log⁡2N⌋h = \lfloor \log_2 N \rfloor

Given that the Min-Heap TT stores N=32N = 32 keys:

h=⌊log⁡232⌋=⌊5⌋=5h = \lfloor \log_2 32 \rfloor = \lfloor 5 \rfloor = 5

Alternative Level-by-Level Verification:

We can determine the level of each node starting from the root at Level 0:

  • Level 0: 20=12^0 = 1 node (Cumulative total: 11)
  • Level 1: 21=22^1 = 2 nodes (Cumulative total: 33)
  • Level 2: 22=42^2 = 4 nodes (Cumulative total: 77)
  • Level 3: 23=82^3 = 8 nodes (Cumulative total: 1515)
  • Level 4: 24=162^4 = 16 nodes (Cumulative total: 3131)
  • Level 5: 11 node (Cumulative total: 3232)

Since the 32nd32^{\text{nd}} node resides at Level 5, the maximum path length from the root to this leaf node is 55 edges.

Thus, the height of the Min-Heap TT is 5.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Binary Heaps questions