Longest Processing Time First
List scheduling fails when a long job arrives last and lands on top of an already full machine. If all jobs are known in advance, the cure is obvious: schedule the long jobs first, and let the short ones fill the gaps. This is the LPT rule, and Graham (1969) proved that it improves the guarantee from to . The proof is a model of a common technique: look at a smallest counterexample and show it cannot exist.
The rule
LPT(p_1..p_n, m)
1 sort the jobs so that p_1 >= p_2 >= ... >= p_n
2 LIST-SCHEDULING in this order -- each job to a least loaded machineSorting dominates: time.
The analysis
Theorem (Graham, 1969). LPT has makespan at most .
Proof. Suppose not, and take a counterexample with the fewest jobs. Let job finish last in the LPT schedule. If , delete jobs : LPT schedules jobs exactly as before, so its makespan is unchanged, while OPT cannot increase. That is a smaller counterexample, so in fact : the shortest job finishes last.
Case 1: . The list scheduling argument gives
so this is not a counterexample.
Case 2: . Then every job is longer than , so no machine in an optimal schedule runs three jobs: . For such instances LPT is optimal. (Sketch: LPT puts jobs on separate machines, and each later job, of which there are at most , goes to a least loaded machine, so it joins one of the machines with a short first job. An exchange argument shows that some optimal schedule has the same shape: if two long jobs share a machine while a machine holds a single shorter job, or a long job is paired with a long partner while a shorter job has a short partner, swapping the partners does not raise the maximum load.) So again it is not a counterexample.
The proof reads more naturally backwards: the only way to hurt LPT is a short job finishing last, short jobs cost little by the list scheduling bound, and if no job is short the instance is simple enough to solve exactly.
import heapq
import random
def schedule(p, m):
loads = [0] * m
for x in p:
heapq.heapreplace(loads, loads[0] + x)
return max(loads)
def lpt(p, m):
return schedule(sorted(p, reverse=True), m)
def optimum(p, m):
states = {tuple([0] * m)}
for x in sorted(p, reverse=True):
states = {tuple(sorted(s[:i] + (s[i] + x,) + s[i + 1:])) for s in states for i in range(m)}
return min(max(s) for s in states)
rng = random.Random(6)
print(" m n list LPT OPT LPT/OPT bound")
for m, n in [(2, 10), (3, 10), (3, 12), (4, 11), (5, 12)]:
p = [rng.randint(3, 25) for _ in range(n)]
a, b, o = schedule(p, m), lpt(p, m), optimum(p, m)
print(f"{m:2} {n:3} {a:5} {b:5} {o:5} {b / o:8.3f} {4 / 3 - 1 / (3 * m):6.3f}") m n list LPT OPT LPT/OPT bound
2 10 74 67 66 1.015 1.167
3 10 55 50 50 1.000 1.222
3 12 70 66 66 1.000 1.222
4 11 45 42 41 1.024 1.250
5 12 48 40 40 1.000 1.267
In C++
#include <algorithm>
#include <cstdio>
#include <functional>
#include <queue>
#include <vector>
int lpt(std::vector<int> p, int m) {
std::sort(p.begin(), p.end(), std::greater<int>());
std::priority_queue<int, std::vector<int>, std::greater<int>> loads;
for (int i = 0; i < m; i++) loads.push(0);
for (int x : p) { int l = loads.top(); loads.pop(); loads.push(l + x); }
int makespan = 0;
while (!loads.empty()) { makespan = loads.top(); loads.pop(); } // the last one popped is the largest
return makespan;
}
int main() {
for (int m = 2; m <= 6; m++) {
std::vector<int> p;
for (int x = 2 * m - 1; x > m; x--) { p.push_back(x); p.push_back(x); }
p.insert(p.end(), {m, m, m});
std::printf("m = %d: %zu jobs, LPT %d, OPT %d\n", m, p.size(), lpt(p, m), 3 * m);
}
}m = 2: 5 jobs, LPT 7, OPT 6
m = 3: 7 jobs, LPT 11, OPT 9
m = 4: 9 jobs, LPT 15, OPT 12
m = 5: 11 jobs, LPT 19, OPT 15
m = 6: 13 jobs, LPT 23, OPT 18
A tight family
The C++ program runs LPT on jobs: two each of lengths , and three of length . LPT pairs the two longest with the two shortest of the first jobs, giving every machine load , and the last job of length goes on top: makespan . The optimum puts the three jobs of length on one machine and pairs the others as , each pair summing to : makespan . The ratio is , so Graham's bound is exact for every .
Checking the worst case exhaustively
For three machines and seven jobs with lengths from 1 to 6, the program tries every multiset of lengths, compares LPT with the optimum, and reports the worst ratio. The theorem predicts at most .
import heapq
from fractions import Fraction
from itertools import combinations_with_replacement
def lpt(p, m):
loads = [0] * m
for x in sorted(p, reverse=True):
heapq.heapreplace(loads, loads[0] + x)
return max(loads)
def optimum(p, m):
states = {tuple([0] * m)}
for x in sorted(p, reverse=True):
states = {tuple(sorted(s[:i] + (s[i] + x,) + s[i + 1:])) for s in states for i in range(m)}
return min(max(s) for s in states)
m, worst, count, hits = 3, Fraction(1), 0, []
for p in combinations_with_replacement(range(1, 7), 7):
count += 1
r = Fraction(lpt(p, m), optimum(p, m))
if r > worst:
worst, hits = r, [p]
elif r == worst:
hits.append(p)
print("instances checked:", count)
print("worst LPT / OPT:", worst, "=", round(float(worst), 4), " bound 11/9 =", round(11 / 9, 4))
print("attained by:", [sorted(h, reverse=True) for h in hits])instances checked: 792
worst LPT / OPT: 11/9 = 1.2222 bound 11/9 = 1.2222
attained by: [[5, 5, 4, 4, 3, 3, 3]]
In practice
LPT is the standard heuristic whenever work must be balanced over identical workers and all tasks are known in advance: test shards on CI runners, build targets on a farm of machines, batch jobs on a cluster. The worst case needs very few jobs per machine (the tight family has jobs), and the proof explains why: once the job that finishes last is short compared with the average load, the error is at most that job's length. With many small jobs per machine, LPT is typically within a fraction of a percent of the lower bound . When jobs arrive over time and cannot be sorted, the online bound of plain list scheduling is what remains.
Beyond LPT
- MULTIFIT (Coffman, Garey and Johnson, 1978) binary-searches a capacity and packs with first-fit decreasing; its ratio is (the tight value is due to Yue, 1990).
- The PTAS of Hochbaum and Shmoys (1987) guesses the optimum by binary search and packs jobs into machines of that capacity, rounding large jobs to few sizes and placing small jobs greedily. It runs in time ; later EPTAS versions reduce the dependence on .
- Sum of completion times () is easy: shortest processing time first, assigned round-robin, is optimal. The choice of objective changes the problem completely.
Test yourself
Why may the proof assume that the shortest job finishes last?
- Because LPT puts the shortest job on the emptiest machine
- Deleting all jobs after the one that finishes last keeps LPT's makespan and does not increase OPT, so a minimal counterexample ends with its last job
- Because short jobs take less time
- Because OPT is attained by sorted schedules
If every job is longer than , what does the optimal schedule look like?
- Each machine has at least three jobs
- Each machine has at most two jobs, so , and LPT is optimal on such instances
- All jobs fit on one machine
- It is unknown
For , what is LPT's guaranteed ratio?