Definition · Overlapping subproblemsA recursive formulation has overlapping subproblems when the set of distinct arguments it is ever called with is much smaller than the number of calls it makes. The two numbers are both countable by running it, and their ratio is what a memo can save.
This is the second of the two properties a dynamic program needs, and it is the one about cost rather than about correctness. Optimal substructure says the recurrence is right. Overlapping subproblems says evaluating it naively is wasteful and that there is a specific, countable amount of waste to remove. A problem with the first and not the second is a divide-and-conquer problem, and a memo on it stores entries nothing ever reads.
Example · Eighteen from 1, 2 and 5, counted three waysThe lab loads this instance. The memo-free recursion answers 5 after 22 089 calls. The same recursion with a memo answers 5 after 50 calls, and reports that it stored eighteen distinct subproblems. The table answers 5 after filling 76 cells and making 106 reads, with no recursion at all. Three routes, one answer, three costs a factor of hundreds apart.
Fifty is worth deriving rather than accepting. The memoised function is entered once per distinct argument that is genuinely computed — eighteen of them, plus the base case — and each such call makes one sub-call per denomination that fits. Every one of those sub-calls is itself a call. So the total is one call to start with, plus one call for every edge leaving a computed amount — and the amounts 1 through 18 have out-degrees 1, then 2 three times, then 3 fourteen times, which is 49. One and 49 is 50. Nothing about that figure is a property of the memo as a technique; it is the size of the dependency graph.
The two numbers the panel separates, and why
The memo stores eighteen entries; the table fills 76 cells. Those count different things. The memo's key is the remaining amount alone, because the recursion may use any denomination at any step; the table's cell is a (denomination-prefix, amount) pair, because it is filled in an order and each row makes one more denomination available. Four rows by nineteen columns is 76. Both are correct formulations of the same problem with different state, and the choice of state is the design decision this course keeps returning to.
Theorem · The memoised recursion and the table compute the same functionFor every amount a reachable from the coin set, the value the memoised recursion returns for a equals the value in the table's last row at column a, and both equal f(a).
By strong induction on a. Both agree at a = 0, where each is 0. Suppose both compute f correctly at every amount below a. The memoised recursion evaluates 1 + min of f(a − c) over the denominations that fit, using stored values that are correct by hypothesis, so it returns f(a) by the theorem of the previous lesson.
The table's last row at column a takes the minimum over the same set of options, reached as a row of cells rather than as a set of calls: the cell for denomination prefix i and amount a is the better of the cell above it and one more than the cell c columns to its left in its own row. Unfolding that row from left to right gives exactly the same minimum. Both therefore equal f(a), and the memo's smaller entry count is a difference of state, not of answer.
□
What 441.8 times fewer does and does not say
The panel prints 22089/50 and its decimal to one place, and the exact fraction is there because the ratio is a count divided by a count and rounding it would misrepresent two integers as one estimate. It is a measurement on one amount with one coin system. The proved statement is different in kind: the table is Θ(nk) for n denominations and amount k, and the memo-free recursion's call count grows exponentially in k because the recursion tree branches at least twice at every level whenever two denominations fit.
The two statements diverge in a way this page can show you. At an amount of six with coins 1, 3 and 4 — the previous lesson's instance — the memo-free recursion makes 24 calls and the table fills 28 cells, so the exponential method is ahead. At eighteen with 1, 2 and 5 the same two routes cost 22 089 and 76. Nothing changed about either bound between those two runs. What changed is which side of the crossing the input sits on, and no count on either side of it is a statement about the other.
The plot beside the grid makes the shape visible: call counts against the amount, on a logarithmic axis, with a dashed reference curve. It stops at sixteen whatever the amount is set to, because the unmemoised arm is re-run at every point on every redraw and plotting further would cost a few million calls for a picture that has already made its point. The figure above the plot is the full amount.