Javatpoint Logo
Javatpoint Logo

Difference between P class Problem and NP class Problem

In this article, we will understand the differences between the P class Problem and the NP class Problem.

Difference between P class Problem and NP class Problem

P Class Problem:

A P class problem can be solved in "polynomial time," which means that an algorithm exists for its solution such that the number of steps in the algorithm is bounded by a polynomial function of n, where n corresponds to the length of the input for the problem. This problem is easy to understand and tractable.

NP Class Problem:

A problem is said to be Nondeterministic polynomial time that can be solvable in polynomial time by a nondeterministic Turing machine. The solutions to the NP class problem are hard to find since they are being solved by a non-deterministic machine.

Following are the differences between the P class problem and the NP class problem:

Sr. No P class Problem NP class Problem
1. P problems are a set of problems that can be solved in polynomial time by deterministic algorithms. NP problems are problems that can be solved in nondeterministic polynomial time.
2. P Problems can be solved and verified in polynomial time. The solution to NP problems cannot be obtained in polynomial time, but if the solution is given, it can be verified in polynomial time.
3. P problems are a subset of NP problems. NP Problems are a superset of P problems.
4. All P problems are deterministic in nature. All the NP problems are non-deterministic in nature.
5. It takes polynomial time to solve a problem like n, n^2, n*logn, etc. It takes non-deterministic polynomial time to quickly check a problem.
6. The solution to P class problems is easy to find. The solution to NP class problems is hard to find.
7. Examples of P problems are: Selection sort, Linear Search Examples of NP problems are the Travelling salesman problem and the knapsack problem.

Next TopicDifference between





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA