🧮Greedy Algorithm
Also known as Greedy Method, Greedy Approach
Taking the choice that looks best at each step. It never goes back.
Think of it like
Think of it like grabbing the biggest coin each time you pay. It is quick, but not always best.
Example
Emma makes 6 cents from coins of 1, 3 and 4. Greedy takes 4, 1, 1, three coins, but 3 and 3 needs only two.
Why it matters
When it works it is the fastest way, and Dijkstra's algorithm is one. You must check that it works first.
Definition
Common mistake
Key takeaways
- 1Best right now. At each step.
- 2No going back. Choices are final.
- 3Fast but risky. Not always the best.