5

Is the following problem NP-hard:

Input: $A\subset\mathbb Z, k\in\mathbb N$
Question: is there a multiset of indices $I$, such that $|I|=k$ and $\sum_{i\in I} a_i=0$?

For example, on the input $A=\{-1,2\}, k=3$ we can take $I=\{1,1,2\}$ and thus we get $|I|=3$ and $a_1+a_1+a_2=(-1)+(-1)+2=0$, as desired.

Dudi Frid
  • 181
  • 1
  • 3
  • 19
  • I know that there's an easy reduction from Subset Sum problem to inputs of the form $A,k$ where $I$ should be a set. Also, I know that there's an easy reduction from this problem to Subset Sum problem by taking $A$ to be a multiset (each element of $A$ should appear $k$ times in the output of the reduction). But I am stuck showing the required reduction. – Dudi Frid Apr 28 '17 at 13:12
  • 1
    I think that careful analysis of the standard reduction from Vertex Cover to Subset Sum will show that you can actually use a multiset, and it wouldn't matter. But I didn't check the details, and it seems like an inelegant solution anyway. – Shaull Apr 28 '17 at 13:34
  • I can't make edits < 6 characters, but I believe $I = {1, 1, 2}$ should be $I = {-1, -1, 2}$. – orlp Apr 28 '17 at 14:07
  • 1
    @orlp, why are you thinking that? Each element of $I$ is supposed to be an index, so in the example it must be either 1 or 2 (as $|A|=2$, i.e., $a_1=-1$, $a_2=2$). – D.W. Apr 28 '17 at 14:31
  • @D.W. Ah I missed that they are multisets of indices. That's a bit of an indirect way of going about it. – orlp Apr 28 '17 at 14:33
  • @D.W. It appears I have misread the paper in my answer. Their algorithm indeed only finds arbitrary integer solutions, and non-negative solutions require some form of post-processing (like integer programming). I'll keep looking. – orlp Apr 28 '17 at 15:18
  • Have you tried looking to see if set-partition might reduce to this? The idea of having elements balance out so their sum = 0 got me thinking about that. – ryan Apr 28 '17 at 19:51
  • I believe that it is not NP-Hard. https://cs.stackexchange.com/questions/2973/generalised-3sum-k-sum-problem – nick.schachter Apr 28 '17 at 22:15
  • 1
    @nick.schachter, why does that suggest the problem is not NP-hard? If we were limited to $k=3$, then the results about 3-sum would suggest that the problem is not NP-hard. But in this question $k$ is not limited to $k=3$; $k$ can be arbitrarily large, and thus those methods don't yield a polynomial-time algorithm. – D.W. Apr 29 '17 at 00:42
  • If 0 is present in $A$, then the "exactly $k$" constraint is effectively weakened to "at most $k$", since we can then "pad" a solution with as many copies of 0 as we like. And if we set $k$ "high enough" then we are asking whether there is any integer vector $\mathbf x$ such that $\mathbf a \cdot \mathbf x=0$, where $\mathbf a$ is a vector representation of $A$ and $\cdot$ is the usual dot product. Pretty sure this problem is NP-hard; the other question is whether it's possible to pick a high enough $k$ that still has size polynomial in the input size (maybe the product of all elements?). – j_random_hacker Apr 29 '17 at 19:04
  • 1
    If 0 is present in $A$, the answer is trivially yes if I correctly understood the problem. (However, the case "at most k" may still be interesting to study). – user53923 May 02 '17 at 09:36

2 Answers2

2

It is NP-hard.

Consider the following two variants:

Variant 1:

Input: $A\subset\mathbb N$, $s\in\mathbb N$.
Question: is there a set of indices $I$, $\sum_{i\in I} a_i=s$?

Variant 2:

Input: $A\subset\mathbb N$, $k\in\mathbb N$, $s\in\mathbb N$.
Question: is there a multiset of indices $I$, such that $|I|=k$ and $\sum_{i\in I} a_i=s$?

It is easy to see variant 1 is NP-hard. It is also easy to reduce variant 2 to your variant in polynomial time by transforming each element $e$ in an instance of variant 2 to $ke-s$. So if we can prove there is a polynomial-time reduction from variant 1 to variant 2, the proof is completed.

The reduction from variant 1 to variant 2 is exactly the same as the one posted by Kristoffer Arnsfelt Hansen in this answer. I rewrite it here for consistency of symbols.

Given an instance of variant 1, assume that $a_i < B$ for all $i$. We will have two new elements for each old element, simulating whether the element is used 0 or 1 times. For element $a_i$ we get two new elements $a^1_i = (2^{n+1} + 2^i)nB + a_i$ and $a^0_i = (2^{n+1} + 2^i)nB$. The new target sum is defined as $s' = (n2^{n+1} + 2^n + \dots + 2^1)nB + s$. The number of elements required in a solution is set to be $n$.

Note in a valid solution of the new instance, for each $i$, the number of $a_i^1$ and that of $a_i^0$ must be exactly $1$ in total, so there is exactly $n$ elements in a valid solution. This is indeed a polynomial-time reduction from variant 1 to variant 2.

xskxzr
  • 7,455
  • 5
  • 23
  • 46
0

Assuming that the algorithm for your problem returns the yes/no answer together with the actual multi-set $I$ itself, then we can build a reduction from sub-set sum to your problem by sending your algorithm several $k$'s starting with $k=N,(|A|=N)$ down to $k=2$, where each time we check for repetitiveness to make sure we have a valid minimum sub-set sum. That would be running your algorithm $N-1$ times each time checking validity which sums up to $N(N-1)$ times your algorithm's running time. Conclusion, your problem is NP-Hard.

Note: Even if your algorithm does not return the actual sub multi-set it can be obtained by repeatedly removing one of the set's elements and checking that the sub multi-set still exists.

David Richerby
  • 81,689
  • 26
  • 141
  • 235
Anwar Saiah
  • 335
  • 2
  • 13