Greedy Scheduling / Sorting
Sort by a useful criterion and make locally optimal choices when an exchange argument supports them.
The task involves scheduling, jumps, assigning resources, or selecting a maximum compatible set.
How to approach it
Identify the choice rule, test it on edge cases, then justify why swapping an optimal solution to use your choice cannot make it worse.
A plausible greedy rule is not proof. Some optimization problems require dynamic programming instead.
Practice question
What is the maximum number of non-overlapping activities: [1,3], [2,4], [3,5], [5,7]?
activities = [[1,3], [2,4], [3,5], [5,7]]Give your answer before revealing the explanation.Show a hint
Sort by end time and repeatedly choose the earliest-finishing compatible activity.
Show an answer
3 activities: [1,3], [3,5], [5,7] when touching endpoints are allowed.
Greedy Scheduling / Sorting at work
One technician can handle one repair at a time. Jobs occupy [1,3], [2,4], [3,5], and [5,7]. What is the largest number of jobs they can finish if one may start exactly when another ends?
Show one possible approach
3 jobs: [1,3], [3,5], and [5,7]. Sorting by finish time lets you repeatedly take the compatible job that frees the technician soonest.
Practice next
Use these problem IDs to find additional practice for this pattern: