Effective algorithm for subset sum search problem based on decision problem of subset sum

548 Views Asked by At

Let us assume that we know the polynomial algorithm for the subset sum decision problem. It return YES (when there is some sub-set summing up to $k$) or NO (when it subset does not exist).

How can we most efficiently build an algorithm based on such an algorithm that will return a subset that adds up to $k$?

What is the complexity of such an algorithm?

Intuitively, it seems possible.

2

There are 2 best solutions below

0
On BEST ANSWER

Suppose we already know that $S$ has a subset that adds up to $k$.

Pick an element $n \in S$ and ask whether $S \setminus \{n\}$ has the desired property. If so, return a subset of $S \setminus \{n\}$ that adds up to $k$; otherwise $n$ is an essential element of the solution. Return the union of $\{n\}$ and a subset of $S \setminus \{n\}$ that adds up to $k-n$ (which is guaranteed to exist).

The oracle is called at most $|S|$ times.

0
On

Suppose the summands come from set $S$; you can assume all the elements of $S$ are less than $k$.

The standard recursive algorithm that loops on $n \in S$ and tries to complete the sum by looking for the subset sum $k -n$ using numbers you haven't yet tried can be speeded up by invoking your oracle before continuing the recursion.

It's not clear to me how much this will help performance.