Quant Memo
Core

Shortest-Job-First and Average Waiting Time

When a single resource serves a queue of jobs one at a time, running the shortest job first minimizes the average time everyone spends waiting — with a worked comparison against other orderings.

Prerequisites: Proving a Greedy Rule Optimal by Exchange

The problem: you run one checkout counter, one CPU, or one trader's execution queue, and several jobs are waiting to be processed one at a time, each taking a known amount of time. In what order should you run them to minimize the average time people spend waiting? The answer — run the shortest job first — is one of the most useful small results in scheduling, both because it's easy to prove and because it shows up disguised in a lot of interview questions about queues, checklists, and task lists.

The rule and the intuition

Sort jobs by processing time, shortest to longest, and run them in that order. The intuition: a job's wait time equals the sum of the processing times of every job that ran before it. A job scheduled early affects the wait of everyone behind it, but a job scheduled late only affects its own wait. So the jobs that impose the least total cost on others when placed early are the short ones — placing a long job early "taxes" every job behind it for the full length of that long job, while a short job imposes only a small tax. Minimizing that cumulative tax means putting the smallest taxes first.

Worked example: four jobs, two orderings compared

Four jobs with processing times 8,3,5,18, 3, 5, 1 (in minutes). Under shortest-job-first, the order is 1,3,5,81, 3, 5, 8:

OrderRunsFinishesWait (finish minus own time)
1stJob(1)10
2ndJob(3)41
3rdJob(5)94
4thJob(8)179

Average wait =(0+1+4+9)/4=14/4=3.5= (0 + 1 + 4 + 9) / 4 = 14/4 = 3.5 minutes.

Now run them in the original order 8,3,5,18, 3, 5, 1 instead:

OrderRunsFinishesWait
1stJob(8)80
2ndJob(3)118
3rdJob(5)1611
4thJob(1)1716

Average wait =(0+8+11+16)/4=35/4=8.75= (0 + 8 + 11 + 16)/4 = 35/4 = 8.75 minutes — more than double the shortest-job-first average, even though both orderings finish the last job at the same total time of 17 minutes. Total processing time is fixed regardless of order; only how that time is distributed across waiting jobs changes, and shortest-job-first distributes it as unevenly as possible in the good direction — most jobs wait very little, only the longest job absorbs a big wait.

0 16 SJF: avg 3.5 Original: avg 8.75
Per-job wait times for the same four jobs under shortest-job-first (left, low and even) versus the original order (right, one job waits 16 minutes) — same total processing time, very different average wait.

What this means in practice

Shortest-job-first is the right instinct anywhere a single resource serves a queue and the goal is minimizing how long people wait on average — email triage, small-ticket support queues, a single execution algo working through a list of small orders before a large one. It's the wrong instinct when jobs have deadlines instead of just an average-wait objective, or when a long job is more urgent than its length suggests, at which point earliest-deadline-first or a priority weighting replaces pure shortest-job-first.

To minimize average waiting time when one resource processes jobs one at a time, run the shortest job first — every job before a given job adds fully to its wait, so putting the smallest processing times earliest imposes the least total wait cost on the queue as a whole.

Shortest-job-first minimizes average wait, not the wait of any particular job — the single longest job in the queue always waits the longest under this rule, which is the tradeoff being made. If fairness to the longest job (or a hard deadline) matters more than the average, a different rule is needed.

Related concepts

Practice in interviews

Further reading

  • Kleinberg & Tardos, Algorithm Design, ch. 4
ShareTwitterLinkedIn