E ExamMaster

GATE Computer Science & IT · Data Structures & Algorithms

Job Sequencing with Deadlines

One machine, unit-time jobs, each with a deadline and a profit: sort by profit and place each job in the latest free slot that still meets its deadline.

Four concepts on job sequencing with deadlines — the one-machine unit-time model, latest-slot greedy after a profit sort, the five-job walk to profit 142, and why this is not activity selection. MST and shortest paths already live under graph algorithms; they are not repeated here.

  • GATE Computer Science & IT
  • Medium level
  • 4 concepts

1One machine, unit time, deadline, profit

A job-sequencing instance is n jobs and one machine. Every job takes exactly one time slot. Job i comes with a deadline d_i (an integer slot index) and a profit p_i paid only if the job is assigned a slot t with t \le d_i. A job that misses its deadline contributes 0. Two jobs cannot share a slot.

The machine's usable slots are 1,2,\ldots,D with D = \min(n, \max d_i). You cannot schedule more jobs than slots, and a deadline larger than n is no more useful than n.

Figure. Three unit slots on one machine. Five jobs will compete for these three cells.

Read one instance

  1. JobsEach row is (id, d_i, p_i). Time is 1 for every job.
  2. SlotsD = \min(n, \max d_i) cells on a single timeline.
  3. ObjectiveMaximise the sum of profits of jobs that received a legal slot.

How many slots?

Five jobs with deadlines 2, 1, 2, 1, 3. What is D, and why is a sixth slot useless even if some deadline were 10?

  • \max d_i3
  • n5
  • D = \min(5,3)3
  • jobs that can finishat most 3, one per slot

Pro tip. Five jobs and three slots means at least two jobs earn 0. The algorithm's job is to choose which three.

In job sequencing with deadlines, a job assigned to slot t > d_i
  1. Earns profit 0 — the deadline was missed
  2. Earns p_i anyway, because the machine ran it
  3. Splits across two slots

Profit is paid only for a slot at most d_i. Jobs are unit time, so there is nothing to split.

2Sort by profit, sit in the latest legal slot

The greedy order is decreasing profit. For the next job, scan slots d_i, d_i-1, \ldots, 1 and take the first one that is still free. If every legal slot is taken, reject the job.

Latest-fit is the rule that makes the order work. It parks a high-profit job as late as its deadline allows, so an earlier slot stays available for a later job in the list whose deadline is tighter. The sort is O(n \log n); each placement is a scan of at most D slots.

Same three slots; J1 occupies slot 2 and J3 occupies slot 1, as the ledger says.

Place one job

  1. OrderJobs already sorted by p_i decreasing.
  2. Scan right to leftTry slot d_i, then d_i-1, down to 1.
  3. Take or skipFirst free slot wins. None free → profit 0 for this job.

Latest-slot placement

def job_sequence(jobs):
    jobs = sorted(jobs, key=lambda j: j['profit'], reverse=True)
    D = min(len(jobs), max(j['deadline'] for j in jobs))
    slot = [None] * (D + 1)
    for j in jobs:
        for t in range(min(D, j['deadline']), 0, -1):
            if slot[t] is None:
                slot[t] = j['id']
                break
    return slot[1:]

Place J1 then J3

Slots 1,2,3 empty. J1 has deadline 2 profit 100. J3 has deadline 2 profit 27. Where does each sit?

  • J1: latest t \le 2 freeslot 2
  • J3: latest t \le 2 freeslot 1 (2 taken)
  • slot 3still empty — saved for a deadline-3 job

Pro tip. If J1 had taken slot 1, J3 would have been rejected and slot 2 would sit empty until a later job. Latest-fit avoids that hole.

After sorting by profit, a job with deadline 2 is placed
  1. In the latest free slot among \{1,2\}
  2. In slot 1 always, to finish as soon as possible
  3. In any free slot, because unit jobs commute

Latest free legal slot is the algorithm. Earliest-fit is a different rule and can lose profit. Slots are not interchangeable once deadlines differ.

3Five jobs finish at profit 142

Running instance: J1 deadline 2 profit 100, J2 deadline 1 profit 19, J3 deadline 2 profit 27, J4 deadline 1 profit 25, J5 deadline 3 profit 15. Profit order J1, J3, J4, J2, J5. Slots: J1 in 2, J3 in 1, J4 and J2 rejected (slot 1 taken), J5 in 3.

Time order is J3, J1, J5. Profit 27+100+15=142. The two rejected jobs are the two cheapest; the greedy spent the three slots on the three profits that fit.

Figure. Final one-machine schedule: J3 in slot 1, J1 in slot 2, J5 in slot 3. Profits 27, 100, 15.

The five decisions

  1. J1 then J3Slots 2 and 1 filled, 100 + 27.
  2. J4, J2Only legal slot is 1, already taken — skip both.
  3. J5Latest t \le 3 free is slot 3 — take 15.

Add the accepted profits

Accepted jobs J3, J1, J5. Confirm the profit and that no accepted job misses its deadline.

  • slot 1 = J3, d=21 \le 2 — paid 27
  • slot 2 = J1, d=22 \le 2 — paid 100
  • slot 3 = J5, d=33 \le 3 — paid 15
  • 27+100+15142

Pro tip. J4 at 25 looks tempting for slot 1, but J3 at 27 already owns it. The difference is 2, not a rounding error.

Coding lab. Five jobs, profit 142 runs in the app, with checks on your output.

On the running instance the accepted profit is
  1. 142 from J3, J1, J5
  2. 152 from J1, J3, J4
  3. 100 from J1 alone

J4 and J3 both need a slot \le 2, and J1 already took slot 2, so only one of J3/J4 can join J1. The greedy kept 27 over 25. J5 fills the leftover slot.

4Not earliest-finish activity selection

Activity selection maximises the count of non-overlapping intervals by sorting on earliest finish time. Job sequencing maximises profit of unit jobs under deadlines by sorting on profit and packing latest legal slots. The sort key, the objective, and the placement rule are all different.

Using earliest-finish on this instance is the wrong algorithm: the jobs are not intervals with start and finish, they are unit cells with a last-legal-cell. Multiprocessor makespan (identical processors) is a third problem — m machines, variable times, no per-job profit — and lives in the NP-scheduling topic.

No new Gantt — the three-row problem table is the comparison.

Three scheduling words
ProblemSort / ruleObjective
Activity selectionEarliest finishMax count of intervals
Job sequencingProfit, then latest slotMax profit under deadlines
Identical processorsNot this greedyMin makespan on m machines
Sorting jobs by earliest deadline and packing earliest free slots
  1. Is not the job-sequencing greedy — that greedy sorts by profit and packs latest slots
  2. Is the job-sequencing greedy, because deadlines are the scarce resource
  3. Is activity selection, so it maximises profit as a side effect

Deadline-sort earliest-fit is a different algorithm. Activity selection maximises count, not profit, and needs start/finish intervals.

Notes

  • Job sequencing with deadlines: n jobs, one machine, each job takes one time slot, job i has deadline d_i and profit p_i if it finishes by d_i (else profit 0).
  • The feasible slot set is \{1,2,\ldots,D\} where D = \min(n, \max d_i). At most one job occupies a slot.
  • Greedy: sort jobs by decreasing profit; for each job, assign the latest still-free slot t with 1 \le t \le d_i; skip the job if no such slot remains.
  • Latest-fit leaves earlier slots free for jobs whose deadlines are tighter. Earliest-fit of the same profit order can block a later high-profit job that needed that early slot.
  • This is not activity selection (max count, earliest finish) and not multiprocessor makespan. Those live in greedy and in NP-scheduling.

Formulas

  • At most D = \min(n, \max_i d_i) jobs can be accepted.
  • Sort O(n \log n); placing each job is O(D) by a right-to-left scan, so O(n \log n + nD).
  • Profit of a schedule = sum of p_i over jobs that received a slot \le d_i.
  • A slot t may hold a job only if d_i \ge t.

Exam traps & shortcuts

  • Sort by profit, not by deadline. Deadline only names the legal slots.
  • Place in the latest legal free slot, not the earliest. Earliest-fit of the same order is a different algorithm and can lose profit.
  • A rejected job is not 'failed forever' in the sense of backtracking — the greedy never revisits it. That is the algorithm, not a bug.
  • Unit time is load-bearing. Variable-length jobs on one machine with deadlines is a different (harder) problem.

Reference tables

Profit order J1, J3, J4, J2, J5. Slots 1..3.

Running instance
JobDeadlineProfitSlot
J121002
J32271
J4125rejected
J2119rejected
J53153

Recap

Night-before job-sequencing pegs.

Model
One machine, unit jobs, profit only if slot \le d_i.
Greedy
Sort by profit down; latest free legal slot; skip if none.
142
J3, J1, J5 in slots 1, 2, 3. J4 and J2 out.
Not
Not earliest-finish activity selection. Not multiprocessor makespan.

Practise Job Sequencing with Deadlines

Reading is free and needs no account. Practice, mocks and progress live in the app.

  • A 5-question practice set that ends the chapter
  • 4 quick checks with worked explanations
  • Timed mocks scored with the real marking scheme
  • Readiness tracked per topic, kept on your device
Continue with Google — freeNo card, no trial. Works offline once installed.