Interval Scheduling
Maximum set of non-overlapping intervals; earliest finish first is optimal by an exchange argument.
Decision · step 2 of 10Intervals and Greedy Choices: Earliest finish first
a is 1-4. It starts at 1, which is after the last kept interval ended (0), so keep it. The next one must start at 4 or later.
What you will see
Same as activity selection with an exchange-argument overlay: any other choice can be swapped for ours.
Cost
| Best | O(n log n) |
|---|---|
| Average | O(n log n) |
| Worst | O(n log n) |
| Space | O(1) |
How you work with it here
play it through, step one change at a time, scrub to any step, run it on your own input, predict what happens next.
Screen readers: Candidates announce their key and state (candidate, chosen, rejected); each step announces the local choice and its consequence.
Reduced motion: Chosen and rejected states crossfade; no travelling emphasis.
Before this
A variant of
Taught by the same lesson
Intervals and Greedy Choices covers these too, in the same run.