Activity Selection Problem and a “Last-Start” Greedy Strategy

Activity Selection Problem and a “Last-Start” Greedy Strategy

Verified Sources
Sep 13, 2026

The activity selection problem is a classic optimization problem on intervals. Each activity ii has a start time sis_i and finish time fif_i with si<fis_i < f_i. Two activities are compatible if they do not overlap, i.e., for activities ii and jj with fisjf_i \le s_j (equivalently, one finishes before the other starts).

A standard greedy strategy chooses the activity with the earliest finish time among those that are compatible with what you have already chosen. The variant you asked about uses a “reverse” viewpoint:

Instead of selecting the first compatible activity to finish, select the last activity to start that is compatible with all previously selected activities.

This “last-start compatible” rule is also a greedy algorithm, and it can be proven optimal by an exchange argument using interval ordering properties.

Key terms: compatible activities , greedy-choice property , exchange argument , optimal substructure.


Activity Selection Problem (Greedy Algorithm)

Formal problem statement

Let the set of activities be A={1,2,,n}A=\{1,2,\dots,n\}. Activity ii is the closed-open interval [si,fi)[s_i, f_i) (any consistent overlap convention works). We want a maximum-size subset SAS \subseteq A such that for any two activities i,jSi,j \in S, they do not overlap: if ii precedes jj then fisjf_i \le s_j.

A greedy algorithm repeatedly extends a partial solution by choosing a single “best” activity according to some local rule, without reconsidering earlier choices.

In the last-start compatible strategy, we proceed like this:

  1. Maintain the already selected set (initially empty).
  2. Among activities that are compatible with all already-selected ones, choose the activity with the largest start time.
  3. Add it to the set.
  4. Repeat on the remaining activities that are compatible with the augmented set.

To make implementation and reasoning clean, we typically order activities by finish time (or by start time depending on the proof). For the last-start strategy, ordering by start time is intuitive, but the proof can be framed using finish times to preserve the non-overlap structure.

Key terms: interval ordering , selection subset , feasible solution , maximal cardinality.

Last-Start-Compatible Greedy Algorithm (Reverse selection)

  1. 1
    Step 1

    Maintain a set S of chosen activities. An activity a is compatible with S if it does not overlap any activity in S; under a chosen ordering of S, this reduces to checking that its finish time is <= the next selected start time.

  2. 2
    Step 2

    Among all activities compatible with S, pick the activity with the largest start time. (Equivalently: pick the “rightmost” activity that still fits before the already-chosen boundary.)

  3. 3
    Step 3

    After selecting activity a, update the boundary to the selected activity's start time. Only activities that finish no later than that boundary can remain compatible.

  4. 4
    Step 4

    When no remaining activity can be added without overlapping S, stop. The resulting S is the output.

  5. 5
    Step 5

    S contains a feasible subset. The proof below shows its size is maximal.

Why this is a greedy algorithm

By construction, at each step the algorithm makes a single local decision: it chooses the compatible activity with the largest start time and never revisits that choice.

Formally, let SkS_k be the set selected after kk iterations. The (k+1)(k+1)-st iteration picks an activity ak+1a_{k+1} that:

  • is compatible with SkS_k, and
  • maximizes sas_a among such compatible candidates.

This is the hallmark of the greedy paradigm: a local optimization criterion that determines the next element of the solution.

Key terms: greedy choice , partial solution , iteration invariant.

Correctness proof (optimality via exchange argument)

We prove that the “last-start compatible” greedy strategy yields an optimal solution (maximum number of non-overlapping activities).

Setup and ordering

Let the activities be distinct or ties handled consistently. Sort activities by start times decreasing (so “last to start” means highest start time).

At any stage, the already selected activities form a feasible schedule. Let the “current boundary” be the earliest start time among activities already selected (because we are building backward: we pick an activity that must end before the boundary starts, so it can fit without overlapping what is already selected).

Define a subproblem: given a boundary time TT, consider only activities that finish at or before TT:

A(T)={ifiT}.A(T) = \{ i \mid f_i \le T \}.

Then the goal is to select the maximum number of pairwise non-overlapping activities from A(T)A(T).

The greedy rule chooses, from A(T)A(T), the activity g(T)g(T) with the largest start time:

g(T)argmaxiA(T)si.g(T) \in \arg\max_{i \in A(T)} s_i.

After choosing g(T)g(T), we update the boundary to sg(T)s_{g(T)}, because any additional activity must end before the start of the newly chosen one.

Thus, the algorithm is recursively:

  • pick g(T)g(T),
  • then solve the subproblem with boundary T=sg(T)T' = s_{g(T)}.

Lemma (greedy-choice property)

Lemma: There exists an optimal solution for subproblem A(T)A(T) that includes the greedy choice g(T)g(T).

Proof (exchange argument): Let OO be an optimal solution for A(T)A(T). If g(T)Og(T) \in O, we are done.

Otherwise, g(T)Og(T) \notin O. Consider the activity oOo \in O that is the first activity in OO (in the backward sense) that conflicts with g(T)g(T) or, equivalently, the activity in OO with the largest start time among those that are compatible to the same extent. A more direct interval argument works:

  • Since both g(T)g(T) and activities in OO are feasible within A(T)A(T), every activity in OO must lie in time positions that do not overlap each other, and they all finish by TT.
  • Let jj be the activity in OO with the largest start time among those in OO. Because OO is a set of non-overlapping intervals within (,T](-\infty, T], these intervals have an induced order.
  • Compare g(T)g(T) with jj. By definition of g(T)g(T), we have sg(T)sjs_{g(T)} \ge s_j.
  • Replace jj with g(T)g(T) in OO to form a new set: O=(O{j}){g(T)}.O' = (O \setminus \{j\}) \cup \{g(T)\}. We claim OO' is feasible and has the same cardinality.

Feasibility reasoning: because g(T)g(T) has the latest start among all activities that finish by TT, and because jj was the latest-start interval in OO, swapping g(T)g(T) in cannot create overlap with activities earlier in the schedule (they all end \le the start boundary imposed by the later activity), and g(T)g(T) also finishes by TT so it does not overlap the later-than-TT region (none exists). Therefore, all non-overlap constraints remain satisfied.

Thus, OO' is feasible, has O=O|O'|=|O|, and includes g(T)g(T). Hence, there exists an optimal solution that contains the greedy choice. 

Theorem (global optimality)

The greedy algorithm is optimal: the solution it outputs has maximum possible size.

Proof (induction on the number of activities / subproblem boundary): We prove by induction on the “size” of the subproblem A(T)A(T) (e.g., number of candidate activities).

  • Base case: If A(T)A(T) is empty or contains only one activity, the greedy algorithm is trivially optimal.
  • Inductive step: Assume the algorithm is optimal for all smaller subproblems (with earlier boundaries). Consider subproblem A(T)A(T).
    • By the Lemma, there exists an optimal solution OO that includes the greedy activity g(T)g(T).
    • After selecting g(T)g(T), the remaining activities must all lie in the subproblem with boundary T=sg(T)T' = s_{g(T)}.
    • The greedy algorithm then solves this subproblem optimally by the induction hypothesis.
    • Therefore, combining g(T)g(T) with the optimal remaining solution produces an optimal solution for A(T)A(T).

Hence, by induction, the greedy algorithm yields a globally optimal maximum-size feasible set. 

Key terms: subproblem boundary , induction on subproblems , feasibility preserved.

type="tip" title="How to remember the proof idea" content="Both earliest-finish and last-start versions work because you can show: (1) a greedy choice can be forced into some optimal solution via exchange, then (2) the remainder is an independent smaller subproblem (optimal substructure)."

type="warning" title="Common proof pitfall" content="If you define the “boundary” incorrectly (e.g., using finish time instead of the correct start boundary when building backward), the exchange step may no longer preserve feasibility. Always align the boundary with the direction you’re selecting."

Greedy selection flow (backward construction)

Start with an empty schedule

T = +∞ (conceptual)

No activities chosen; all activities finishing by T are available."

Pick activity with last start time

Step 1

Choose g(T)g(T) with the maximum sis_i among those with fiTf_i \le T."

Set $T \leftarrow s_{g(T)}$

Update boundary

Only activities that finish before the chosen activity starts remain compatible."

Continue until no candidate remains

Repeat

The accumulated set is maximum-size by the correctness proof."

Greedy rule comparison (conceptual)

Both strategies are greedy but choose different local “best” elements.

Common questions

Activity Selection — Greedy Proof Essentials

1 / 5
Question · Term

Define [activity selection problem]{def="Choose the maximum number of non-overlapping activities from given intervals"}

Click to reveal
Answer · Definition

Select a maximum-cardinality subset of intervals such that no two overlap.

Knowledge Check

Question 1 of 4
Q1Single choice

In the last-start compatible greedy algorithm, what is the local choice at each step?