Activity Selection Problem
We are given activities indexed from 1 to . Activity has start time and end (finish) time . We cannot participate in two activities that occur at the same time.
We want to determine the maximum cardinality set of non-overlapping activities. Essentially, we want to see the maximum number of activities we can do.
Important Observation
Let be an activity with minimum finish time. We claim that some optimal solution contains .
To prove this claim, we can use the “exchange argument”:
- Suppose is an optimal solution that does not include
- Let be the first activity in
- Then is an optimal solution that includes
Activity Selection Algorithms
Activity Selection Greedy Algorithm
- Re-index the activities in non-decreasing order of finish time.
- Initialize to and to .
- Let be a minimum-index activity in
- Add to
- Eliminate from all indices such that activities and overlap
Fast Implementation
- Re-index the activities in nondecreasing order of finish time
- Initialize to and to
- For running from 2 to
- If the start time of activity is at least the finish time of activity , then add to and set to