Consider a binary tree in which every node has either zero or two children. Let be the number of nodes in .
Which ONE of the following is the number of nodes in that have exactly two children?
View worked solution
Answer: B
In a binary tree , let:
- be the number of leaf nodes (nodes with children)
- be the number of nodes with exactly child
- be the number of nodes with exactly children
According to the problem, every node in has either zero or two children. Therefore, the number of nodes with exactly one child is:
The total number of nodes is given by:
For any binary tree, the relationship between the number of leaf nodes () and the number of nodes with two children () is always:
Substituting Equation 2 into Equation 1, we get:
Thus, the number of nodes with exactly two children is .
Free practice · Your answers on this page are not saved.
