0

As a homework exercise our professor presented to us a simplified version of the coin-changing problem in which we do not need to minimize the number of coins used or track the number of possible combinations. Instead we need only to determine if a certain number of coins of same or varying denomination, equal exactly, some amount M.

My recursion equation of the problem is as follows:

let k = 0

If ∑ (v1 + v2 + … + vn) = M   
    return true

If ∑ (v1 + v2 + … + vn) < M
    return false

Else 
    Increment k by 1
    make recursive call on coin subset {v1, v2, … v(n-k)}

The next question is to convert this into pseudo-code that represents a dynamic programming solution to this problem.

I'm a bit stuck. If you were to make a table of every possible sum {v1 + v2}, {v1 + v2 + v3}, {v1 + v2 + v3 + v4}, etc. You could eventually find a solution but wouldn't that be a much less efficient brute force approach?

I assume the solution would include some implementation of memoization or some way to store and retrieve sums already encountered, but being that the problem is not an optimization problem, I'm having a hard time envisioning a dynamic solution.

Much of the dynamic programming examples that I see suggest iteratively subtracting elements, one item at a time, which is similar to the composition of my recursion equation but I don't see a modification that would make this pseudo code dynamic in nature.

If anyone could please enlighten me, I'd be very grateful

Trixie the Cat
  • 317
  • 3
  • 18
  • 1
    `"determine if a certain number of coins of same or varying denomination, equal ... M"` Did you mean the exact number of coins to use, say `n`, is given and the choice is just which denomination for each of the `n` coins? The problem seems a bit unclear, to me at least. – גלעד ברקן Mar 09 '19 at 02:06
  • @גלעדברקן sorry, what i mean is to determine if some subset of n coins of varying denomination equal some amount M exactly. for example suppose you have the following set of coins each of the following denominations {1, 1, 3, 4, 6, 6, 8, 9} suppose you want to see if you can make the amount 16cents, you could have one 9cent coin, one 1 cent coin, and one 6 cent coin. That subset {1, 6, 9} would represent the solution, or the subset {9, 4, 3} would also represent a solution – Trixie the Cat Mar 09 '19 at 04:15
  • 1
    I would read up about the subset sum problem. There's plenty of literature out there. – גלעד ברקן Mar 09 '19 at 17:20
  • Also posted at [Computer Science](https://cs.stackexchange.com/questions/105313/dynamic-pseudo-code-for-simplified-coin-changing-algorithm). – burnabyRails Mar 11 '19 at 15:33
  • @גלעדברקן thank you, I think that's the hint I was looking for – Trixie the Cat Mar 11 '19 at 19:47

0 Answers0