Subset Sum problem [SUBSET SUM ]:
Given a list of n numbers and a number k, is there a subset of the numbers that
adds to exactly k? For example, the answer is yes for <(3, 4, 12, 7, 4), 20> and no
for <(3, 4, 12, 7, 4), 6>.
When the input is expressed in binary (or any other base except unary), it takes exponential time to solve this problem. But hang on!
Unary Subset Sum problem [UNARY SSUM]:
Same problem but the input is expressed in unary!
Result: UNARY SSUM is in P!
Here are the details, that are taken from http://www.cs.virginia.edu/~evans/cs3102-s10/ps/ps6/ps6-comments.pdf
Given a list of n numbers and a number k, is there a subset of the numbers that
adds to exactly k? For example, the answer is yes for <(3, 4, 12, 7, 4), 20> and no
for <(3, 4, 12, 7, 4), 6>.
When the input is expressed in binary (or any other base except unary), it takes exponential time to solve this problem. But hang on!
Unary Subset Sum problem [UNARY SSUM]:
Same problem but the input is expressed in unary!
Result: UNARY SSUM is in P!
Here are the details, that are taken from http://www.cs.virginia.edu/~evans/cs3102-s10/ps/ps6/ps6-comments.pdf
- Why does the NP-completeness proof for SUBSET SUM fail to show UNARY SSUM is NP-complete?
Answer. The crux of the question is that we measure complexity as a function from the size of the input to the number of steps required to run the decided on that input. When the input is represented in unary, the size of the input is equal to the value (that is, it takes x squares to represent the input value x). When the input is represented in binary (or any higher base), it takes log x squares to represent the input value x. Hence, the if size of the input in binary is N, the size of the same input in unary is 2^N. This, the size of the input increases exponentially, even though the problem is of the same difficulty as it would be for the corresponding binary input. The reduction proof fails because the reduction from 3SAT to UNARY SSUM requires more than polynomial time. The input size increases exponentially, so the transformation to generate the corresponding input for UNARY SSUM requires a number of steps that is exponential in the size of the input. - Show that UNARY SSUM ∈ P.
Answer. To show a language is in P, we need to show there is a polynomial-time algorithm that decides it. Note the we can simulate a nondeterministic TM in exponential time using a deterministic TM. Hence, if SUBSET SUM is in NP, we know UNARY SSUM (the same problem, but with exponentially larger input size) is in P, since we can solve it by first converting the input to binary representation (which can be done in polynomial time) and shrinks the input size to log N. Then, we can simulate the nondeterministic polynomial-time TM running on this input (which has size log N) in time that is exponential in its input size, which is polynomial in log N.