TExcelTAD
Home › Approximation Algorithms › Longest Processing Time First

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 2−1m2 - \frac{1}{m} to 43−13m\frac{4}{3} - \frac{1}{3m}. The proof is a model of a common technique: look at a smallest counterexample and show it cannot exist.

The rule

text
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 machine

Sorting dominates: O(nlog⁡n)O(n \log n) time.

The analysis

Theorem (Graham, 1969). LPT has makespan at most (43−13m)OPT\left(\frac{4}{3} - \frac{1}{3m}\right)\text{OPT}.

Proof. Suppose not, and take a counterexample with the fewest jobs. Let job ℓ\ell finish last in the LPT schedule. If ℓ<n\ell < n, delete jobs ℓ+1,…,n\ell + 1, \ldots, n: LPT schedules jobs 1,…,ℓ1, \ldots, \ell exactly as before, so its makespan is unchanged, while OPT cannot increase. That is a smaller counterexample, so in fact ℓ=n\ell = n: the shortest job finishes last.

Case 1: pn≤13OPTp_n \le \frac{1}{3}\text{OPT}. The list scheduling argument gives

Cmax⁡≤Pm+(1−1m)pn≤OPT+(1−1m)OPT3=(43−13m)OPT,C_{\max} \le \frac{P}{m} + \left(1 - \frac{1}{m}\right)p_n \le \text{OPT} + \left(1 - \frac{1}{m}\right)\frac{\text{OPT}}{3} = \left(\frac{4}{3} - \frac{1}{3m}\right)\text{OPT},

so this is not a counterexample.

Case 2: pn>13OPTp_n > \frac{1}{3}\text{OPT}. Then every job is longer than 13OPT\frac{1}{3}\text{OPT}, so no machine in an optimal schedule runs three jobs: n≤2mn \le 2m. For such instances LPT is optimal. (Sketch: LPT puts jobs 1,…,m1, \ldots, m on separate machines, and each later job, of which there are at most mm, 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. □\square

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.

python · try it yourself
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++

cpp · try it yourself
#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 2m+12m + 1 jobs: two each of lengths 2m−1,2m−2,…,m+12m - 1, 2m - 2, \ldots, m + 1, and three of length mm. LPT pairs the two longest with the two shortest of the first 2m2m jobs, giving every machine load 3m−13m - 1, and the last job of length mm goes on top: makespan 4m−14m - 1. The optimum puts the three jobs of length mm on one machine and pairs the others as (2m−1,m+1),(2m−2,m+2),…(2m - 1, m + 1), (2m - 2, m + 2), \ldots, each pair summing to 3m3m: makespan 3m3m. The ratio is 4m−13m=43−13m\frac{4m - 1}{3m} = \frac{4}{3} - \frac{1}{3m}, so Graham's bound is exact for every mm.

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 43−19=119\frac{4}{3} - \frac{1}{9} = \frac{11}{9}.

python · try it yourself
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 2m+12m + 1 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 max⁡(Pm,pmax⁡)\max(\frac{P}{m}, p_{\max}). When jobs arrive over time and cannot be sorted, the online bound 2−1m2 - \frac{1}{m} 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 1311\frac{13}{11} (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 nO(1/ε2)n^{O(1/\varepsilon^2)}; later EPTAS versions reduce the dependence on ε\varepsilon.
  • Sum of completion times (P∥∑CjP \Vert \sum C_j) 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?

  1. Because LPT puts the shortest job on the emptiest machine
  2. 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
  3. Because short jobs take less time
  4. Because OPT is attained by sorted schedules

If every job is longer than 13OPT\frac{1}{3}\text{OPT}, what does the optimal schedule look like?

  1. Each machine has at least three jobs
  2. Each machine has at most two jobs, so n≤2mn \le 2m, and LPT is optimal on such instances
  3. All jobs fit on one machine
  4. It is unknown

For m=3m = 3, what is LPT's guaranteed ratio?

  1. 43\frac{4}{3}
  2. 119\frac{11}{9}
  3. 53\frac{5}{3}
  4. 32\frac{3}{2}