Introduction to Greedy Algorithms
Objectives
We would like to :
- Understand the basics of greedy algorithm design.
Notes
- For this I am using Tim Roughgarden's Algorithms Illuminated, Part3: Greedy Algorithms and Dynamic Programming.
- He describes the greedy paradigm as: Construct a solution iteratively, via a sequence of myoptic decisions, and hope that everything works out in the end.
- That might be a bit flippant
- CLRS says: Always make a choice that seems best at the moment.
- This is a strategy that can work really well if you make the right greedy choice,
- But it is problematic if you do not.
- Roughgarden says that greedy algorithms are
- Usually easy to come up with
- Generally easy to analyze
- Hard to establish correctness
- In his first chapter, he repeats over and over again
- Warning: Most greedy algorithms are not always correct.
- Frequently greed solutions miss edge cases or other special cases.
- Proving that your greed solution is optimal is frequently very difficult
- or impossible because it is not.
- CLRS lists the following as the elements of a greedy strategy
- Determine the optimal substructure of the problem
- Develop a solution (most likely recursive)
- Show that if you make the greedy choice, then only one subproblem remains
- Prove that it is always safe to make the greedy choice
- Develop an algorithm that implements the greedy strategy