View worked solution
Answer: 4.25
A full binary tree (where every level is completely filled) with leaves has a height of . Let the root be at depth , and the leaves be at depth .
Since two leaves and are chosen uniformly and independently at random, there are possible ordered pairs . The distance between any two leaves depends on the depth of their Lowest Common Ancestor (LCA):
- Case 1: (LCA at depth 3)
The distance is . There are such pairs. - Case 2: and are siblings (LCA at depth 2)
The distance is . For each leaf, there is exactly sibling. There are such pairs. - Case 3: LCA is at depth 1
The distance is . For each leaf, there are such leaves in the adjacent sibling subtree. There are such pairs. - Case 4: LCA is the root (depth 0)
The distance is . For each leaf, there are such leaves in the opposite half of the tree. There are such pairs.
We can verify the total number of pairs: .
The expected value of the distance is:
Free practice · Your answers on this page are not saved.
