Question
Consider a binary tree that has 200 leaf nodes. Then, the number of nodes in that have exactly two children are _____.
Official answer and solution
- Official answer
- 199
- From
- Official GATE 2015 answer key
Solution
Apply the fundamental binary tree relation between the number of leaves and the number of degree-2 nodes.
In any binary tree :
- Let be the number of leaf nodes (nodes with 0 children).
- Let be the number of nodes with exactly 1 child.
- Let be the number of nodes with exactly 2 children.
- Let be the total number of nodes: .
Every node except the root has exactly one incoming edge, so the total number of edges is:
Alternatively, counting edges by the outgoing degree of each parent node:
Equating the two expressions for :
Given leaf nodes:
Thus, the number of nodes in that have exactly two children is 199.
199
Assuming the tree must be strictly full or complete, whereas the identity n2 = n0 - 1 holds universally for every binary tree.
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2015 Computer Science and Information Technology (CS) Session 3
- Question
- 35 of 65, printed as CS Q.25
- Section
- Computer Science and Information Technology
Report an error in this question
GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.