Exact algorithm - Dynamic programming
In the subset-sum problem we wish to find a subset of A.1,...,A.N whose sum is as large as possible but not larger than T (capacity of the knapsack).
The time complexity of the following exact algorihm is O(MIN(2**(N+1),N*T). The algorithm encodes the result as bit string. For example:
The result is 743, it is the bit string 1011100111 and it means that elements with indexes (read the bit string from the right to the left) 1, 2, 3, 6, 7, 8, 10 belong to subset. Proof: A.1 (5) + A.2 (9) + A.3 (13) + A.6 (17) + A.7 (11) + A.8 (2) + A.10 (12) = 69
Unit: internal subroutine
Global variables: array A.1,...,A.N of positive integers, output array X.
Parameters: a positive integer N, a positive integer T
Result: output array X., where X.J=1 if item A.J is selected; or X.J=0 otherwise (for J=1,...,N)
For N=100;T=25557 and the array A. created by statements:
I compared the algorithms for solution of the Subset-sum problem and my algorithm DIOPHANT for solution of the diofantine equations.
I halted the EXACT_SUBSET_SUM after 30 minutes of computations. For APPROX_SUBSET_SUM I used the value Epsilon=0.5
Exponential-time exact algorithm
Polynomial-time approximation algorithm
Diophantine linear equation
Technique: Bit array encoded as decimal number
Martello S., Toth P. Knapsack Problems: Algorithms nad Computer Implementations
Chichester, John Wiley & sons 1990