Greedy Algorithm definition
A greedy algorithm builds a solution by making the best available local choice at each step according to a stated rule.
Greedy Algorithm in a picture
How it works
Once chosen, a step is typically kept while the algorithm moves on. A greedy rule can give an optimal result when the problem has a suitable structure, but a proof is needed. Choosing the largest value now can miss a better combination later.
Worked examples
Using coin values 1, 5, and 10, what does largest-first choose for 16?
10, then 5, then 1.
Does a locally best step always yield the best complete solution?
No. The example with 1, 3, and 4 shows a failure.
What would show a greedy method works for every input?
A correctness proof that the local rule can always produce an optimal solution.
Common mistake
State the selection rule and verify its correctness. A few successful examples do not establish general optimality.
Quick check
Can a greedy method give a nonoptimal answer?
Show answer
Yes.
What can disprove a greedy rule?
Show answer
One valid input where it misses the optimum.
Sources
Flashcard
Greedy Algorithm
Reveal the definition
A greedy algorithm builds a solution by making the best available local choice at each step according to a stated rule.
Effortless Math. “Greedy Algorithm.” Math Dictionary.



