The earliest due date first algorithm is a greedy algorithm that repeatedly schedules the available job with smallest due date.
In the interval scheduling problem, each job j has fixed interval [sj,fj) and its due date is its finish time fj. The algorithm therefore chooses compatible jobs in increasing order of fj.
Principle
For fixed intervals, accepting a job consumes the machine until its finish time. If two candidate jobs are both currently compatible and
fi≤fj,
then choosing i leaves at least as much time for every later compatible job as choosing j. This is the local reason why the earliest finishing job is safe.
Algorithm
Fixed intervals
Given jobs J={1,…,n} with intervals [sj,fj):
sort jobs by increasing f[j];S = {};t = -infinity;for (j in jobs) { if (s[j] >= t) { S.add(j); t = f[j]; }}
The invariant is that t is the finish time of the last selected job, and S is a compatible set.
Correctness
Optimality for interval scheduling
For the interval scheduling objective max∣S∣, earliest due date first returns an optimal solution.
Exchange argument G=(g1,…,gk) be the greedy solution. Let O=(o1,…,ot) be an optimal compatible solution, ordered by increasing finish time.
Let
Consider the first position r where G and O differ, after replacing earlier positions so that gi=oi for i<r.
At this point, both gr and or are compatible with the common prefix. Since the algorithm chooses the compatible job with earliest due date,
fgr≤for.
Replace or by gr. Every later job in O starts after for, and therefore also starts after fgr. The replacement preserves feasibility and does not change the number of jobs.
Repeating this exchange transforms some optimal solution into one whose prefix is the greedy solution. When the greedy algorithm stops, no job remains that is compatible with its prefix. Hence no optimal continuation can contain more jobs, so ∣G∣=∣O∣. □
Complexity
Sorting by due date takes O(nlogn). The greedy scan takes O(n), so the total running time is
O(nlogn).
Limitation
Scope
Earliest due date first is optimal for unweighted interval scheduling with fixed intervals and objective max∣S∣. Different scheduling objectives, such as minimising maximum lateness or maximising total weight, require different proofs or different algorithms.