Question
A binary tree has 20 leaves. The number of nodes in having two children is _____.
Official answer and solution
- Official answer
- 19
- From
- Official GATE 2015 answer key
Solution
Apply the structural relation between leaves and degree-2 internal nodes in a binary tree.
Let be the total number of nodes in binary tree , and let denote the number of nodes with 0, 1, and 2 children, respectively.
The total number of nodes is:
Every node except the root has exactly one incoming edge, so the total number of edges is . The number of edges can also be counted from outgoing degrees:
Subtracting the two equations:
Given leaves:
19
Confusing the relation for general binary trees () with that for strictly full binary trees.
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 2
- Question
- 20 of 65, printed as CS Q.10
- 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.