|
Subset-Sum Problem Greedy algorithm PROBLEM
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).
ALGORITHM
Greedy algorithm is an approximate algorithm, which consists in examining the items and inserting each new item into the knapsack if it fits. Better average results can be obtained by sorting items according to decreasing weights. The time complexity is O(N*lg N) but the worst-case performance ratio is 1/2. Martello and Toth define this concept: Let A. be an approximate algorithm for a given maximization problem. For any instance I of the problem, let OPT.I be the optimal solution value and A.I the value found by A.; then, the worst-case performance ratio of A. is defined as the largest real number R.A such that
(A.I/OPT.I)>=R.A for all instances I IMPLEMENTATION
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 Interface: D_QUICKSORT - sorting in descending order Result: output array X., where X.J=1 if item A.J is selected; or X.J=0 otherwise (for J=1,...,N)
COMPARISON
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.
Notes: I halted the EXACT_SUBSET_SUM after 30 minutes of computations. For APPROX_SUBSET_SUM I used the value Epsilon=0.5
CONNECTIONS
Subset-sum problem
Exponential-time exact algorithm Exact algorithm - Dynamic programming Polynomial-time approximation algorithm Diophantine linear equation Technique: Bit array encoded as decimal number
Literature
Martello S., Toth P. Knapsack Problems: Algorithms nad Computer Implementations Chichester, John Wiley & sons 1990
| ||||||||||||||||||||
|
|
|
|
|
![]()