12

Does the difficulty of a strongly NP-hard or NP-complete problem (as e.g. defined here) change when its input is unary instead of binary encoded?

What difference does it make if the input of a strongly NP-hard problem is unary encoded? I mean, if I take for instance the weakly NP-complete Knapsack problem, it is NP-complete when binary encoded but can be solved in polynomial time by dynamic programming when unary encoded. Maybe it has some implications for hardness of higher levels of the polynomial time heirarchy?

Does the notion of strongly ...-hard also hold for other complexity classes, e.g. higher classes of the polynomial time hierarchy?

I previously asked this question at stackoverflow.com but it was pointed out that it is more appropriate here.

user2145167
  • 703
  • 5
  • 14

4 Answers4

4

A problem size of $N$ encoded in unary is size $N$ and $\log N$ if binary. If the time taken is $F(N)$, this is $F(\text{size})$ in the first case and $F(2^{\text{size}})$ in the second case. So an algorithm that is polynomial for the first case will probably be exponential for the second. The encoding of the problem can so change the complexity of an algorithm radically.

vonbrand
  • 14,204
  • 3
  • 42
  • 52
3

No.

If you change the encoding of the input, you've changed the formal definition of the problem, which means it's a different problem. The complexity of the original problem doesn't change, for the same reason that pointing at a different light in the sky does not change the mass of the moon.

JeffE
  • 8,783
  • 1
  • 37
  • 47
2

The short answer is, that if the input is unary encoded, then it is longer. It is exponentially longer. Now, an algorithm that works in polynomial time in the size of the input has "enough time" to solve the problem, just because the input itself is exponentially longer than in the original problem.

Ran G.
  • 20,884
  • 3
  • 61
  • 117
1

Seeing past the formulation issue pointed out in JeffE's answer, the answer is yes.

Consider the Knapsack problem. It does have a pseudo-polynomial algorithm, that is one with runtime bounded by a polynomial in a number encoded in the input. Because in unary encoding values correspond to length, this is a polynomial-time algorithm for the unary version.

In fact, every weakly NP-complete problem falls into this category.

Raphael
  • 73,212
  • 30
  • 182
  • 400