Monday, October 7, 2013

Layman definition of P, NP and NP-complete


Here is my layman intuition for these important complexity classes:

1. P

All problems which are solvable in polynomial time.
Sorting for example.

2. NP

All problems which can be verified in polynomial time. That is given an instance of a problem and its 'solution' we can tell in polynomial time whether it is indeed a solution or not.
Integer factorization for example.

3. NP-hard

All problems which are harder than NP or at least as hard as NP. Any thing whose verification is exponential will trivially belong to this. 
For example factorial of n.  Or producing all permutations of n.
[Technical nit - problems have to be decision problems for them to be in P, NP etc. but we will ignore this for now]

4. NP-complete 

 


It is in NP - hard  as in 3) above and this can be reduced to a problem in NP. So in a sense NP-completeness brings down the complexity a notch from NP-hard to NP.
For example, subset sum problem. In general many optimization problems end up here.

 

In layman terms:


P <= NP

P+NP-Complete = NP
 
NP < NP-hard

NP-Complete < NP-hard [this follows from previous inequality]





No comments: