GATE / CS ARCHIVE

GATE CSE 2015 SET 3 / QUESTION 21

GATE CSE 2015 Set 3 Q21

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

GATE 2015 Set 3, Q21 1 mark · NAT
Report issue

Tree Properties & Traversals

Question 21, GATE 2015: A binary tree T has 200 leaf nodes. How many nodes in T have exactly two children? Nodes with exactly one child are allowed.
Tap to enlarge
Answer & solution

Official answer: 199

1. Let n0,n1,n2 count nodes with zero, one and two children. Every non-root node contributes one incoming edge, so E=n0+n1+n2−1. Counting edges from parents instead gives E=n1+2n2; subtracting cancels n1 and yields the result without assuming a full binary tree.

2. Counting tree edges gives n1+2n2=n0+n1+n2−1. Hence the number with two children is n2=n0−1=200−1=199.

Original paper, page 60 · Answer key