Job
A Job J is a half closed half open interval [ s J , f J ) R , we say that s J is it's start time and f J is it's finishing time.
Job Compatibility for Two Jobs
We say that two jobs I , J are comptible iff I J

Note that two jobs where the finish time of one equals the start time of the other are still compatible

Job Compatibility
Suppose that J is a collection of jobs then we say that J 's jobs are compatible iff for any I , J J such that I J they are compatible.
Interval Scheduling Problem
Suppose that J is a collection of jobs, find the largest subset S J such that S 's jobs are 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.

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

Earliest Finish Time Adding Criterion
Suppose that EFT run on a set of jobs J and is paused during iteration. If it's solution thus far is S = ( s 1 , s 2 , , s k ) , and there is at least one job in a J S , such that S { a } is compatible, then after this iteration EFT will increase it's solution by exactly one job.
Earliest Finish Time is Optimal

Suppose that we are given jobs J = ( j 1 , j 2 , j 3 , . . . , j w ) EFT selects jobs S := ( s 1 , s 2 , s k ) . Recall that an optimal solution is one that maximizes the number of scheduled jobs, suppose the optimal solutions all have length m . Before continuing we should note that k < m , this is because S is not optimal

Let opt ( J ) be the collection of optimal solutions (note that it is finite), and for each O opt ( J ) , there is some l [ 1 k ] such that for every j [ 1 l ] , s j = o j and s l + 1 o l + 1 , we will denote this value by M O . Note that this formalizes the idea of two tuples matching up to a certain index.

The above defines f : opt ( J ) N 0 as f ( O ) := M O . In english language, f maps an optimal solution, to the index that it matches up to with respect to EFT's solution. Let r := max ( f ( opt ( J ) ) ) , then let O f 1 ( r ) be an optimal solution that matches with S E F T for the longest.

It's possible that r = k , if that's true then we know that for every i [ 1 k ] , s i = o i . Let m j > k , then note that o j has the property that S { o j } is compatible, therefore since o j J S , then by the lemma, EFT would have extended it's solution by one on the iteration after it added s k producing a solution on the next iteration of S = ( s 1 , , s k , x ) where x J , but clearly now we have S S , which is a contradiction, thus we know r k

We are sure that k < r is not true because S only has k indices. So for sure r < k , by the way r was defined this means that for every j [ 1 r ] , s j = o j , but that s r + 1 o r + 1 . Note that since s r + 1 o r + 1 and ETF adds by earliest finishing time, we must have that f s r + 1 f o r + 1 , since that's true we know that { s r + 1 , o r + 2 , o m } is compatible, therefore ( o 1 , o 2 , , o r , s r + 1 , , o m ) is an optimal solution that matches with S for r + 1 indices. This is impossible, because the maximum number of indices an optimal solution could match was r .

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 S was optimal then k = m and r = k , and then in the latter part of the proof we wouldn't be able to talk about s r + 1 because it would be an invalid index.