Skip to content
Official PYQ · 2025

GATE CS 2025 Set 2 Q3 — Trees

Explain with AI

​​​​Consider a binary tree TT in which every node has either zero or two children. Let n>0n>0 be the number of nodes in TT.

Which ONE of the following is the number of nodes in TT that have exactly two children?
 
Choose one option
View worked solution

Answer: B

In a binary tree TT, let:

  • n0n_0 be the number of leaf nodes (nodes with 00 children)
  • n1n_1 be the number of nodes with exactly 11 child
  • n2n_2 be the number of nodes with exactly 22 children

According to the problem, every node in TT has either zero or two children. Therefore, the number of nodes with exactly one child is:

n1=0n_1 = 0

The total number of nodes nn is given by:

n=n0+n1+n2=n0+n2— (Equation 1)n = n_0 + n_1 + n_2 = n_0 + n_2 \quad \text{--- (Equation 1)}

For any binary tree, the relationship between the number of leaf nodes (n0n_0) and the number of nodes with two children (n2n_2) is always:

n0=n2+1— (Equation 2)n_0 = n_2 + 1 \quad \text{--- (Equation 2)}

Substituting Equation 2 into Equation 1, we get:

n=(n2+1)+n2n = (n_2 + 1) + n_2 n=2n2+1n = 2n_2 + 1 2n2=n−12n_2 = n - 1 n2=n−12n_2 = \frac{n - 1}{2}

Thus, the number of nodes with exactly two children is n−12\frac{n-1}{2}.

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

Published
Report a correction
Keep exploringMore Trees questions