3

Let Q be a computational problem that accepts as input some $n$ non-negative integers. Is it possible (assuming $P\neq NP$) that Q is NP-hard in general, but can be solved in polynomial time when restricted to inputs in the range $[0,2^n]$?

If, instead of $2^n$, there was any function that is polynomial in $n$, then the answer would be "yes", as there are many NP-hard problems that can be solved in pseudo-polynomial time, such as the knapsack problem.

For some specific NP-hard problems, the question is "no". For example, it is easy to prove that the Partition problem is NP-hard even when restricted to inputs in $[0,2^n]$, as we can always add zeros without changing the outcome, such that $n$ becomes equal to $\log_2$ of the largest integer in the input. But I am not sure if this trick works for other problems.

Is it possible in general?

Erel Segal-Halevi
  • 6,088
  • 1
  • 25
  • 60

2 Answers2

3

Yes, absolutely. Let $f:\{0,1\}^*\to \{0,1\}$ be the function corresponding to 3-SAT, i.e., if $x \in \{0,1\}^*$, we interpret $x$ as a representation of a 3-CNF formula, then $f(x)=1$ if this formula is satisfiable or 0 otherwise. Computing $f$ is NP-hard. Of course there is a bijection between $\{0,1\}^*$ and $\mathbb{N}$, so we can think of $f$ as a function with signature $f:\mathbb{N}\to \{0,1\}$. Now define the function $g$ by

$$g(x_1,\dots,x_n) = \begin{cases} f(x_1) &\text{if $n=1$}\\ 0 &\text{otherwise.} \end{cases}$$

Let $Q$ be the problem to compute $g$. Then this problem is NP-hard, since 3-SAT is. Yet if you restrict all input integers to be in the range $[0,2^n-1]$, $g$ can be computed in polynomial time, by hardcoding the correct value of $g(0)$ and $g(1)$ and then returning 0 for all other inputs.

D.W.
  • 167,959
  • 22
  • 232
  • 500
2

Let X be any NP-complete problem, and P any polynomial time decision problem, both taking n integers as input. Define X’ = P if all n numbers are <= 2^n, and as X’ = X if any number is greater than 2^n.

We can check in polynomial time that all numbers are 2^n, and get the solution for these instances in further polynomial time.

gnasher729
  • 32,238
  • 36
  • 56