CS146
Chris Pollett
Apr 30, 2014
Theorem. Consider any nonempty subproblem `S_k`, and let `a_m` be an activity in `S_k` with the earliest finish time (might be more than one). Then `a_m` is included in some maximum-size subset of mutually compatible activities of `S_k`.
Proof. Let `A_k` be a maximum-size subset of mutually compatible activities in `S_k` and let `a_j` be the activity in `A_k` with the earliest finish time. If `a_j = a_m` as then `a_m` would be in some maximal sized solution of the `S_k` subproblem. If `a_j ne a_m`, let `A_k' = (A_k - {a_j}) cup {a_m}`. The activities in `A_k'` are disjoint because the activities in `A_k` are disjoint, and `a_j` is the first activity in `A_k` to finish and `f_m le f_j`. Since `|A_k'| = |A_k|`, we conclude that `A_k'` is a solution as well. Moreover, it contains `a_m`. QED.
RECURSIVE-ACTIVITY-SELECTOR(s,f,k,n) 1 m = k + 1 2 while m ≤ n and s[m] < f[k] 3 m = m + 1 4 if m ≤ n 5 return {a_m} ∪ RECURSIVE-ACTIVITY-SELECTOR(s, f, m, n) 6 else return 0.