AlgoScope

Interval Scheduling

Maximum set of non-overlapping intervals. Earliest finish first is optimal by an exchange argument.

Greedy, algorithm, intermediateAlso called Activity Selection
Keep a, 1 to 4.012345678910abcdefghaaabbccccccddeeeeeeffffgggghhh

Intervals and Greedy Choices: Earliest finish first

Decision, step 2 of 10

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.

Cost

Best
O(n log n)
Average
O(n log n)
Worst
O(n log n)
Space
O(1)

A variant of

Taught by the same lesson

Intervals and Greedy Choices covers these too, in the same run.