Why it matters

Activity selection is greedy classic. Understanding shapes greedy proofs.

Advertisement

The architecture

Sort by finish time.

Pick earliest.

Skip overlapping; repeat.

Activity selection greedySort by finishascendingPick earliestcompatible nextSkip overlapsnext non-conflictExchange argument proves optimality; sort dominates cost
Activity selection.
Advertisement

How it works end to end

Exchange argument for optimality.

Sort O(n log n); scan O(n).

Weighted variant needs DP.