What are Divide-and-Conquer, Greedy, and Dynamic Programming?
Divide-and-conquer, greedy, and dynamic programming, told as a story about the student council allocating twenty clubs' festival budget with three different methods. (These are algorithm design techniques, not law or policy — but even the council solves a hard decision with a clear procedure.)
Deciding the festival budget for twenty clubs at once is too complicated.Too many clubs to compare all at once.
Granting budgets purely by submission order is unfair.Handing out money by submission order alone misses a fairer split.
There are three ways to solve a big problem: divide-and-conquer, greedy, and dynamic programming.Even the student council should follow a clear procedure for a hard decision, just like an algorithm.
Applied to the festival budget, the three differ in how they split, what they pick first, and how often they recalculate.The right method depends on whether the problem splits cleanly or repeats the same subproblems.
Greedy is fast because it skips comparing every combination, but it isn't always the best.Greedy is fast — but it doesn't always guarantee the overall best.
Divide-and-conquer splits a problem and combines the results, greedy always picks the best choice right now, and dynamic programming remembers an already-solved answer instead of re-solving it.
Divide-and-conquer splits a problem into independent smaller subproblems, solves each, and combines the results (e.g., merge sort). Greedy repeatedly picks whatever choice looks best at each step without considering the whole picture — fast, but not always globally optimal (though for some problems, like minimum spanning trees, it is). Dynamic programming stores the result of a subproblem once computed (memoization) and reuses it, avoiding redundant recomputation — suited to problems with optimal substructure and overlapping subproblems. All three handle a big problem in smaller pieces, but they differ in how they treat those pieces.
When grown-ups say it
- Divide and Conquer
- Splitting a problem, solving the pieces, then combining. Sorting gives a concrete example. → different ways to line cars up by size
- Greedy Algorithm
- Picking whatever looks best right now, every time. Greedy is provably optimal for connecting every point at the lowest cost. → piping every branch together for the least cost
- Dynamic Programming
- Remembering an already-solved answer and reusing it. Never solves the same subproblem twice.
- Memoization
- The technique of storing a result once it's computed. A common way to implement dynamic programming.
- Optimal Substructure
- The property that optimal sub-answers combine into the optimal whole. Dynamic programming only works when this property holds.
- Overlapping Subproblems
- The same small problem showing up again and again. Memoization only pays off when the same subproblem repeats.
- Backtracking
- Backing up and trying another path when stuck. Yet another strategy for tackling a big problem.
- Time Complexity (Big-O)
- The ruler that measures how much slower an algorithm gets as a problem grows. All three methods are compared using this same ruler. → how much slower as cars pile up