The Subset-sum Problem

The Subset-sum Problem
• Problem statement
– given the set S = {x1, x2, x3, … xn } of positive integers
and t, is there a subset of S that adds up to t
– as an optimization problem, what subset of S adds up
to the greatest total <= t
• What we will show
– first we develop an exponential time algorithm to solve
the problem exactly
– we modify this algorithm to give us a fully polynomial
time approximation scheme that has a running time that
is polynomial in 1/e and n
The exponential algorithm
• Some preliminaries
– we use the notation S + x = { s+x : s  S}
– we have a merge lists algorithm that runs in time
proportional to the sum of the lengths of the two lists
Why it works
• Some notation
– Pi is the set of sums of all
subsets of values up to xi
– it can be shown that Pi 
Pi 1
 ( Pi 1  xi )
• Proof and complexity
– by induction on i it can be shown that Li is a sorted list
that contains every element of Pi <= t
– since Li can be as long as 2i, the algorithm, in general,
is exponential
– polynomial time algorithms exist if t is polynomial in
|S| or all numbers in S are bounded by a polynomial in
|S|
Trimming a List
• To trim by a factor d means
a term z can be represented by
a smaller term provided it is
“close enough”
The complexity is (m)
A fully-polynomial scheme
• The algorithm is similar to our exponential
algorithm except we now perform a trim step
An example