Skip to content
Official PYQ · 2019

GATE CS 2019 Q46 — Trees

Explain with AI
Let TT be a full binary tree with 88 leaves. (A full binary tree has every level full.) Suppose two leaves aa and bb of TT are chosen uniformly and independently at random. The expected value of the distance between aa and bb in TT (ie., the number of edges in the unique path between aa and bb) is (rounded off to 22 decimal places) _________.
View worked solution

Answer: 4.25

A full binary tree (where every level is completely filled) with 88 leaves has a height of 33. Let the root be at depth 00, and the 88 leaves be at depth 33.

Since two leaves aa and bb are chosen uniformly and independently at random, there are 8×8=648 \times 8 = 64 possible ordered pairs (a,b)(a, b). The distance d(a,b)d(a, b) between any two leaves depends on the depth of their Lowest Common Ancestor (LCA):

  • Case 1: a=ba = b (LCA at depth 3)
    The distance is 00. There are 88 such pairs.
  • Case 2: aa and bb are siblings (LCA at depth 2)
    The distance is 2+2−2(2)=22 + 2 - 2(2) = 2. For each leaf, there is exactly 11 sibling. There are 8×1=88 \times 1 = 8 such pairs.
  • Case 3: LCA is at depth 1
    The distance is 3+3−2(1)=43 + 3 - 2(1) = 4. For each leaf, there are 22 such leaves in the adjacent sibling subtree. There are 8×2=168 \times 2 = 16 such pairs.
  • Case 4: LCA is the root (depth 0)
    The distance is 3+3−2(0)=63 + 3 - 2(0) = 6. For each leaf, there are 44 such leaves in the opposite half of the tree. There are 8×4=328 \times 4 = 32 such pairs.

We can verify the total number of pairs: 8+8+16+32=648 + 8 + 16 + 32 = 64.

The expected value of the distance is:

E[D]=(8×0)+(8×2)+(16×4)+(32×6)64E[D] = \frac{(8 \times 0) + (8 \times 2) + (16 \times 4) + (32 \times 6)}{64}E[D]=0+16+64+19264=27264=4.25E[D] = \frac{0 + 16 + 64 + 192}{64} = \frac{272}{64} = 4.25

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Trees questions