- Note that
*f*_{j}always has the maximum finish time of any activity in A - Greedy-AS takes time
- This algorithm is greedy because it always picks the activity with the earliest compatible finish time (leave as much time as possible)
- Optimal?
? Yes - Proof
- Note that if ordered by
*f*_{i}, activity 1 has earliest finish - Show that there exists an optimal solution that begins with a greedy choice (activity 1).
- Let A S be an optimal solution. If the first activity in A is (not greedy), then there exists another optimal solution B that begins with 1.
- B = A - {k} {1}
- Because , activity 1 is still compatible with A
- B
= A,
so B is also optimal. Thus there exists
an optimal solution that
**begins**with a greedy choice. - Now prove optimal substructure.
Once we make the first greedy choice, now the problem is
,
with
**optimal solution**A' = A - {1}. - This solution must be optimal. If B' solves S' with more activities than A', adding activity 1 to B' makes it bigger than A, which is a contradiction.
- Therefore, greedy choice yields an optimal solution.

- Note that if ordered by