Skip navigation.
Home

Subset sum related problem

This is not a java related question, but i think it could be interesting to some of you guys. I appreciate if someone has more info about this. I have encountered a problem in my current project that seems pretty much related to the subset sum problem. I just want to make sure it is not a special case of the subset sum problem and whether it has a efficient solution or not. We are doing an application for tellers in a bank. The teller basically has a cash box that contains money of different denominations. He wants us to provide a function that assists him in determining whether his cashbox contains any collection of coins and notes that sum up to certain value or not. That is, he wants to ask, can I get 123.25 out of my cashbox? a typical cashbox will look like the illustrated figure. It seems to me a typical subset problem. The guy in the team who was doing this function came up with greedy algorithm and I showed to him that it is not always correct for the showed coin system . Yet, I am not quite sure if there are some special cases in this problem or not. ---------------------------------------------------------------- Avail. No. In Cashbox Denomination Value Total ---------------------------------------------------------------- 100 500 50,000<-- Notes 40 200 8,000 10 100 1,000 100 50 5,000 100 20 2,000 44 10 440 20 5 100 100 1 100 100 1 100 <--Coins 100 0.5 50 100 0.25 25 100 0.1 10 100 0.05 5 100 0.01 1

Back to the old days :-)

It is a knapsack probelm. \\ http://www.nist.gov/dads/HTML/knapsackProblem.html \\ http://en.wikipedia.org/wiki/Knapsack_problem \\ http://acm.fzu.edu.cn/reference/Knapsack%20Problems.htm \\ You may solve it using dynamic programming \\ http://mat.gsia.cmu.edu/classes/dynamic/dynamic.html http://en.wikipedia.org/wiki/Dynamic_programming Or using recursive descent search ----- __Michael Ageeb__\\ OpenCraft Software Developer\\ http://www.open-craft.com

Thank you for the info. Yes

Thank you for the info. Yes it can be regarded as 0-1 Knapsack problem. However the [subset sum|http://en.wikipedia.org/wiki/Subset_sum] problem is a special case of the knapsack and this problem could be yet another special case from the subset sum. I think that following this approach can lead to hopefully effecient solution. The 0-1 knapsack and the Subset sum problems are known to be [NP-complete | http://en.wikipedia.org/wiki/NP-Complete] thus there is no effecient (P-time) algorithm to solve them. \\ As I said, my only hope is that this is a special case of the subset sum that has a effecient [P-time algorithm | http://en.wikipedia.org/wiki/P_%28complexity%29 ]

mmm, Since the amount of

mmm, Since the amount of every coin is limited (fixed) I cannot find a P algorithm for it. The recursive descent search with dynamic programming will help improving the performance and run time. (I've done it this way many times before)\\ I'll be interested in the solution you will come up with and use when you solve it. ----- __Michael Ageeb__\\ OpenCraft Software Developer\\ http://www.open-craft.com