4

I am looking for a yes/no answer to a question whether it can be solved with efficiency or not. I am pretty sure that's impossible with current state of computing technology available to us. I would be glad to know I am wrong. So here goes nothing.

I have a list of 2576 numbers. I am trying to find a combination of numbers in the list which sums up to 44576.54. The list of numbers contain numbers from 5 digits (with two digit precision) to 8 digits(with two digits precision).

I would be really grateful for your help!

ishan
  • 73
  • 1
  • 2
  • 7
  • 1
    +1 for the "intro". If you want to find all the combinations in reasonable time, i'd say No! But not sure. maybe there is some sorcery algorithm somewhere. – Mike B Nov 10 '16 at 14:44
  • 4
    Are there negative numbers in the list? If not, then at most four 5-digit numbers could be part of the sum, and no 6/7/8-digit numbers can be used at all. That cuts down the number of combinations to check tremendously. Note that specifying the numbers in floating point is going to cause problems - it's unlikely for any sum of numbers to test exactly equal to 44576.54, even if that is the mathematically correct result. Better to multiply everything by 100, and deal only with integers. – jasonharper Nov 10 '16 at 14:52

3 Answers3

0

You're wrong. The classical dynamic programming algorithm will make quick work of this problem on modern computing hardware.

David Eisenstat
  • 64,237
  • 7
  • 60
  • 120
0

This is dynamic programming algorithm, and already implemented in the Emercoin engine for select optimal UTXO subset. See source code and article about this solution.

Common idea of this algorithm is following:

You have set of "rods" with different lengths (length is your number value). You needed select subset of the rods, total length of 4457654.

  1. Let you create LINE of flags, length of sum+1, i.e. 4457655. LINE[i] = 1, if sum subset for value "i" is found, and zero, if subset for value "i" is not found. Initially, this entire array is zero-filled, since no any sum found.

  2. Mark LINE[0] := 1; This is meaning, sum for $0.00 can be trivially found - this is empty subset.

  3. while(LINE[4457654] == 0):

    • get a next rod from set.
    • apply this rod to the end of array. I.e, end of the rod at LINE[4457654], begin of the rod - at the LINE[4457654 - rod length].
    • move rod from the end of array to begin, and:
    • if LINE[begin of the rod] == 1, then LINE[end of the rod] := 1;
olegarch
  • 3,670
  • 1
  • 20
  • 19
0

Basically there are two solutions to this problem:

  1. Dynamic programming: complexity sum*n, so in your case this will very big and your program wont finish for days.

  2. Back tracking solution : complexity 2^n, which means your program wont end for years and that is why it is called NP-Hard problem

I have been working on subset sum problem for long time now and i have an algorithm which I have tested for n=400 and it give results in few seconds. Currently I am working on paper to get it published. Share your input. I will let you know what subset it is, this will also help me to verify my algorithm for real problem.

BTW, can you tell me why you need to get subset sum? what is your usecase?

Vj More
  • 85
  • 1
  • 7