Bird
Raised Fist0

Consider two approaches to find Minimum Height Trees: (1) brute force BFS from each node to compute height, and (2) leaf trimming using BFS. When is approach (1) preferable over (2)?

hard⚖️ Approach Comparison Q8 of Q15
Topological Sort - Minimum Height Trees (Centroid by Trimming)
Consider two approaches to find Minimum Height Trees: (1) brute force BFS from each node to compute height, and (2) leaf trimming using BFS. When is approach (1) preferable over (2)?
AWhen the tree is very large and performance is critical
BWhen the tree is very small and code simplicity is preferred
CWhen the graph contains cycles and is not a tree
DWhen the tree is a star with one central node
Step-by-Step Solution
Solution:
  1. Step 1: Compare time complexities

    Brute force BFS is O(n^2), leaf trimming is O(n).
  2. Step 2: Consider trade-offs

    For very small trees, brute force is simpler to implement and overhead is negligible.
  3. Final Answer:

    Option B -> Option B
  4. Quick Check:

    Small input favors brute force simplicity [OK]
Quick Trick: Small trees -> brute force acceptable [OK]
Common Mistakes:
MISTAKES
  • Assuming brute force is always worse regardless of input size
Trap Explanation:
PITFALL
  • Candidates overlook that brute force can be simpler for tiny inputs.
Interviewer Note:
CONTEXT
  • Tests understanding of trade-offs between approaches
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