A binary tree T has n leaf nodes. The number of nodes of degree 2 in T is
1995
A binary tree T has n leaf nodes. The number of nodes of degree 2 in T is
- A.
log₂ n
- B.
n − 1
- C.
n
- D.
2ⁿ
Attempted by 269 students.
Show answer & explanation
Correct answer: B
In a binary tree, the number of nodes of degree 2 can be determined using the relationship between leaves and internal nodes.
Let L be the number of leaf nodes and I be the number of internal nodes (nodes with degree 2).
For any binary tree, the total number of edges is equal to the sum of degrees of all nodes divided by 2.
Each leaf contributes 0 to the degree sum, and each internal node of degree 2 contributes 2.
The total number of edges is also equal to the number of nodes minus 1.
Using these relationships, we can derive that the number of nodes of degree 2 is related to the number of leaves.
A video solution is available for this question — log in and enroll to watch it.