A binary tree T has 64 leaf nodes. The number of nodes of degree 2 in T is —
2022
A binary tree T has 64 leaf nodes. The number of nodes of degree 2 in T is —
- A.
64
- B.
log₂ 64
- C.
63
- D.
32
Attempted by 804 students.
Show answer & explanation
Correct answer: C
The correct option is C (63).
Explanation
In any binary tree, there is a strict relationship between the number of leaf nodes (nodes with 0 children) and the number of nodes with degree 2 (nodes with 2 children).
Let:
n₀ = number of leaf nodes (degree 0)
n₁ = number of nodes with exactly 1 child (degree 1)
n₂ = number of nodes with exactly 2 children (degree 2)
The total number of nodes (N) is:
N = n₀ + n₁ + n₂
In any tree, the total number of edges (E) is one less than the total number of nodes:
E = N - 1
Therefore,
E = n₀ + n₁ + n₂ - 1
We can also count edges based on the number of children:
Each degree 0 node contributes 0 edges.
Each degree 1 node contributes 1 edge.
Each degree 2 node contributes 2 edges.
Hence,
E = n₁ + 2n₂
Equating both expressions for E:
n₀ + n₁ + n₂ - 1 = n₁ + 2n₂
Subtracting n₁ and n₂ from both sides:
n₀ - 1 = n₂
Conclusion
For any binary tree:
n₂ = n₀ - 1
That is, the number of nodes with two children is always exactly one less than the number of leaf nodes.
Given:
n₀ = 64
Therefore:
n₂ = 64 - 1 = 63
Hence, the correct answer is C (63).