Tree Properties & Traversals

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.