Skip to main content

GATE CSE 2019Data Structures › Trees & Binary Search TreesVerified

GATE CSE 2019 PYQ: Let T T T be a full binary tree with 8 8 8 leaves. (A full binary tree has every level full.) Suppose two…

Let TT be a full binary tree with 8 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 2 decimal places) _________.

    Answer

    4.25

    Approach

    Model the tree as a perfect binary tree of height 3, so every leaf is at depth 3. Because $a$ and $b$ are selected independently, order matters and the same leaf may be selected twice. There are $8^2=64$ equally likely ordered pairs. Classify each pair by the depth of the lowest common ancestor, then compute the average distance.

    The weighted average over all 64 ordered leaf pairs gives $(16+64+192)/64=272/64=4.25$. The independence of the two random choices is essential; it allows the same leaf to be chosen twice.

    Reviewed by GateIQ Editorial Team: IIT & IISc Alumni.