Greedy algorithms build a solution step-by-step by choosing the best-looking option right now, then committing to it (no backtracking). They can be extremely fast — but only work when the problem has the right structure.
Greedy bets that choosing “best now” will not block the best final solution.
Many greedy algorithms look different on the surface, but they share the same skeleton: keep selecting the “best” remaining candidate, and only accept it if the partial solution stays feasible.
Greedy(A):
solution = ∅
repeat:
x = Select(A) // greedy choice rule
if Feasible(solution ∪ {x}):
solution = solution ∪ {x}
return solution
Solution space = the set of all feasible solutions (valid ones). The optimal solution is the best among them for the objective (maximum profit, minimum cost, etc.).
There exists an optimal solution that begins with the greedy choice.
After making a choice, the remaining problem is a smaller version of the same problem.
| Paradigm | Key idea | Revisits choices? | Typical examples |
|---|---|---|---|
| Greedy | Pick best now, commit | No | Kruskal, Prim, Dijkstra, Huffman |
| Divide & Conquer | Split → solve → combine | No | Merge sort, Quick sort, Karatsuba |
| Dynamic Programming | Try alternatives + store best | Yes | 0/1 Knapsack, LCS, Matrix-chain |
Next pages will apply this template in classic greedy problems (Knapsack, Job Sequencing, Huffman).
Try the famous counterexample: coins {1,3,4}, amount 6. Greedy picks 4+1+1 (3 coins) but optimal is 3+3 (2 coins).