GATE / CS ARCHIVE

GATE CSE 2015 SET 2 / QUESTION 23

GATE CSE 2015 Set 2 Q23

Data Structures · Tree Properties & Traversals · Full GATE CSE 2015 Set 2 paper

GATE 2015 Set 2, Q23 1 mark · NAT
Report issue

Tree Properties & Traversals

Question 23, GATE 2015: A binary tree has 20 leaves. How many nodes have exactly 2 children?
Tap to enlarge
Answer & solution

Official answer: 19

Let n0, n1, n2 count nodes with 0, 1, 2 children. Counting edges gives n1+2n2=n0+n1+n2−1, so n2=n0−1=19, regardless of one-child nodes.

Let L, U, B count leaves, one-child nodes, and two-child nodes. The total nodes are L+U+B, and a tree has one fewer edges. Counting edges by parents instead gives U+2B. Equating U+2B=L+U+B−1 cancels U and gives B=L−1. Hence 20 leaves imply 19 two-child nodes, regardless of how many unary nodes occur.

Original paper, page 34 · Answer key