GATE / CS ARCHIVE

GATE CSE 2019 / QUESTION 46

Expected distance between tree leaves

Data Structures · Tree Properties & Traversals · Full GATE CSE 2019 paper

GATE 2019, Q46 2 marks · NAT
Report issue

Tree Properties & Traversals

Question 46, GATE 2019: A binary tree T has 8 leaves and every level is full (a perfect tree). Two leaves a,b are selected uniformly and independently. Find the expected number of edges on their unique connecting path, to two decimal places.
Tap to enlarge
Answer & solution

Official answer: 4.25

1. A perfect binary tree with eight leaves has height 3 because 8=2³. All leaves are at depth 3, with the root at depth zero.
2. By symmetry, fix the first chosen leaf a. Independence means b remains uniformly distributed among all eight leaves, including a itself.
3. If b=a, there is one choice and distance 0. Its sibling is one choice at distance 2, via their parent. The two leaves in the other child subtree of the same depth-one ancestor have distance 4.
4. The remaining four leaves lie across the root, so the path goes up three edges and down three: distance 6. The counts 1+1+2+4=8 exhaust all equally likely outcomes.
5. Therefore E[d]=(1×0+1×2+2×4+4×6)/8=34/8=4.25.
6. The zero-distance case is required by independent sampling. Sampling two distinct leaves would instead condition on b≠a and produce 34/7, a different answer. Also, the question's parenthetical definition fixes a perfect tree; the broader textbook meaning 'every internal node has two children' alone would not determine these distances.

Original paper, page 14 · Answer key