What are the P class and NP class in TOC?

Data Structure AlgorithmsComputer ScienceComputers

To begin with, let us learn about the P class in the theory of computation (TOC).


  • The class P consists of those problems that are solvable in polynomial time, i.e. these problems can be solved in time O(n k) in the worst-case, where k is constant.

  • These types of problems are called tractable and others are called intractable or super polynomial.

  • Generally, an algorithm is a polynomial time algorithm, if there exists a polynomial p(n) such that the algorithm can solve any instance of size n in a time O(p(n)).

  • Problems requiring Ω(n 50) time to solve are essentially intractable for large n. Most known polynomial time algorithms run in time O(n^k) for a fairly low value of k.

  • The advantage in the class of polynomial-time algorithms is that all reasonable deterministic single processor models of computation can be simulated on each other with at most a polynomial slow-d.


  • The class NP consists of problems that are verifiable in polynomial time. NP is a class of decision problems for which it is easy to check the correctness of a given answer, with the aid of a little extra information. Hence, we are not asking for a way to find a solution, but only to verify that a solution really is correct.

  • Every problem in the given class can be solved in exponential time using exhaustive search.


Consider an example to check if a problem is in P class or NP class

Step 1 − If a problem is in class P, it is nothing but we can find a solution to that type of problem in polynomial time.

Step 2 − If a problem is in class NP, it is nothing but that we can verify a possible solution in polynomial time.

Step 3 − Consider another way, NP means that a problem is NondeterministicallyPolynomial. Specifically, that means that if you could build a machine that had the ability to try all the possible solutions of your problem at once, it could finish in polynomial time.

We know this to be true because we know that we can verify a possible solution in polynomial time, and what that machine is basically doing is trying to verify (test) all of the potential answers to the problem at the same time.

Step 4 − So, if you can solve a problem in polynomial time, you can certainly verify that your answer is correct in polynomial time, can't you? Sure, if you can prove that your algorithm is correct and that it can find an answer in polynomial time, which it must to be in P.

Published on 16-Jun-2021 13:53:20