Sie sind auf Seite 1von 3

P, NP, and NP-Complete Problems (due to: Anany Levitin)

Definition 1 We say an algorithm solves a problem in polynomial time if its worst case
time efficiency belongs to O(p(n)) where p(n) is a polynomial of the problems input size
n. Remember when we say O(x) we are giving an upper bound and clearly the function
f(n) = log2n is less than the function g(n) = n3. Problems that can be solved in polynomial
time are said to be tractable and those that cannot be solved in polynomial time are
intractable.
A refresher from the beginning of the course in the following table
n
10
100
1,000
10,000
100,000

log2n
3.3
6.6
10
13
17

n
10
100
1,000
10,000
100,000

n log2n
33
660
10,000
130,000
1,700,000

n2
100
10,000
1,000,000
100,000,000
10,000,000,000

2n
1000
1.3x1030

n!
3.6x10
9.3x10157

Definition 2 - Class P is a class of decision problems that can be solved in polynomial


time by (deterministic) algorithms. This class of problems is called polynomial.
This raises the question are all problems decision problems? In fact the answer can be
stated as yes since we can convert the problem to a decision problem that requires a
yes/no answer. As an example instead of asking what is the minimum number of colors
needed to color a graph so that no two adjacent vertices have the same color can be
restated as, does there exist a graph with m colors for m = 1, 2, 3, (called the mcoloring problem).
Now, we wonder, can every decision problem be solved in polynomial time? The answer
unfortunately is no. There are even some problems that are known to be undecidable.
The most famous problem in this class is called the halting problem stated by Alan
Turing in 1936. The halting problem asks, given computer program P and input set I does
the program halt.
Here is a simple and short proof of this fact. We will use contradiction and start by
assuming that there exists algorithm A that solves the halting problem. In other words for
any program P and input I we have:
A(P,I) =

1, if program P halts in input I;


0, if program P does not halt in input I.

We can now consider program P as an input to itself and use the output of algorithm A for
pair (P,P) to construct the program Q as follows:
Q(P)= halts, if A(P,P)=0, i.e., if program P does not halt in input P;
does not halt, if A(P,P) = 1, i.e., if program P halts in input P.

Then we substitute Q for P and get:


Q(Q)= halts, if A(Q,Q)=0, i.e., if program Q does not halt on input Q;
does not halt, if A(Q,Q)=1, i.e., if program Q halts on input Q.
This is a contradiction since neither of the two outcomes for program Q is possible, and
therefore completes the proof.
Now, are there decidable but intractable problems? Turns out the answer is yes, but
luckily for us this is a very small set of known problems.
There are however many known problems that do not have polynomial time algorithms
(at least that we know of). The classic paper was published by Garey and Johnson in 1979
and lists several hundred such problems.
Definition 3 A nondeterministic algorithm is a two-stage procedure that takes as
input an instance I of a decision problem and does the following.
Nondeterministic (guessing) stage: An arbitrary string S is generated that can be thought
of as a candidate solution to the given instance I.
Deterministic (verification) stage: A deterministic algorithm takes both I and S as its
input and outputs yes if S represents a solution to instance I. (If S is not a solution to
instance I, the algorithm either returns no or is allowed not to halt at all).
We say that a nondeterministic algorithm solves a decision problem if and only if for
every yes instance of the problem it returns yes in some execution. In other words it
guesses the answer and then verifies that the answer is correct. Finally we call the
nondeterministic algorithm nondeterministic polynomial if the time efficiency of the
verification stage is polynomial.
Definition 4 Class NP is the class of decision problems that can be solved by
nondeterministic polynomial algorithms. This class of problems is called
nondeterministic polynomial.
Most decision problems are in fact in NP. First of all, this class includes all the problems
in P:
P NP.

This is true since if a problem is in P, we can use a deterministic polynomial time


algorithm that solves it in the verification stage of a nondeterministic algorithm that
simply ignores the string S generated by the guessing stage.
Of course the open question is does:

P = NP?
Definition 5 A decision problem D1 is said to be polynomially reducible to a decision
problem D2 if there exists a function t that transforms instances of D1 to instances of D2
such that
1. t maps all yes instances of D1 to yes instances of D2 and all no instances in D1 to
no instances of D2;
2. t is computable by a polynomial time algorithm.
This says that if D1 is polynomially reducible to some problem D2 that can be solved in
polynomial time, the D1 can also be solved in polynomial time.
Definition 6 A decision problem D is said to be NP-complete if
1. it belongs to the class NP, and
2. every problem in NP is polynomially reducible to D.
Now assuming that we already know that the Traveling Salesperson Problem to be NPcomplete we will show that the Hamiltonian Circuit Problem also NP-Complete.
Traveling Salesperson Find the shortest tour through n cities with known positive
integer distances between them.
Hamiltonian Circuit Determine whether a given graph has a Hamiltonian circuit (a
path that starts and ends at the same vertex and passes through all the other vertices
exactly once)
To do this we need to show that Hamiltonian Circuit problem is polynomially reducible
to the decision version of Traveling Salesperson. The latter can be stated as the problem
to determine whether there exists a Hamiltonian circuit in a given complete graph with
positive integer weights whose length is not greater than a given positive integer m. We
can map a graph G of a given instance of the Hamiltonian circuit problem to a complete
weighted graph G representing an instance of the traveling salesperson problem by
assigning 1 as the weight to each edge in G and adding an edge with weight 2 between
any pair of non-adjacent vertices in G. As an upper bound m in the Hamiltonian circuit
length, we make m = n, where n is the number of vertices in G (and G). Obviously this
transformation can be done in polynomial time.
Let G be a yes instance of the Hamiltonian Circuit problem. Then G has a Hamiltonian
circuit, and its image G will have length n, making the image a yes instance of the
decision traveling salesperson problem. Conversely, if we have a Hamiltonian circuit of
length not larger than n in G, then its length must be exactly n (why?) and hence a circuit
must be made up of edges present in G, making the inverse image a yes instance of the
traveling salesperson be a yes instance of the Hamiltonian circuit problem. This
completes the proof.

Das könnte Ihnen auch gefallen