Data Structures & Algorithms · Data Structures & Algorithms
NP-Hard Scheduling
Identical-processor makespan (2 machines ≡ PARTITION) and job-shop (named machines, per-job routes). Problem statements, one reduction you can finish by hand, and LPT as a…
Six concepts on the syllabus scheduling pair — identical-processor makespan, the m=2 / PARTITION map you can finish, LPT as a heuristic, the job-shop model, flow shop versus job shop, and what an NP-hard label licenses. No invented SAT gadgets. Job sequencing with deadlines is a different greedy and is not repeated.
- Data Structures & Algorithms
- Hard level
- 6 concepts
1n jobs, m identical machines, minimise makespan
An identical-processor instance is n jobs with processing times t_1,\ldots,t_n and m machines that are interchangeable — any job may run on any machine, one job per machine at a time, no preemption. The makespan C_{\max} is the time the last machine becomes free. The optimisation problem is to assign jobs to machines so C_{\max} is as small as possible.
A trivial lower bound is C_{\max} \ge \max(\max_i t_i, \lceil(\sum t_i)/m\rceil): no machine can finish a job shorter than the job, and m machines cannot beat the average load. For m=1 the bound is the whole story — C_{\max} = \sum t_i in any order.
Figure. Two interchangeable machines. Makespan is the later of the two finish times, not the sum of both loads.
Read one instance
- JobsA list of times. No machine names, no per-job route.
- Machinesm copies of the same processor.
- ScoreC_{\max} = max of the m machine loads (sums of the jobs assigned to them).
Lower bound on 5,5,4,3,3 with m=2
What does the lower bound say, and is a makespan of 10 possible?
- \sum t_i20
- \lceil 20/2 \rceil10
- \max t_i5
- lower bound10 — so 10 is possible only if both machines load exactly 10
Pro tip. The bound does not construct the schedule. The next concepts ask whether 10 (or 11, or 12) is attained.
On one identical machine, non-preemptive, no release times, C_{\max} is
- The sum of the job times, in any order
- The longest job only
- NP-hard to compute
One machine just concatenates the jobs. The longest job is a lower bound, not the makespan. Hardness starts at m \ge 2.
2Two machines, target T: that is PARTITION
PARTITION asks: given positive integers a_1,\ldots,a_k, can they be split into two subsets with equal sum? The 2-processor decision 'is there a schedule with C_{\max} \le T?' on times a_1,\ldots,a_k with T = (\sum a_i)/2 (when that T is an integer) is the same question: each subset is one machine's load, and both loads \le T forces both loads = T.
That map is polynomial (it copies the numbers) and you can finish it by hand. Horowitz, Sahni and Rajasekaran place multiprocessor scheduling with the NP-hard problems; PARTITION is the m=2 reason this topic will actually compute. We do not invent a reduction for general m or a Cook-style SAT gadget.
Figure. Left: equal loads 6 and 6, a PARTITION yes. Right: loads 7 and 5, a PARTITION no. Bar lengths are schematic, not 6:7 scale.
The map you can finish
- From PARTITIONIntegers a_i. Let T = (\sum a_i)/2 when even.
- To 2-processor decisionJobs of times a_i, m=2, budget T.
- Yes iff yesA partition is a pair of machine loads each equal to T.
Yes-instance 3,3,2,2,2 and no-instance 5,5,2
Both sums are 12, so T=6. Which one partitions?
- 3+3 and 2+2+26 and 6 — yes, C_{\max}=6
- 5+5 and 210 and 2
- 5+2 and 57 and 5 — both > 6 on the heavy side
- 5,5,2 at T=6no partition, C_{\max}=7
Pro tip. The no-instance still has a schedule (load 7 and 5). Decision at T=6 is no; the optimisation answer is 7, not 'unsolvable'.
2-processor decision with T=(\sum t_i)/2 is yes if and only if
- The times form a PARTITION yes-instance
- Every t_i \le T, regardless of the subset sums
- m=1, so the sum itself is T
Each t_i \le T is necessary (a job longer than T cannot fit) but not sufficient — 5,5,2 has every job ≤ 6 and still fails. m=1 is a different, easy case.
3LPT is a heuristic, not the optimum
Longest-processing-time (LPT) list scheduling sorts the jobs by decreasing t_i and always starts the next job on a machine whose current load is smallest. It is the rule you actually run. It is not guaranteed to hit the optimum.
On times 3, 3, 2, 2, 2 and m=2 — the PARTITION yes-instance — LPT gives loads 3+2+2=7 and 3+2=5, so C_{\max}=7. The partition \{3,3\} and \{2,2,2\} has C_{\max}=6. LPT missed the optimum. Graham's worst-case ratio for LPT is a named theorem in the literature; this topic does not invent or re-prove it.
Figure. LPT on 3,3,2,2,2 with m=2 places 3 then 3, then 2 and 2 on the lighter machine, then the last 2 on M1 after a tie. Loads 7 and 5, Cmax=7. The partition {3,3} and {2,2,2} has Cmax=6. Same jobs; LPT missed the optimum.
LPT on 3,3,2,2,2
- SortAlready 3, 3, 2, 2, 2.
- First four3 on M1, 3 on M2, 2 on M1 (loads 5 and 3), 2 on M2 (loads 5 and 5).
- Last 2Tied loads: the first machine takes it. Loads 7 and 5. C_{\max}=7.
LPT list scheduling
def lpt(times, m):
times = sorted(times, reverse=True)
load = [0] * m
for t in times:
k = min(range(m), key=lambda i: load[i])
load[k] += t
return max(load), loadLPT 7 versus partition 6
m=2, times 3,3,2,2,2. Run LPT, then the equal-sum assignment.
- place 3, then 3M1=3, M2=3
- place 2 on M1, then 2 on M2M1=5, M2=5
- place last 2 on M1 (tie → first machine)M1=7, M2=5 — C_{\max}=7
- opt: \{3,3\} and \{2,2,2\}6 and 6 — C_{\max}=6
Pro tip. LPT never considers moving an earlier 3 next to the other 3. The partition is legal and better. That is why LPT is a heuristic.
LPT on two machines with times 3,3,2,2,2 finishes with
- C_{\max}=7 (loads 7 and 5), worse than the partition's 6
- C_{\max}=6, because LPT always matches PARTITION
- C_{\max}=12, running every job on one machine
After 3,3,2,2 the loads are 5 and 5; the last 2 makes 7 and 5. The partition \{3,3\} / \{2,2,2\} is 6 and is not what LPT builds.
4Job shop: each operation names its machine
A job-shop instance has n jobs and m named machines. Job j is a sequence of operations (M_{j,1}, t_{j,1}), (M_{j,2}, t_{j,2}), \ldots that must run in that order. Two operations cannot occupy the same machine at the same time. Machines are not interchangeable: an operation that names M_2 cannot run on M_1.
That is a different model from identical processors (no machine names, any job on any machine) and from job sequencing with deadlines (one machine, unit jobs, profit). The 2-by-2 shop J1: (M_1,2) then (M_2,1); J2: (M_2,2) then (M_1,1) has makespan 3 if both jobs start immediately on their first machines.
Figure. Gantt of the 2-by-2 shop. Widths 0.36 versus 0.18 are 2:1, matching the durations 2 and 1. Makespan 3.
Read one job shop
- Per jobA route: which machine, for how long, in which order.
- Per machineA sequence of the operations that named it, no overlap.
- MakespanThe time the last operation in the instance finishes.
2 jobs, 2 machines, makespan 3
J1: M1 for 2 then M2 for 1. J2: M2 for 2 then M1 for 1. Start both first operations at time 0. When does the shop finish?
- M1 [0,2): J1; M2 [0,2): J2both first operations done at 2
- M2 [2,3): J1's second; M1 [2,3): J2's secondboth done at 3
- each job's own length3 — so 3 is also a lower bound
- C_{\max}3
Pro tip. Delaying J2's start on M2 cannot beat 3: J2 still needs 2+1 after it starts, and J1 still needs 3.
In a job shop, an operation (M_2, 4)
- Must run on machine 2 for 4 time units, after the job's earlier operations
- May run on any idle machine, because processors are identical
- Is a unit-time profit job with deadline 2
Named machine plus precedence inside the job. Identical processors and job-sequencing-with-deadlines are the other two models.
5Flow shop is the same route for every job
A flow shop is a job shop in which every job visits the machines in the same order — typically M_1 then M_2 then \cdots then M_m. An open shop drops the per-job order and keeps only 'each job has an operation on each machine'. The running 2-by-2 instance is not a flow shop: J1 wants M_1 then M_2, J2 wants M_2 then M_1.
Horowitz, Sahni and Rajasekaran classify job-shop scheduling as NP-hard. This topic records that classification and does not invent a reduction. What you can check by hand is the model: named machines, per-job routes, no overlap on a machine, precedence inside a job.
Same 2-by-2 Gantt. The new content is the flow-shop row: that Gantt would be illegal in a flow shop that demanded M1-then-M2 for every job.
| Model | Machines | What is fixed |
|---|---|---|
| Identical processors | Interchangeable | Only the times t_i |
| Job shop | Named | Per-job route and times |
| Flow shop | Named | The same route for every job |
| Job sequencing (greedy topic) | One machine | Unit jobs, deadlines, profit |
The running 2-by-2 instance is a job shop and not a flow shop because
- The two jobs visit the two machines in opposite orders
- The machines are identical, so routes do not matter
- Each job is a unit-time profit job
Flow shop needs one shared route. Identical processors have no routes. Unit-time profit is job sequencing.
6What the book’s NP-hard label licenses
The book’s placement of identical-processor scheduling and job shop among the NP-hard problems is a licence to stop looking for a polynomial algorithm that works on every instance, unless you are also trying to prove P = NP. It is not a licence to call a 5-job 2-machine instance 'impossible', and it is not a proof we re-derived in this topic except for the m=2 / PARTITION map.
Honest tools: exact search or IP on small n (the 3,3,2,2,2 instance is enumerable), LPT or other list rules when you need a schedule now, and special cases you can actually solve (m=1; 2-colouring-style structure is the wrong analogue here). Do not invent a SAT-to-job-shop gadget in an exam you cannot finish.
Same 'do this / do not chase that' idea as the graph-NPC licence table, specialised to m=1, LPT, and job shop.
| Response | Licensed? |
|---|---|
| Give up on a general poly-time solver | Yes — that is the book’s label |
| Call every 6-job instance unsolvable | No |
| Use LPT / exact search on small n | Yes |
| Treat m=1 as NP-hard | No — C_{\max} is the sum |
| Invent a SAT gadget you cannot draw | No |
NP-hardness of job shop means
- A general poly-time algorithm would collapse P and NP; a 2-by-2 shop can still be solved by hand
- The 2-by-2 instance of makespan 3 is unsolvable
- LPT is incorrect, because the problem is hard
Hardness is about all instances and polynomial time. The 2-by-2 ledger finished at 3. LPT is a heuristic for identical processors, not a mistaken P algorithm for job shop.
Notes
- Identical-processor scheduling: n jobs with times t_i, m identical machines, non-preemptive. Minimise makespan C_max — the time the last machine finishes.
- The decision version (is C_max ≤ T?) is in NP: the certificate is an assignment of jobs to machines. For m=1, C_max is just the sum of the times. For m=2 the decision is the same question as PARTITION.
- Horowitz, Sahni and Rajasekaran list multiprocessor scheduling among the NP-hard problems. This topic shows the m=2 / PARTITION map you can recompute, and does not invent a Cook-style proof for general m.
- LPT (longest processing time first) list scheduling is the honest practical rule. It is not always optimal; the running 2-machine instance 3,3,2,2,2 has LPT makespan 7 and optimum 6.
- Job shop: each job is a sequence of operations (machine, time). Machines are not identical; each operation names its machine. Flow shop is the special case where every job visits the machines in the same order. The book classifies job shop NP-hard; we do not invent the reduction.
Formulas
- Makespan C_{\max} = \max_k (finish time of machine k).
- Lower bound: C_{\max} \ge \max\bigl(\max_i t_i,\, \lceil (\sum t_i)/m \rceil\bigr).
- m=1: C_{\max} = \sum t_i (any order, non-preemptive, no release times).
- m=2 decision with T = (\sum t_i)/2 is yes iff the times partition into two sets of equal sum.
- LPT: sort t_i decreasing; always start the next job on a currently earliest-finishing machine.
Exam traps & shortcuts
- Identical processors have no machine names. Job shop operations do. Mixing the two models is the usual syllabus slip.
- PARTITION is the m=2 map you can finish. Do not sketch a SAT gadget for job shop in an exam unless you can draw every clause.
- LPT is a heuristic. A counter-example (3,3,2,2,2 on two machines: LPT 7, optimum 6) is a better answer than a fake 4/3 proof you did not recompute.
- Job sequencing with deadlines (one machine, unit jobs, profit) is a different greedy and already has its own topic.
Reference tables
The syllabus names both. They do not share a machine story.
| Identical processors | Job shop | |
|---|---|---|
| Machines | Interchangeable | Named |
| Job | A single time t_i | A route of operations |
| Easy case this topic computes | m=1; m=2 via PARTITION | The 2-by-2 shop of makespan 3 |
| Hardness | Book: NP-hard; we show m=2 | Book: NP-hard; we do not invent the proof |
Recap
Night-before NP-scheduling pegs.
- Makespan
- C_{\max} = last machine finish. m=1 is the sum.
- PARTITION
- m=2, T=(\sum t_i)/2 yes iff the times partition.
- LPT
- Longest first, lightest machine. Heuristic. 3,3,2,2,2 → 7, not 6.
- Job shop
- Named machines, per-job routes. 2-by-2 finishes at 3.
- License
- Stop chasing a general P algorithm. Still solve small n. Do not invent gadgets.
Practise NP-Hard Scheduling
Reading is free and needs no account. Practice, mocks and progress live in the app.
- A 6-question practice set that ends the chapter
- 6 quick checks with worked explanations
- Timed mocks scored with the real marking scheme
- Readiness tracked per topic, kept on your device