Bird
Raised Fist0

What is the overall time complexity of the sweep line algorithm when computing the minimum number of platforms needed for n trains?

medium📊 Complexity Q5 of Q15
Intervals - Minimum Number of Platforms Required
What is the overall time complexity of the sweep line algorithm when computing the minimum number of platforms needed for n trains?
AO(n log n) due to sorting arrivals and departures
BO(n^2) because each train is compared with every other train
CO(n) since only a single pass is required
DO(log n) because of binary search on sorted times
Step-by-Step Solution
Solution:
  1. Step 1: Sorting arrivals and departures

    Sorting both arrays takes O(n log n) time.
  2. Step 2: Single pass merge-like traversal

    After sorting, a linear scan with two pointers takes O(n).
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Sorting dominates complexity, linear scan is secondary [OK]
Quick Trick: Sorting dominates complexity, linear scan is linear [OK]
Common Mistakes:
MISTAKES
  • Assuming O(n) ignoring sorting step
  • Confusing with quadratic comparisons
  • Thinking binary search is involved
Trap Explanation:
PITFALL
  • Ignoring sorting step leads to underestimating complexity.
Interviewer Note:
CONTEXT
  • Checks understanding of algorithmic complexity for interval scheduling.
Master "Minimum Number of Platforms Required" in Intervals

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 Intervals Quizzes