Lessons 21–25 · About 60 min per lesson
Intervals and basic greedy methods
Choose a greedy rule for the objective and check it with an exchange argument or counterexample.
Lesson breakdown
- Lesson 21
Distinguish closed and half-open intervals and touching endpoints.
- Lesson 22
Sort and merge overlapping intervals.
- Lesson 23
Select a maximum number of nonoverlapping activities by finish time.
- Lesson 24
Explain earliest-finish selection by exchanging the first activity.
- Lesson 25
Refute earliest-start selection with one long activity and several short ones.
Worked example
Activities [1,4), [2,3), [3,5) may touch at endpoints. Maximise the number selected.
How to solve it
Choose the earliest finish [2,3), then [3,5), for 2. Starting with [1,4) gives only 1.
Assignment
Implement half-open activity selection and check it by enumerating subsets of a small set.
Check your result
The example gives 2; three consecutive positive-length activities give 3; three identical activities give 1.