04 Try it yourself Interactive

Step through it, then watch greedy lose

Two modes, one press at a time. Activity selection walks whatever events you load in finish order and accepts or rejects each one — green bars are taken, rose bars are gone for good. Coin change runs the same amount twice: greedy first, then the answer dynamic programming finds, so you can compare the two counts. On some coin sets a gap opens up; on others greedy happens to tie, and the line under the controls tells you which.

Activity selection
sorted by finish time · greedy is optimal here
2–7 events as start-end pairs, e.g. 1-5, 4-6.
Press Next to begin. Each press moves one step.


      
Hall free at
Now checking
Taken
Skipped0
step 0 / 0