Skip to content
Official PYQ · 1995

GATE CS 1995 Q1.17 — Trees

Explain with AI

A binary tree TT has nn leaf nodes. The number of nodes of degree 22 in TT is

Choose one option
View worked solution

Answer: B

In any binary tree, let:

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

The total number of nodes NN in the tree is:

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

Since a tree with NN nodes has exactly N−1N - 1 edges, and each edge connects a parent to its child, we can also count the edges by summing the outgoing degrees of all nodes:

E=0⋅n0+1⋅n1+2⋅n2=n1+2n2E = 0 \cdot n_0 + 1 \cdot n_1 + 2 \cdot n_2 = n_1 + 2n_2

Equating the two expressions for the number of edges (E=N−1E = N - 1):

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

Subtracting n1+n2n_1 + n_2 from both sides simplifies to:

n2=n0−1n_2 = n_0 - 1

Given that the number of leaf nodes n0=nn_0 = n, the number of nodes of degree 22 is:

n2=n−1n_2 = n - 1

Therefore, the correct option is B.

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

Published
Report a correction
Keep exploringMore Trees questions