1
$\begingroup$

I am looking for a formula or at least something to use when trying to compute how many ways I can make change for an amount.

Example: there are $3$ ways to give change for $4$ if you have coins with denomination $1$ and $2$: $1+1+1+1, 1+1+2, 2+2$.

What formula should I use?

$\endgroup$
0

2 Answers 2

4
$\begingroup$

This problem is called integer Partitioning. There is a recursive formula to list all possible partitions of an integer. Given a number of 4 you could generate the following sets of values:

4

3 1

2 2

2 1 1

1 1 1 1

Please refer to Wiki-Partitions for details. Unfortunately, it is not a trivial calculation.

There is another problem related to this that is called Money Changing Problem or Change Making Problem , where you'd be interested in specific values rather than getting all possible values. For example changing Five Dollars in a country where there is no 4 dollar notes or coins.

For such problems you may use R, Mathmatica, etc.

$\endgroup$
2
  • $\begingroup$ The question text clearly shows that this is Making Change rather than Partitions: "you have coins with denomination 1 and 2" $\endgroup$
    – AakashM
    Sep 28, 2012 at 8:41
  • $\begingroup$ @AakashM, you may have a point. I don't have a simple formula for this though. $\endgroup$
    – NoChance
    Sep 28, 2012 at 9:04
2
$\begingroup$

The formula to use is to find the coefficient of $X^a$ (where $a$ is your amount) in the expansion as a power series in $X$ of $$ \frac1{(1-X^{d_1})(1-X^{d_2})\cdots(1-X^{d_n})} $$ where $d_1,d_2,\ldots,d_n$ are the denominations of your coins. In principle this is just an algebraic reformulation that does not help you at all: finding the coefficient in the straightforward way (writing each $\frac1{1-X^{d_i}}$ as a geometric series and multiplying out) merely gives you the combinatorial problem you started with. However, as I explained in this answer to a related question, you can actually perform these multiplications very easily without even expanding each $\frac1{1-X^{d_i}}$ in the first place, by a simple loop updating a sequence of coefficients of your current power series (truncated after the term that interests you).

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.