GATE CS 2019 Set 1 — Question 56
Go beyond PYQs with Success TrackerAI-powered personalised practice and doubt support. Unlimited practice on eligible plans; AI usage limits apply.NAT+2 / -0HardBinary Tree PropertiesTreesProgramming & Data StructuresExpectation & VarianceProbability & StatisticsEngineering Mathematics
Engineering Mathematics → Probability & Statistics → Binary Tree Properties
Last updated
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) _______.
Correct answer
4.25 to 4.25
Solution
Given that is a full binary tree (perfect binary tree) with 8 leaves, we can determine its height .
For a perfect binary tree, the number of leaves is . Thus, .
The tree has levels , where the root is at level 0 and leaves are at level 3.We choose two leaves and uniformly and independently at random. Since there are 8 leaves, the total number of possible pairs is .The distance between two nodes in a tree is the number of edges on the unique path between them. For two leaves and at depth , the distance is given by:where is the Lowest Common Ancestor of and .We analyze the possible depths of the LCA:
The LCA is the root if is in the left subtree and is in the right subtree, or vice versa.
Number of pairs = .
Distance = .
Contribution to sum = .
Each node at depth 1 has a left child and a right child, each leading to leaves.
For a specific node at depth 1 to be the LCA, one leaf must be in its left branch (2 choices) and the other in its right branch (2 choices), or vice versa.
Pairs per node = .
Total pairs for 2 nodes = .
Distance = .
Contribution to sum = .
For a node at depth 2 to be the LCA, one leaf must be left (1 choice) and the other right (1 choice), or vice versa.
Pairs per node = .
Total pairs for 4 nodes = .
Distance = .
Contribution to sum = .
Total pairs = 8.
Distance = .
Contribution to sum = 0.Total Sum of Distances:Expected Distance:The expected value is 4.25.
For a perfect binary tree, the number of leaves is . Thus, .
The tree has levels , where the root is at level 0 and leaves are at level 3.We choose two leaves and uniformly and independently at random. Since there are 8 leaves, the total number of possible pairs is .The distance between two nodes in a tree is the number of edges on the unique path between them. For two leaves and at depth , the distance is given by:where is the Lowest Common Ancestor of and .We analyze the possible depths of the LCA:
1.LCA at depth 0 (Root):
The root has a left subtree and a right subtree. Each subtree contains leaves.The LCA is the root if is in the left subtree and is in the right subtree, or vice versa.
Number of pairs = .
Distance = .
Contribution to sum = .
2.LCA at depth 1:
There are nodes at depth 1. Each is the root of a subtree with height 2 (leaves at relative depth 2).Each node at depth 1 has a left child and a right child, each leading to leaves.
For a specific node at depth 1 to be the LCA, one leaf must be in its left branch (2 choices) and the other in its right branch (2 choices), or vice versa.
Pairs per node = .
Total pairs for 2 nodes = .
Distance = .
Contribution to sum = .
3.LCA at depth 2:
There are nodes at depth 2. Each has 2 leaves as children (1 left, 1 right).For a node at depth 2 to be the LCA, one leaf must be left (1 choice) and the other right (1 choice), or vice versa.
Pairs per node = .
Total pairs for 4 nodes = .
Distance = .
Contribution to sum = .
4.LCA at depth 3 (Leaf itself):
This occurs when . There are 8 leaves.Total pairs = 8.
Distance = .
Contribution to sum = 0.Total Sum of Distances:Expected Distance:The expected value is 4.25.
Continue learning with Success Tracker
A step still unclear? Work through it with support
Use Success Tracker to ask about the reasoning, then try another GATE CS question to check your understanding.
AI-powered practice· Unlimited practice on eligible plans
- PYQs with solutions
- Attempt available previous-year questions, then compare your reasoning with the worked solution. Coverage varies by stream.
- Practice that adapts
- Choose a topic, work on weaker areas and bookmark questions to revisit. Your attempts feed your progress tracking.
- AI doubt support
- Ask follow-up questions about a step or concept while practising, instead of stopping at the final answer.
Unlimited practice is available on eligible plans. Free practice and AI usage have limits; check the current plan allowances before choosing.
This page stays readable without an account. AI responses can be wrong; check them against the solution and source material.
More questions on Probability & Statistics
2026 Set 2 Q3A day can only be cloudy or sunny. The probability of a day being cloudy is , independent of…2026 Set 2 Q5‘When it is raining, peacocks dance.’ Based only on this sentence, which one of the following…2026 Set 2 Q8Figures (i) and (ii) represent intercity highway systems. The black dots represent cities and the…2026 Set 1 Q10An unbiased six-faced dice whose faces are marked with numbers 1, 2, 3, 4, 5, and 6 is rolled twice…2026 Set 2 Q10An unbiased six-faced dice whose faces are marked with numbers 1, 2, 3, 4, 5, and 6 is rolled twice…