Job and Activity Selection: Greedy Rules, Worked Examples and Exam Traps
Learn why activity selection sorts by finish time while unit-time job sequencing sorts by profit. Trace both algorithms, test their invariants, and avoid the standard traps.
KnowledgeGate Team
Exam prep & CS education

Activity selection and job sequencing are both greedy selection problems, yet they optimise different objectives and need different sorting keys. Mixing their rules gives plausible but wrong answers. Exchange arguments justify both choices, and concrete counterexamples break tempting alternatives.
Job and activity selection are two different greedy problems
In activity selection, activity i has start time s_i and finish time f_i. Choose the largest pairwise compatible set for one resource. Here, a new activity is compatible when start >= last_finish, so it may start exactly when the previous one finishes.
In job sequencing with deadlines and profits, every job takes one time slot. Job i has deadline d_i and profit p_i, earned only if it finishes by its deadline. Maximise total profit, not job count.
Feature | Activity selection | Job sequencing |
|---|---|---|
Input | Start and finish times | Deadline and profit |
Objective | Maximum compatible activity count | Maximum total profit |
Greedy key | Non-decreasing finish time | Descending profit |
Placement rule | Accept if | Use the latest free slot at or before the deadline |
Critical assumption | One resource, unweighted activities | One machine, unit-time jobs |
Weighted interval scheduling, variable-duration jobs, and multiple-machine scheduling are different problems. Keep those boundaries visible while studying Algorithms through the GATE CS exam preparation courses and test series.
Activity selection uses the earliest-finish greedy choice
Sort by non-decreasing finish time and accept the first activity. Scan left to right, accepting activity i exactly when s_i >= last_finish, then set last_finish = f_i. A deterministic tie-break such as input order makes tied output repeatable without changing optimal cardinality.
Why earliest finish? In an optimal solution, replace the first choice with the globally earliest finisher. It finishes no later, so no later chosen activity becomes incompatible and the count does not fall. Repeat this exchange on the remaining suffix.
Sorting costs O(n log n) and the scan costs O(n), giving O(n log n) time overall. If the input is already sorted by finish time, the scan alone is O(n). The earlier Greedy Algorithms: Strategy and Problems guide introduces exchange arguments and summarises this classic interval set. Here, the same eleven intervals are expanded into every accept/reject state so you can compare activity selection directly with unit-time job sequencing.
Activity selection worked example: trace all eleven intervals
The activities are already sorted by finish time.
Activity | Interval | Decision | Reason or new state |
|---|---|---|---|
A1 | (1,4) | Select | First choice, |
A2 | (3,5) | Reject |
|
A3 | (0,6) | Reject |
|
A4 | (5,7) | Select |
|
A5 | (3,9) | Reject |
|
A6 | (5,9) | Reject |
|
A7 | (6,10) | Reject |
|
A8 | (8,11) | Select |
|
A9 | (8,12) | Reject |
|
A10 | (2,14) | Reject |
|
A11 | (12,16) | Select |
|
Therefore the selected sequence is [A1, A4, A8, A11], and the selected count is 4. This is a maximum-size compatible set. No profit was given or maximised.

Job sequencing uses profit order and the latest free slot
Sort unit-time jobs by descending profit and create slots 1..D, where D is the maximum deadline. Place each job in the latest free slot at or before its deadline, rejecting it only when no such slot exists. If jobs are optional, skip non-positive-profit jobs.
Profit order protects valuable rewards. Latest-slot placement preserves early slots for tighter deadlines. Moving a chosen job from an earlier slot to a later valid slot keeps it feasible without reducing other jobs' options.
A direct backward slot scan takes O(n log n + nD) time and O(D) space. A disjoint-set predecessor structure gives near-constant amortised lookup and O(n log n + n alpha(D)) overall. The simple scan suffices by hand.
Job sequencing worked example: three-slot schedule and greedy placements
Use J1(deadline=2, profit=100), J2(deadline=1, profit=19), J3(deadline=2, profit=27), J4(deadline=1, profit=25), and J5(deadline=3, profit=15). The maximum deadline is 3, so begin with free slots [1,2,3].
Profit order is J1(100), J3(27), J4(25), J2(19), J5(15).
Put
J1in its latest available slot, slot2.For
J3, slot2is occupied, so put it in slot1.Reject
J4because its only valid slot, slot1, is occupied.Reject
J2for the same reason.Put
J5in slot3.
The chronological schedule is [J3, J1, J5]. Its total profit is 27 + 100 + 15 = 142. Notice that profit-sorted consideration order and chronological execution order are different lists.

Job and activity selection traps need concrete counterexamples
Earliest start is wrong for activity selection. Consider L=(0,10), S1=(1,2), S2=(2,3), S3=(3,4), and S4=(4,5). Earliest start chooses L and then cannot choose anything else, giving count 1. Earliest finish chooses [S1,S2,S3,S4], a compatible set of 4 activities.
A profitable job should use its latest available slot. Let JA(deadline=2, profit=100), JB(deadline=1, profit=99), and JC(deadline=2, profit=1). If JA takes slot 1, JB is forced out and the best remaining addition is JC, giving 100 + 1 = 101. Put JA in slot 2 instead, and JB fits in slot 1, giving 100 + 99 = 199.
Use this fast trap checklist:
Do not sort activities by start time or profit.
Do not treat a deadline as an interval finish time.
Do not apply unit-time job sequencing to variable-duration jobs.
Do not add the profit of rejected jobs.
Do not confuse profit-sorted consideration order with chronological slot order.
Job and activity selection exam patterns test the trace and invariant
Conceptual problems may ask you to trace a table, identify the sorting key, compute count or profit, analyse complexity, fill a compatibility or slot condition, disprove a heuristic, or spot a broken assumption. KnowledgeGate has over 10 live Job and Activity Selection questions in its practice bank for practising the reasoning beyond one table.
Try two quick variations:
If
A11becomes(10,16), then after selectingA8the value oflast_finishis11. Reject the changedA11because10 < 11. The result is[A1,A4,A8], with count3.If
J5's profit becomes30, profit order becomesJ1,J5,J3,J4,J2. PlaceJ1in slot2,J5in slot3, andJ3in slot1. The schedule remains[J3,J1,J5], while profit becomes27 + 100 + 30 = 157.
When weights and arbitrary interval lengths appear together, earliest finish alone is no longer enough. That boundary is easier to see after studying Dynamic Programming Explained: 0/1 Knapsack. For optional timed practice across such distinctions, use the GATE Test Series.
Job and activity selection: the short decision checklist
Intervals plus maximum count: sort by earliest finish.
Unit-time jobs plus deadlines and profits: sort by profit, then place each job in the latest free slot.
Weights with arbitrary interval lengths, or variable job durations: stop and reformulate instead of forcing either greedy rule.
The two checksums are activity set [A1,A4,A8,A11] with count 4, and job schedule [J3,J1,J5] with profit 142. A learner building wider Algorithm foundations can use GATE Guidance by Sanchit Sir for a broader subject plan. If you only needed this distinction, rework both tables once from blank paper.
Keep learning
Job and Activity Selection Interview Questions and Answers: Greedy Traces and Proofs
Learn to separate activity selection from unit-time job sequencing, trace both greedy algorithms, defend their proofs, and handle common interview follow-ups.
Job Sequencing and Activity Selection MCQs: 12 Solved Questions with Explanations (GATE/NET/ISRO)
Solve 12 activity selection and job sequencing questions step by step. The set covers greedy rules, compatibility, room counting, feasible schedules and maximum-profit slotting.
Software Process and Generic Process Model MCQs: 10 Solved Questions on Framework Activities and Patterns
Test the boundaries that make software-process questions tricky. Each MCQ includes its answer, cue words, distractor repair, and a concrete help-desk example.
Multi-Topic Algorithm Problems Explained: Greedy, DP and Complexity in One Worked Example
Use one four-item 0/1 knapsack instance to separate modelling, greedy output, DP optimality, proof and pseudo-polynomial complexity.





