Definition · Combinations and ordered sequencesA combination is a multiset of coins adding to the amount: how many of each denomination, with no notion of order. An ordered sequence is a list of coins adding to the amount, where two lists differing only in order are different. Every combination corresponds to one or more ordered sequences, and the two counts are never equal once more than one denomination is used.
Theorem · The two counting recurrencesLet C(i, v) be the number of combinations of the first i coin types adding to v, with C(i, 0) = 1 and C(0, v) = 0 for v > 0. Then C(i, v) = C(i−1, v) + C(i, v − c(i)), the second term omitted when c(i) > v. Let S(v) be the number of ordered sequences adding to v, with S(0) = 1. Then S(v) is the sum of S(v − c) over all coins c ≤ v.
For combinations, split on how many copies of coin type i are used. If none, the combination uses the first i−1 types and there are C(i−1, v) of those. If at least one, remove exactly one copy and what remains is a combination of the first i types adding to v − c(i), and this correspondence is a bijection. The two cases are disjoint and exhaustive, so the counts add.
For sequences, split on the last coin. Each sequence adding to v has a final coin c, and deleting it leaves a sequence adding to v − c; conversely appending c to such a sequence gives one adding to v. That is a bijection for each c, the cases are disjoint because the final coin differs, and summing over c gives S(v). The single-row loop with the amounts outermost is exactly this recurrence, and the one with the coins outermost is exactly the other.
□
Example · Five from 1, 2 and 5, with the objects listedFour combinations: 5, 2 + 2 + 1, 2 + 1 + 1 + 1, 1 + 1 + 1 + 1 + 1. Nine ordered sequences: the five ones; 1 1 1 2 and its three other arrangements; 1 2 2, 2 1 2 and 2 2 1; and 5. Four and nine, and the lab lists both at this size so the difference is an object rather than a number.
Notice which objects multiplied. The combination 2 + 2 + 1 has three arrangements and the combination 2 + 1 + 1 + 1 has four, while 5 and the five ones have one each: 1 + 4 + 3 + 1 = 9. The ratio between the two counts is not a constant and is not a factorial — it depends on how many copies of each denomination each combination uses.
The cost is the same; the question is not
On the lab's main instance — 1, 2 and 5 at an amount of 100 — both nestings read the table 295 times. Identical work, identical table, identical arithmetic per step. The only difference is which loop is outside, and the two answers differ by twenty orders of magnitude. There is no performance argument for either one and there is no way to tell them apart by watching them run.
This is the most direct version of a claim this course keeps making. A measurement of what an algorithm costs tells you nothing about what it computes, and here the two are completely decoupled: same reads, same cells, different question. The only defence is a second route, and the panel provides one — a memo-free recursion for each count, which at small amounts confirms both, and the objects themselves listed where they fit.
Why these numbers are not held as doubles
91 197 869 007 632 925 819 218 has twenty-three digits, and the largest integer a double holds exactly is 9 007 199 254 740 992, which has sixteen. A page computing this count in floating point would print a number that is merely close — the leading digits right, the tail invented — and would look exactly like a page that had computed it. Every count of ways in this kit is an arbitrary-precision integer for that reason, and none is ever converted.
One consequence for the cost model, and it is the divergence this page closes on. The table makes 295 reads, and each read is followed by an addition; but those additions are on numbers of up to twenty-three digits, not on machine words. The bound Θ(nk) counts arithmetic operations and treats each as constant, which is exactly what stops being true here. Measured: 295 reads. Proved: Θ(nk) operations. What neither of them says is how long an addition takes when the numbers are as long as the answer, and on this instance it is the addition that dominates.