Greedy algorithms solve problems by making the best immediate choice at each step, aiming for a globally optimal solution. They are not always correct, but often efficient.

Greedy algorithms are powerful and widely applicable, and studying them helps understand many fundamental algorithms.

15.1 An activity-selection problem

We want to schedule the maximum number of non-overlapping activities in a single resource. Each activity has a start and finish time. Two activities are compatible if their times do not overlap.

Dynamic Programming Approach:

Key Insight (Greedy):

Instead of checking all activities, we can always pick the activity that finishes earliest. Then only one subproblem remains, making the solution much simpler.

image.png

Making the greedy choice

Instead of solving all subproblems like in dynamic programming, we can make one simple choice: always pick the activity that finishes earliest. This leaves the resource available for as many remaining activities as possible.