Leaves of a full binary tree — Aptitude Question
Leaves of a full binary tree: In a binary tree every node has either 0 or 2 children. If the tree contains 10… Answer and worked solution on CodeKairo.
- Topic: Data Structures & Algorithms
- Section: Programming MCQs
- Difficulty: Medium
- Time target: 75 seconds
Question
In a binary tree every node has either 0 or 2 children. If the tree contains 10 internal nodes, how many leaves does it have?
Options
- 9
- 10
- 11
- 20
Show the answer and the worked solution
Correct answer: C. 11
Worked solution
- Begin with a single node: 0 internal nodes and 1 leaf.
- Giving a leaf two children turns it into an internal node and adds two leaves, so each step adds 1 internal node and a net 1 leaf.
- After 10 such steps the tree has 10 internal nodes and 1 + 10 = 11 leaves, matching the rule that leaves exceed internal nodes by exactly one.
Answer: 11.
The idea
In a tree where every node has 0 or 2 children, L = I + 1 always holds, and the total node count 2I + 1 is therefore always odd. Both facts are worth carrying into the exam hall.
Shortcut. Count edges: 10 internal nodes with 2 children each give 20 edges, so 21 nodes in all, and 21 − 10 = 11 are leaves.
Common trap. 20 counts two leaves per internal node, forgetting that most of those children are themselves internal nodes.
All Data Structures & Algorithms questions · placement mock tests