Talk:Subset sum problem

From Rosetta Code
Revision as of 18:03, 3 May 2012 by rosettacode>Gerard Schildberger (added another section on query of how many solutions. --- ~~~~)

I ran into some unanticipated implementation issues the last time I tried to create a task, so I'd like to request feedback on this one before promoting it even though it seems straightforward enough to me.

Sluggo 15:58, 1 January 2012 (UTC)

1) Why the words? 2) Caution about trying all subsets being "infeasible" seems superfulous. The problem is NP-complete, so for any algorithm, it's easy enough to construct a data set that will run (practically) forever or exhaust memory. --Ledrug 08:16, 2 January 2012 (UTC)
Thank you for your comments. My rationale is as follows. 1) Any practical application in which this calculation is needed would probably pertain to something more than just integers (e.g., the Dropbox candidate screening exercise). The words are there to stand in for whatever the integers might represent, and thereby to allow other programming language features than arithmetic to be demonstrated in the solutions. 2) Although this is an NP complete problem, an efficient implementation is possible in practice when the weights are restricted to a manageable range as stipulated (e.g., -1000 to 1000). One only needs a bit vector with an entry for each possible sum, and a linear time traversal of the word list. I wanted to make it clear that an alternative to the brute force solution exists and is appropriate. --Sluggo 01:05, 3 January 2012 (UTC)

how many solutions?

I was wondering how many solutions there are for the sample names/weights shown, so I ran my REXX program with a "stop" value of 32,000. The REXX program found that many results.
Does anyone have a fast program that could the find exact number of results (whose weights add up to zero)?
Since REXX is an interpretive language, it's not exactly a speed demon for these types of number crunching. -- Gerard Schildberger 18:03, 3 May 2012 (UTC)