Skip to content
Official PYQ · 2002

GATE CS 2002 Q2.9 — Trees

Explain with AI

The number of leaf nodes in a rooted tree of n nodes, with each node having 00 or 33 children is:

Choose one option
View worked solution

Answer: D

Let LL be the number of leaf nodes (nodes with 00 children) and II be the number of internal nodes (nodes with 33 children).

The total number of nodes nn is the sum of leaf nodes and internal nodes:

n=L+I— (Equation 1)n = L + I \quad \text{--- (Equation 1)}

Since each internal node has exactly 33 children, the total number of children in the tree is 3I3I. In any rooted tree, every node except the root is a child of exactly one node. Therefore, the total number of nodes is also given by:

n=3I+1n = 3I + 1

Solving for II:

I=n−13— (Equation 2)I = \frac{n - 1}{3} \quad \text{--- (Equation 2)}

Substitute the value of II from Equation 2 into Equation 1:

n=L+n−13n = L + \frac{n - 1}{3}L=n−n−13L = n - \frac{n - 1}{3}L=3n−n+13=2n+13L = \frac{3n - n + 1}{3} = \frac{2n + 1}{3}

Thus, the number of leaf nodes is 2n+13\frac{2n+1}{3}.

Alternative Verification:

Consider a tree with just a root and its 33 children (n=4n = 4):

  • Number of leaf nodes L=3L = 3.
  • Substituting n=4n = 4 into the options:
    • Option A: 42=2\frac{4}{2} = 2
    • Option B: 4−13=1\frac{4-1}{3} = 1
    • Option C: 4−12=1.5\frac{4-1}{2} = 1.5
    • Option D: 2(4)+13=3\frac{2(4)+1}{3} = 3

Only Option D matches the correct count.

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

Published
Report a correction
Keep exploringMore Trees questions