Note that two jobs where the finish time of one equals the start time of the other are still compatible
When trying to solve a problem using a greedy approach one can usually consider a collection of finite natural orderings that a normal human may guess. For example, for the interval scheduling problem we could consider the following approaches. Where we start with some element, and then iteratively try to add new elements so long as the new element is compatible and using some heuristic.
- Earliest Start Time
- Earliest Finish Time
- Shortest Interval
- Fewest Conflicts
For earliest start time we can see that it does not work via this counter example
Shortest Interval Counter Example
TODO: Earliest finish time implementation
It turns out that adding valid jobs based on earliest finish time yields an optimal solution
Suppose that we are given jobs EFT selects jobs . Recall that an optimal solution is one that maximizes the number of scheduled jobs, suppose the optimal solutions all have length . Before continuing we should note that , this is because is not optimal
Let be the collection of optimal solutions (note that it is finite), and for each , there is some such that for every and , we will denote this value by . Note that this formalizes the idea of two tuples matching up to a certain index.
The above defines as . In english language, maps an optimal solution, to the index that it matches up to with respect to EFT's solution. Let , then let be an optimal solution that matches with for the longest.
It's possible that , if that's true then we know that for every . Let , then note that has the property that is compatible, therefore since , then by the lemma, EFT would have extended it's solution by one on the iteration after it added producing a solution on the next iteration of where , but clearly now we have , which is a contradiction, thus we know
We are sure that is not true because only has indices. So for sure , by the way was defined this means that for every , but that . Note that since and ETF adds by earliest finishing time, we must have that , since that's true we know that is compatible, therefore is an optimal solution that matches with for indices. This is impossible, because the maximum number of indices an optimal solution could match was .
Our assumption was that ETF doesn't produce an optimal solution, and we obtained a contradiction.
Note that in the above proof it's important to realize that if was optimal then and , and then in the latter part of the proof we wouldn't be able to talk about because it would be an invalid index.