Skip to content
Official PYQ · 2015

GATE CS 2015 Set 3 Q25 — Trees

Explain with AI
Consider a binary tree T that has 200200 leaf nodes. Then the number of nodes in T that have exactly two children are ______.
View worked solution

Answer: 199

In any binary tree, there is a strict relationship between the number of leaf nodes (nodes with degree 0) and the number of nodes with exactly two children.

Let:

  • n0n_0 be the number of leaf nodes (nodes with 0 children)
  • n1n_1 be the number of nodes with exactly 1 child
  • n2n_2 be the number of nodes with exactly 2 children

The total number of nodes in the tree is:

N=n0+n1+n2N = n_0 + n_1 + n_2

Since every node except the root has exactly one incoming edge, the total number of edges in a tree with NN nodes is N−1N - 1. We can also count the edges by looking at the children of each node:

Total Edges=n1+2n2\text{Total Edges} = n_1 + 2n_2

Equating the two expressions for the total number of edges:

N−1=n1+2n2N - 1 = n_1 + 2n_2(n0+n1+n2)−1=n1+2n2(n_0 + n_1 + n_2) - 1 = n_1 + 2n_2

Simplifying the equation by subtracting n1+n2n_1 + n_2 from both sides:

n2=n0−1n_2 = n_0 - 1

Given that the number of leaf nodes n0=200n_0 = 200:

n2=200−1=199n_2 = 200 - 1 = 199

Thus, the number of nodes in TT that have exactly two children is 199.

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

Published
Report a correction
Keep exploringMore Trees questions