Question
Let be a full binary tree with 8 leaves. (A full binary tree has every level full.) Suppose two leaves and of are chosen uniformly and independently at random. The expected value of the distance between and in (i.e., the number of edges in the unique path between and ) is (rounded off to 2 decimal places) ________.
Official answer and solution
- Official answer
- 4.25
- From
- Official GATE 2019 answer key
Solution
Enumerate the distance between any two leaves chosen uniformly and independently based on their lowest common ancestor level, and compute the expected value.
A full binary tree with 8 leaves has root at level 0, internal nodes at levels 1 and 2, and all leaves at level 3. The height of the tree is 3.
Two leaves and are chosen uniformly and independently at random from the 8 leaves. Thus, there are equally likely pairs .
The distance between and is the number of edges on the unique path between them, which depends on their lowest common ancestor (LCA):
- (same leaf): There are such pairs. The distance is .
- LCA at level 2 (sibling leaves): Each leaf has sibling. There are pairs. The path goes up 1 edge to the parent and down 1 edge to the sibling, giving distance .
- LCA at level 1 (leaves sharing a grandparent but not a parent): Each leaf has such cousins in its subtree of size 4. There are pairs. The path goes up 2 edges and down 2 edges, giving distance .
- LCA at level 0 (root, leaves in different halves of the tree): Each leaf has leaves in the opposite half of the tree. There are pairs. The path goes up 3 edges and down 3 edges, giving distance .
Verify the sum of pairs: pairs, which covers all possibilities.
The expected value of the distance is the weighted average:
4.25
Assuming and must be distinct leaves, giving 56 pairs and distance , but the question states they are chosen independently at random, allowing .
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2019 Computer Science and Information Technology (CS)
- Question
- 56 of 65, printed as CS Q.46
- Section
- Computer Science and Information Technology
Report an error in this question
GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.