A perfect binary tree contains 2^m - 1 routers (one at each node). To send a message from router I to router J, the message first goes up to the root and then down to J. What is the mean router-to-router path length under this “via root” policy?

Difficulty: Hard

Correct Answer: 2 * ( 2^m * (m - 2) + 2 ) / ( 2^m - 1 )

Explanation:


Introduction / Context:
In a full (perfect) binary tree with 2^m - 1 routers, a “centralized” routing rule sends any message up to the root and then down to the destination. The hop count between two routers equals the depth of the source plus the depth of the destination (since the least common ancestor is always the root). We seek the mean hop length over all pairs under this policy.


Given Data / Assumptions:

  • The tree is perfect with m levels numbered 0..m-1; total routers = 2^m - 1.
  • Depth(root) = 0; a node at level k has depth k.
  • Path via root: hops(I → J) = depth(I) + depth(J).
  • Routers are equally likely when computing the mean.


Concept / Approach:
Let D be the random variable “depth of a uniformly chosen node.” The mean path length is E[depth(I) + depth(J)] = 2 * E[D]. Hence compute the average node depth in a perfect binary tree: E[D] = (Σ k * 2^k from k=0 to m-1) / (2^m - 1). Use the identity Σ k * 2^k = 2^m * m - 2^(m+1) + 2, then double that value for the final mean path length.


Step-by-Step Solution:

Compute S1 = Σ 2^k (k=0..m-1) = 2^m - 1. Compute S2 = Σ k * 2^k (k=0..m-1) = 2^m * m - 2^(m+1) + 2. Average depth E[D] = S2 / S1. Mean path length L = 2 * E[D] = 2 * ( 2^m * m - 2^(m+1) + 2 ) / ( 2^m - 1 ) = 2 * ( 2^m * (m - 2) + 2 ) / ( 2^m - 1 ).


Verification / Alternative check:
Test small m. For m=1 (single node): L = 0 (formula gives 0). For m=2 (3 nodes): node depths {0,1,1}, E[D] = 2/3, L = 4/3; enumerating ordered pairs via root gives the same average, validating the expression.


Why Other Options Are Wrong:

  • 2 * (m - 2): linear approximation; ignores exponential node counts per level.
  • 2 * (2m - 1): scales linearly with m but grossly overestimates for large m.
  • m - 1: equals maximum depth, not the mean via root over all pairs.
  • m / 2: heuristic guess; not derived from node distribution by depth.


Common Pitfalls:
Forgetting that most nodes lie near the leaves, increasing mean depth; computing undirected shortest path rather than the constrained “via root” path; averaging unordered pairs and then forgetting to account for ordered pairs (the mean is the same here because the sum is symmetric).


Final Answer:
2 * ( 2^m * (m - 2) + 2 ) / ( 2^m - 1 )

More Questions from Networking

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion