4
$\begingroup$

So I can solve a given problem using dynamic programming in $O(n^2k^2)$ time complexity. This means that the problem is in P. But I am asked if it is in NP.

My answer is, "Since it is also polynomial time solvable, the problem is also in $NP$".

Is that a correct statement? If not, is a problem in P solved via dynamic programic also NP?

$\endgroup$
  • 2
    $\begingroup$ The definitions of "P" and "NP" don't make any reference to the type of algorithm used. Why should the fact that you used dynamic programming instead of something else be of any relevance? $\endgroup$ – John Coleman Dec 13 '19 at 17:11
  • $\begingroup$ @JohnColeman Perhaps because there is a well-known conversion from a certain class of solution-producing algorithms to a solution-checking algorithm. I don't see any reason a priori that adding constraints on the set of programs you're willing to look at should make it harder to prove a particular property of that set. It turns out in this case that the answer doesn't depend on what algorithm was used, but until you know that it seems like the question itself is a perfectly cromulent one to wonder about. $\endgroup$ – Daniel Wagner Dec 13 '19 at 18:06
19
$\begingroup$

Any problem in P is also in NP

A decision problem that's in P is also in NP, because you can give the verification logic like this: for yes instance x, use empty string as a certificate, and solve x in polynomial time. You get the result that it's yes instance (that's by definition of P) and that means verification is done in polynomial time.

Note that, the order written as $n^2 k^2$ doesn't simply mean the problem is in P (Check "Pseudo-polynomial time" in wikipedia.) For example, Knapsack problem can be solved by the dynamic programming and its order is $O(n W)$ where $n$ is the number of products and $W$ is the maximum weight for the knapsack. But $W$ is actually considered exponential of the input size and Knapsack problem is known to be NP-complete.

$\endgroup$
  • $\begingroup$ $n$ is used in two different meanings here: "where $n$ is the number of products [...] is actually considered exponential of $n$ (which is the input size to the problem)". $\endgroup$ – JiK Dec 13 '19 at 16:56
  • $\begingroup$ @JiK thanks for pointing that. I fixed the sentence. $\endgroup$ – Ryoji Dec 13 '19 at 19:32
6
$\begingroup$

Any problem that's in P is also in NP, since P is a subset of NP.

$\endgroup$
1
$\begingroup$

One way to think of this is that problems in NP lift a restriction by not necessarily meeting the polynomial time requirement in a deterministic manner. Problems in P and NP meet the polynomial time requirement, but problems in P are those that meet it deterministically. Since P vs. NP is still an open question, it could be that everything in NP is also in P, even though most computer scientists don't think this is the case. If P is not equal to NP, then the NP-complete class of problems is mutually exclusive with P -- meaning that these problems cannot meet the polynomial time requirement deterministically.

Relationship of P and NP

$\endgroup$
  • 4
    $\begingroup$ Even if $P=NP$, $NPC\neq P$. Indeed the empty language and the language of all words on the alphabet are not NP-Complete (for the technical reason that a reduction must map a yes-instance to a yes-instance and a no-instance to a no-instance) $\endgroup$ – eru-cs Dec 13 '19 at 19:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.