The other day I was working on a proof to show that there is a polynomial transformation from SUBSET-SUM-ZERO to SUBSET-SUM-ONE where the two problems are decision problems and are defined as follows:

  1. SUBSET-SUM-ZERO: Given a list of integers, if there exists a non-empty subset of those integers that sum to , return YES. Otherwise return FALSE.
  2. SUBSET-SUM-ONE: Given a list of integers, if there exists a non-empty subset of those integers that sum to , return YES. Otherwise return FALSE. For a while, I had come up with a transformation where I could show that if I had a instance that should evaluate to true for SUBSET-SUM-ZERO (SSZ), then there is one for that evaluates true for SUBSET-SUM-ONE (SSO), but couldn’t find one to prove the backwards direction.

After some back and forth of modify/adding/removing parts of to gain the ability to fix a structure for a subset sum in which is , I ended up with the transformation:

  1. Define as the sum of all positive numbers in and as the sum of all negative numbers.
  2. Define . The importance of the will become apparent in setting up inequalities in the following sections.
  3. Add to the list generated by where is an entry in .
  4. Add entries of to where is the length of .
  5. Add to .

Using this definition of I was able to eliminate some possible structures for a subset of that adds to (which I leave the elimination as an exercise to the reader 🙃) to be left with the only possible structure(s) being of the form:

where:

  1. is some non-empty subset sum of elements in that “come from” but are transformed. is the number of entries in .
  2. are some entries of where .
  3. is the last entry, and must be included since it is the only non-odd entry.

After doing some rearranging and factoring, we are left with:

where . My goal here is to show that sums to zero, which shows that contains a subset who’s sum is zero.

The key observation is that the righthand side is some positive or negative multiple of . Then, the smallest positive value that can appear on the righthand side of the equation is while the greatest negative number (closest to zero) is .

We know that the largest possible positive sum we can find in can only be as large as the sum of positive values in , since any other value is either zero or reduces the sum as it is negative. Then we have since . A same statement can be made about the greatest negative number to determine that . This means that and is a non-empty subset of that sums to a multiple of . See where this is going? The only integer multiple of between and that is , which means is a non-empty sum of that sums to (as required).

To summarize: the reason we were able to deduce that the sum was zero was because we had (among some other choices of ) to eliminate possible other structures) a choice of that has a lowest possible positive value and greatest possible negative value out of the range of values that any subset of could sum too. Finding these bounds are a very simple task (unlike the NP nature of the SSO and SSZ class of problems), which makes finding in polytime easy too.

This also highlights the nature of some problems are NP (like finding whether a subset of given integers sum to a particular value), but related problems are in fact P (like finding the upper and lower bounds of the sum of a subset of given integers).