0
$\begingroup$

This question already has an answer here:

I only just recently learned about the P=NP problem in introduction to algorithms class, and I'm still trying to wrap my head around it. I thought of this situation while cleaning my room today and couldn't think of a way to disprove it to myself. Perhaps it

Obviously, the algorithm described in the title would have to iterate 2^n times to print all numbers from 1 to 2^n. As a result, this algorithm would never be able to be done in polynomial time and P is indeed a proper subset of NP. What is the error in my reasoning here? Is it that this problem is not in NP?

$\endgroup$

marked as duplicate by David Richerby, Luke Mathieson, Community Nov 21 '17 at 1:15

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    $\begingroup$ How do you go from “this algorithm would never be able to be done in polynomial time” to “P is indeed a proper subset of NP”? $\endgroup$ – Gilles Nov 21 '17 at 0:59
  • $\begingroup$ It is my (basic) understanding that the problems in NP are those not able to be solved in polynomial time. Thus, the described problem would be in NP, but definitely not in P because it can never be done in polynomial time. $\endgroup$ – tchar989 Nov 21 '17 at 1:01
  • $\begingroup$ NP is a particular set of problems, some of which we don't know how to do in polynomial time. It isn't just "not polynomial." Also, P and NP are sets of decision problems and "count to $2^n$" isn't a decision problem. $\endgroup$ – David Richerby Nov 21 '17 at 1:10
3
$\begingroup$

NP is the set of problems that can be verified in polynomial time, i.e. there is a polynomial-time algorithm that can verify a purported solution. P is the set of problems that can be solved in polynomial time, i.e. there is a polynomial-time algorithm that can find a solution.

“The problems in NP are those not able to be solved in polynomial time” is completely wrong. This is not at all what NP means. The N in NP is for “nondeterministic”, not for “not”. A problem in NP may be solvable in polynomial time — P is a subset of NP. The question “P = NP?” is in fact whether all problems in NP are solvable in polynomial time.

The set of problems that cannot be solved in polynomial time is the complement of P.

Note that “problem” has a specific technical meaning: it's a decision problem, i.e. an function from some input space to $\{\mathrm{yes}, \mathrm{no}\}$.

Counting is not a decision problem, so it doesn't fit in the classification that includes P and NP.

If you found a decision problem that cannot be solved in less than $2^n$ steps where $n$ is the size of the input, then that problem would not be in P. It might not be in NP either: it would only be in NP if there was a way to verify a solution in polynomial time.

$\endgroup$

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