Definition · An adjacent exchangeGiven an order and a position i, the adjacent exchange at i is the order obtained by swapping the jobs in positions i and i + 1 and leaving everything else alone. It is improving for an objective when the swapped order has a strictly smaller value.
Adjacent is the load-bearing word. An arbitrary transposition moves every completion time between the two jobs and gives a difference with a sum in it; an adjacent one moves exactly two, and the difference collapses to a single subtraction that does not mention the rest of the schedule.
Theorem · The exchange identity for total completion timeLet a and b be adjacent, with a first, and let the pair begin at time t. Swapping them changes sum C by exactly p_b − p_a, whatever t is and whatever the rest of the order is.
Only C_a and C_b change: every earlier job is untouched, and every later job starts when the same two jobs have been done, so it starts and finishes at the same clock as before.
Before: C_a = t + p_a and C_b = t + p_a + p_b, summing to 2t + 2p_a + p_b. After: C_b = t + p_b and C_a = t + p_b + p_a, summing to 2t + 2p_b + p_a.
Subtract: the change is (2p_b + p_a) − (2p_a + p_b) = p_b − p_a. No term involving t or any other job survives.
□
Read the sign. The change is negative exactly when p_b < p_a, that is, exactly when the shorter job was behind the longer one. So any order containing an adjacent pair in the wrong length order can be strictly improved by one swap, and an order that cannot be improved by any adjacent swap has no such pair — which is to say it is sorted by processing time ascending.
Shortest processing time, and what the theorem actually says
Definition · The SPT ruleThe shortest processing time rule orders the jobs by p ascending, breaking ties arbitrarily. Every tie-break gives the same sum C, because swapping two jobs with equal p moves sum C by p_b − p_a = 0.
The theorem is that SPT minimises sum C, and nothing more. It says nothing about weights, nothing about due dates, and nothing about the makespan, which does not move. It also says nothing about the individual jobs: shortest-first is the rule that makes the longest job wait the longest, which is exactly what minimising an unweighted total of finish times asks for.
jobs A 9, B 2, C 6, D 3, E 5 total work 25
LPT A C E D B C = 9 15 20 23 25 sum C 92
FCFS A B C D E C = 9 11 17 20 25 sum C 82
SPT B D E C A C = 2 5 10 16 25 sum C 58
best of all 120 orders 58, attained by B D E C A alone
makespan 25 in every one of them
Ten swaps, and the walk that stops on its own
The lab starts from the worst order there is and repeatedly takes the first adjacent swap that improves sum C, printing the exact quantity each one moved. It is never told what SPT is. On this instance it takes ten swaps and then stops, and where it stops is the sorted order:
start A C E D B sum C 92
1 swap A,C p_C − p_A = 6 − 9 = −3 89
2 swap A,E p_E − p_A = 5 − 9 = −4 85
3 swap C,E p_E − p_C = 5 − 6 = −1 84
4 swap A,D p_D − p_A = 3 − 9 = −6 78
5 swap C,D p_D − p_C = 3 − 6 = −3 75
6 swap E,D p_D − p_E = 3 − 5 = −2 73
7 swap A,B p_B − p_A = 2 − 9 = −7 66
8 swap C,B p_B − p_C = 2 − 6 = −4 62
9 swap E,B p_B − p_E = 2 − 5 = −3 59
10 swap D,B p_B − p_D = 2 − 3 = −1 58
stop B D E C A sum C 58 total moved −34
Ten swaps is not a bound and not an estimate; it is the count on this instance, and it is the number of pairs in a five-job order, because the starting order was the exact reverse of the finishing one. The second preset starts one swap away from sorted and takes two, not one: swapping the out-of-order pair puts a new out-of-order pair next to each other. Watching that happen is worth more than being told that greedy local improvement is subtle.
What the walk demonstrates and the theorem proves are two different things, and it is worth being clear about which is which. The walk shows that on this instance improving swaps exist until the order is sorted. The theorem shows that on every instance an unsorted order has an improving swap, so no unsorted order can be optimal. The lab then checks the conclusion a third way, against all 120 orders, and reports 58 from the enumeration as well.