Skip to content
Official PYQ · 2007

GATE CS 2007 Q12 — Trees

Explain with AI

The height of a binary tree is the maximum number of edges in any root to leaf path. The maximum number of nodes in a binary tree of height hh is:

Choose one option
View worked solution

Answer: C

The height of a binary tree is defined as the maximum number of edges from the root to any leaf node.

To maximize the number of nodes in a binary tree of height hh, the tree must be a perfect binary tree where every level is completely filled:

  • Level 00 (root level) has 20=12^0 = 1 node.
  • Level 11 has 21=22^1 = 2 nodes.
  • Level 22 has 22=42^2 = 4 nodes.
  • ...
  • Level hh has 2h2^h nodes.

The total maximum number of nodes NN is the sum of nodes at all levels from 00 to hh:

N=∑i=0h2i=20+21+22+⋯+2hN = \sum_{i=0}^{h} 2^i = 2^0 + 2^1 + 2^2 + \dots + 2^h

Using the formula for the sum of a geometric progression, we get:

N=2h+1−1N = 2^{h+1} - 1

Example: For a tree of height h=1h = 1, the maximum number of nodes is 21+1−1=32^{1+1} - 1 = 3 (a root with two children), which matches option C.

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

Published
Report a correction
Keep exploringMore Trees questions