Greedy algorithms for the two classic interval problems, with proof sketches.
Scheduling the max number of intervals
- Algorithm: sort by finish time and select the next compatible interval
- Proof: Greedy stays ahead, by induction
- Claim: Greedy algorithm is optimal
- Lemma
- : For greedy choices and optimal choices ,
- : is chosen to have the minimum finish time, so
- Suppose . Since , is among the candidates considered for . Of those candidates, it picks the minimum finish time, so .
- By this lemma, we must have , since otherwise is in the set of candidates for .
Partitioning intervals into the minimum number of sets
- Algorithm: sort intervals by start time, adding them to any compatible set. If no set is compatible, create a new one
- Proof: exploit structural property
- Claim: greedy algorithm is optimal
- Let be the number of sets the greedy algorithm allocates. The th set, is allocated because we had to assign some interval, , that was not compatible with any of the previous sets.
- Since we sorted by start time, all intervals have . Thus, we have at least depth intervals, and so all valid partitions must have sets.