Lably
Skip to content

NP (complexity)

Complexity class used to classify decision problems

  • 10 min read
  • 8 chapters

Related on Lably

Through Turing machine, Computer science and Integer

The first definition is the basis for the abbreviation NP; "nondeterministic, polynomial time". These two definitions are equivalent because the algorithm based on the Turing machine consists of two phases, the first of which consists of a guess about the solution, which is generated in a nondeterministic way, while the second phase consists of a deterministic algorithm that verifies whether the guess is a solution to the problem.

The complexity class P (all problems solvable, deterministically, in polynomial time) is contained in NP (problems where solutions can be verified in polynomial time), because if a problem is solvable in polynomial time, then a solution is also verifiable in polynomial time by simply solving the problem. It is widely believed, but not proven, that P is smaller than NP, in other words, that decision problems exist that cannot be solved in polynomial time even though their solutions can be checked in polynomial time. The hardest problems in NP are called NP-complete problems. An algorithm solving such a problem in polynomial time is also able to solve any other NP problem in polynomial time. If P were in fact equal to NP, then a polynomial-time algorithm would exist for solving NP-complete, and by corollary, all NP problems.

The complexity class NP is related to the complexity class co-NP, for which the answer "no" can be verified in polynomial time. Whether or not NP = co-NP is another outstanding question in complexity theory.

Formal definition

The complexity class NP can be defined in terms of NTIME as follows:

NP=⋃k∈NNTIME(nk),

where NTIME(nk) is the set of decision problems that can be solved by a nondeterministic Turing machine in O(nk) time.

Equivalently, NP can be defined using deterministic Turing machines as verifiers. A language L is in NP if and only if there exist polynomials p and q, and a deterministic Turing machine M, such that

  • For all x and y, the machine M runs in time p(|x|) on input ⁠(x,y)⁠.
  • For all x in L, there exists a string y of length q(|x|) such that ⁠M(x,y)=1⁠.
  • For all x not in L and all strings y of length q(|x|), ⁠M(x,y)=0⁠.

Sign in to keep reading

7 more chapters are free with a Lably account.

More in Theoretical computer science