Vous êtes sur la page 1sur 5

P class, NP class, NP hard class, NP complete class their interrelationship

My aim is to provide the intuition of for this question as other answers did good job
describing the technical terms.
Consider the scenario where you walked into the exam hall and you have following three
questions

1. Does there exist


2. Do there exist

in set
in set

such that

such

that
3. Do there exist

?
in set

that

such
?

While skimming through questions, you feel that first question is easy but last two
are difficult. What exactly do you mean by easy or difficult? Both arerelative and vague
terms, right? Can can we classify the problem which areindeed easy (or doable) and
which are difficult (not doable).
Before we start, lets assume two things -1) You are no less than Arthur T. Benjamin[1] and can do any calculation in one sec no
matter however complicated that is.
2) You don't know about complicated stuff like square-root smare-root!
With this you started to solve the first question. Your approach is simple and robust.
Trying all the possible values of . So there are 1000 possible values to try. Estimated
time to solve this problem -- 1000 secs. But you realize that has to be even if you hope
to satisfy the equation. Cool, now you have only 500 possibilities to try from. Estimated
time to solve problem -- 500 secs. Another realization is that
increases as you keep
increasing and you remember that 20 * 20 = 400. Hence, if at all there exist a
solution, it should lie within first 20 numbers. Now you only need to check 20
possibilities. Estimated time to solve problem -- 20 secs. Wow! this is 50 times
improvement over naive approach.
Now lets turn to second question. Consider
as tuple. Since every element in
tuple can take any value between 1 and 10, we have 1000 such possible tuples. You still
need only one sec to check whether

is

indeed equal to 4564 for given


. Estimated time to solve problem -- 1000 sec.
There is hardly any hope to reduce this time. There is no special property or structure
that you can exploit to reduce the number of possibilities of tuple (and henceforth time
to solve) significantly.
Not willing to waste your 1000 secs on the second question, you turned to third one. You
are again stuck with same difficulties but you realized that if you could solve second
question, you will very well be able to solve third one too. You can just rename some

variable, rearrange some terms and it look exactly like second problem.
So having realized that now you have only one problem to solve, you turned your
attention to second question. Since clock is ticking, you can't explore all the possibilities.
Now you have two options -- You can ask guy/girl sitting next to you for solution and
s/he does tell you the solution, say
. Instead of merely copying
his/her solution, you check it in one sec. Notice, you can't solve the problem in one sec
but if someone provides you the solution, you can check it one sec. This is possible
because the s/he has done all the hard work (creative part) and you just verifying it.
If you moral values doesn't allow you to copy, you can approach as follows.Guess the
values of
like

and check the solution. So your scratch paper for Question 2 looks

(1st possibility) -- (4, 8, 2)

(2st possibility) -- (3, 9, 13)

...
so and so for, unlike for Question 1 where it looks like

(1st possibility) -- 1

(2nd possibility) -- 2

...
You can predict with at most certainty what comes as next possibility in Question 1 (and
hence deterministic approach) but not in Question 2 (NonDeterministic approach). These two words are used in the same context while
defining P and NP.
We broadly divide set of all problems into two categories. First, where you can find
solution is reasonable time, we call it class P. Second, where you can't find solution
in reasonable time but you can check the solution in reasonable time, we call that
class NP.
So Question 1 is in P and Question 2, 3 are in NP. (Strongly because of second
assumption. Please see footnote)
Now it is open challenge is to solve all problems in NP in reasonable time. And in the
quest of one million dollar[2], you and me started to attack every problem which is
known in NP. But it is foolish to attach hundreds of problems at once, right? So we
decided to pick the hardest problem in this world and put all our energy in solving that
problem. Set of such hard problems is called NP-Hard. But wait, we are making this
matter more complicate than necessary. If we could pick hardest problem in the
class NP and solve it, we would be able to solve many problems which are less harder
than that and are in NP. Class of such problems is call NP-Complete. So, I can vaguely
say, Question 2 is inNP-Complete as once you solve that, Question 3 is easy.
But why should you worry about classification at the first place?

The resources are limited you don't want it to assign it to some problem which takes lots
of time. If you don't care about this, you could get lost trying to solve second problem
losing points for all three questions.
Note Technically, 2 and 3 are NOT in NP if you include algebraic tools. The P vs NP approach
is Russian Math circle was to check whether a given problem can be solved without
exploring (almost) all the possibilities. In this sense, we can classify Question 2 and 3
in NP.

Related to this, quoting MIT Computer Scientist Scott Aaronson:

If P=NP, then the world would be a profoundly different place than we usually assume
it to be. There would be no special value in creative leaps, no fundamental gap
between solving a problem and recognizing the solution once its found. Everyone who
could appreciate a symphony would be Mozart; everyone who could follow a step-bystep argument would be Gauss; everyone who could recognize a good investment
strategy would be Warren Buffett. Its possible to put the point in Darwinian terms: if
this is the sort of universe we inhabited, why wouldnt we already have evolved to take
advantage of it?

Definition

There are two classes of problems, P, and NP. These stand for "Polynomial" and "Nondeterministic Polynomial".
P Class
Problems in P are solvable by a polynomial-time algorithm (runs in
where is polynomial). This includes things like sorting and triangulation.

Example: Given a graph connected G, can its vertices be colored using two colors so that no
edge is monochromatic. Algorithm: start with an arbitrary vertex, color it red and all of its
neighbors blue and continue. Stop when you run our of vertices or you are forced to make an
edge have both of its endpoints be the same color.

NP Class
Problems in NP are checkable by a polynomial-time algorithm, but not necessarily
solvable. Generally, we mean NP minus P, when we say NP (so they are only checkable).
Mathematically we can explain it as follows:
Q is an NP-Complete problem if:
1) Q is in NP
2) every other NP problem polynomial time reducible to Q
Example: Integer factorization is NP. This is the problem that given integers n and m, is there an
integer f with 1 < f < m such that f divides n (f is a small factor of n)? This is a decision
problem because the answers are yes or no. If someone hands us an instance of the problem
(so they hand us integers n and m) and an integer f with 1 < f < m and claim that f is a factor
of n (the certificate) we can check the answer in polynomial time by performing the division n /
f.

NP-hard
What does NP-hard mean? A lot of times you can solve a problem by reducing it to a
different problem. I can reduce Problem B to Problem A if, given a solution to Problem
A, I can easily construct a solution to Problem B. (In this case, "easily" means "in
polynomial time.").
If a problem is NP-hard, this means I can reduce any problem in NP to that
problem. This means if I can solve that problem, I can easily solve any problem in NP. If
we could solve an NP-hard problem in polynomial time, this would prove P = NP.
Example: The halting problem is the classic NP-hard problem. This is the problem that given a
program P and input I, will it halt? This is a decision problem but it is not in NP. It is clear that
any NP-complete problem can be reduced to this one.

NP-complete
A problem is NP-complete if the problem is both

NP-hard, and
in NP.

Example: 3-SAT. This is the problem wherein we are given a conjunction of 3-clause disjunctions
(i.e., statements of the form
(x_v11 or x_v21 or x_v31) and
(x_v12 or x_v22 or x_v32) and
...
and
(x_v1n or x_v2n or x_v3n)
where each x_vij is a boolean variable or the negation of a variable from a finite predefined
list (x_1, x_2, ... x_n). It can be shown that every NP problem can be reduced to 3-SAT.
The proof of this is technical and requires use of the technical definition of NP (based on nondeterministic Turing machines and the like). This is known as Cook's theorem.
What makes NP-complete problems important is that if a deterministic polynomial time algorithm
can be found to solve one of them, every NP problem is solvable in polynomial time (one
problem to rule them all).

Vous aimerez peut-être aussi