Bird
Raised Fist0

Given n = 4 and edges = [[0,1],[1,2],[1,3]], what nodes will be returned as roots of Minimum Height Trees using the leaf trimming algorithm?

easy🧾 Trace Q3 of Q15
Topological Sort - Minimum Height Trees (Centroid by Trimming)
Given n = 4 and edges = [[0,1],[1,2],[1,3]], what nodes will be returned as roots of Minimum Height Trees using the leaf trimming algorithm?
A[1]
B[0,2,3]
C[0,1,2,3]
D[2]
Step-by-Step Solution
Solution:
  1. Step 1: Identify leaves

    Leaves are nodes 0, 2, and 3.
  2. Step 2: Remove leaves

    Remove leaves and update neighbors; node 1 remains.
  3. Step 3: Remaining node(s)

    Only node 1 remains, so it is the root of minimum height tree.
  4. Final Answer:

    Option A -> Option A
  5. Quick Check:

    Single centroid after trimming leaves [OK]
Quick Trick: Leaves removed until one node remains: the centroid [OK]
Common Mistakes:
MISTAKES
  • Including all leaves as roots
  • Assuming multiple centroids without trimming
  • Confusing edges order with node roles
Trap Explanation:
PITFALL
  • Mistaking leaves for centroids leads to wrong answers
Interviewer Note:
CONTEXT
  • Tests ability to trace leaf trimming steps on a small tree
Master "Minimum Height Trees (Centroid by Trimming)" in Topological Sort

3 interactive learning modes - each teaches the same concept differently

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Topological Sort Quizzes