A classic greedy problem of selecting the maximum number of non-overlapping activities.
The Activity Selection Problem is a canonical example used to illustrate the power of greedy algorithms. The problem is as follows: given a set of activities, each with a start time and a finish time, select the maximum number of activities that can be performed by a single person, assuming that a person can only work on a single activity at a time. The greedy strategy that solves this problem is surprisingly simple and intuitive: always choose the next activity that finishes earliest among those that do not conflict with the previously chosen activity. To implement this, we first sort the activities by their finish times in ascending order. We select the first activity from this sorted list. Then, we iterate through the remaining activities and select the next activity whose start time is greater than or equal to the finish time of the previously selected activity. This process continues until we have considered all activities. The reason this greedy choice works is that by picking the activity that finishes earliest, we maximize the amount of time remaining for other activities to be scheduled. This proof of correctness is a key part of understanding why greedy algorithms are effective for certain problems.