Decision problem

Lecture17-P,NP, NPC
 2004 SDU
Concepts concerning NPcompleteness
1. Decision problem and language
• decision problem
• decision problem and language
2. P and NP
• Definitions of P and NP
3. Polynomial reduction and NP-complete
• Definition of polynomial reduction
• Definition of NP-complete
4. Cook’s theorem
• The first NP-complete problem
 2004 SDU
2
Decision problem
• Why decision problem?
1. Easy to give uniform definition, and thus convenient to study
2. Many optimization problems can be converted to decision
problems. E.g., TSP.
•
•
Optimization version: Given n cities and the distances
between them. Find the shortest tour that visits each city
exactly once.
Decision version: Given n cities and the distance between
them, and an integer K. Does there exist a tour that
visits each city exactly once and with cost less than K?
3. The proof of the first NPC problem use the
uniform descriptions of problems in NP.
• Formal description of a decision problem: Describe the
parameters of instances and the yes-no problem.
Input: Given two graphs G1=(V1,E1) and G2=(V2,E2)
Question: Does G1 contain a sub-graph that is isomorphic
to G2?
 2004 SDU
3
Language and decision problem
•Language: Let  be a finite set of characters, * be the set of
all the finite strings over . Then any subset of * is called a
language on .
•Decision problem лdescribed as language: Under a coding
system, each instance is coded as a string I. All the instances
form the language Dл. The “yes” instances form the language
Yл. Then for each I Dл, is I Yл?
TSP:
 = {c,[,],/,0,1,2,3,4,5,6,7,8,9,#}
c[1]c[2]c[3]c[4]//10/5/9//6/9//3#25
 2004 SDU
4
Language and decision problem
• Solve decision problem  by algorithms  Decide
language D by a Turing machine.
• For a decision problem , there may be many coding systems.
U. w. l. g., we mean a reasonable coding system:
•
No redundant characters
•
Numbers are coded in binary (What happens if in unary?)
•
Decodable
• Under different reasonable coding systems, the lengths of
instances: DZ+ are polynomial related, i.e., suppose e, e’ be
two reasonable coding systems, the lengths of instance I under
e and e’ are L[I] and L’[I], respectively, then there are
polynomials P and P’ such that
 2004 SDU
L’[I]P(L[I]), L[I] P’(L’[I])
5
P and NP --Informal definitions
• Class P: The set of decision problems that can be solved in
polynomial time.
• Class NP: The set of decision problems that can be verified in
polynomial time (also called solved non-deterministically).
• An algorithm A verifies a decision problem  : For an instance
ID, A first guesses a witness y, and then on input <I, y>, it produces
an answer. And IY  there exists a witness y,such that A
answers “yes” on input <I, y>.
• Polynomial verifier A: There exists polynomial P, such that on each
input <I, y>, A halts in P(length[I]) time.
 2004 SDU
6
Notes on NP!
1. The length of guess “y” is no more than P(length[I])
2. For an “yes” instance IY,there exists at least one such witness y,
such that on input <I, y>, A answers “yes”.
3. Such a verifier could be viewed as an infinite parallel machine that on an
instance I, guesses all the witnesses and if on one witness, one process
answers “yes”, then the whole machine halts and answers “yes”. The shortest
time for answering “yes” can be the running time on this instance.
 2004 SDU
7
Non-symmetric of NP
•A decision problem  and its complement c.
: given an instance I,ask if X holds?
c: given an instance I,ask if X does not hold?
i.e., D=Dc, Y=Dc-Yc, Yc=D-Y.
• P  cP
• NP  cNP?
Not necessarily.
e.g., Hamilton cycle problem and its
complement.
 2004 SDU
8
P and NP—formal definitions
• P={L: there exists polynomial Turing Machine M such that L=LM}
• NP={L: there exists polynomial non-deterministic Turing Machine such
that L=LM}
 2004 SDU
9
P and NP—relationships
• P  NP
• P = NP ?
 2004 SDU
10
How hard is problem in NP?
Theorem: If LNP, then there exists polynomial P such that L can be solved
by a DTM in O(2P(n)) time.
proof. LNP, then there exists NDTM M, and polynomial q, such that on each
xL,|x|=n, there exists a witness y, |y|q(n), such that M answers “yes” on <x,s>
in q(n) time.
Note that the number of witnesses shorter than q(n) is at most Kq(n), K=||.
Construct DTM M’ as follows: On instance I, write all the witnesses y shorter
than q(n) one by one, and on <I, y>, simulate the verifying process of M. If on
one such y, M answers “yes” within q(n) steps, then M’ answers “Yes” and halt;
if on all such y’s, M answers “no”, then M’ answers “no”. Obviously LM’= LM.
Time(M’)= O(Kq(n)q(n)) = O(2P(n))
 2004 SDU
11
Polynomial Reduction
•
Polynomial reduction: Let 1, 2 be two decision problems. If
there exists a function f: D1D2, such that
I. f can be computed in polynomial time
II. ID1, IY1  f(I)Y2
then we say that f is a polynomial reduction from 1 o 2, and that
1 is polynomial reduced to 2, denoted as 1  2.
•
Steps to construct reduction:
1. Construct function f: D1D2, that is, for each instance I in D1,
construct an instance f(I) of D2
2. Prove that IY1  f(I)Y2
3. Prove f(I) can be constructed in polynomial time.
 2004 SDU
12
Polynomial Reduction-an example
•HC  TSP
HC : Given a graph G=(V,E), does there exist a tour that visits each
vertex exactly once?
TSP:Given cities C={c1,c2,…,cm}, and integers d(ci,cj),1i<jm,
and an integer B, does there exist a tour no more than B that visits each
city exactly once?
f:For an given instance G, construct: C=V. B=|V|.
vi, vj V (i<j),
 2004 SDU
1
d (v i , v j )  
2
{v i , v j }  E
{v i , v j }  E
13
Polynomial Reduction-an example
•Conclusion: f is a polynomial reduction from HC to TSP.
Proof.
1.
If G has a HC <v1,v2,...,vm>, then <v1,v2,...,vm> is also a tour in f(G).
Obviously each edge on this tour has length 1, hence, the total length of this
tour is m. Hence, f(G) is also a “yes” instance of TSP.
The opposite. Suppose <v1,v2,...,vm> is a tour of f(G) no more than B.
Then since each edge has length either 1 or 2, and since there are B edges
on the tour, each edge on the tour must have length 1. Thus proves that this
tour is also a HC of G.
2.
Concerning polynomial. We have to construct m(m-1)/2 d(vi, vj), i<j.
For each construction, test whether {vi,vj} is in E. This could obviously
be finished within polynomial time.
 2004 SDU
14
Polynomial Reduction--properties
1)If L1  L2, then L2P  L1P.
2)If L1  L2, L2  L3, then L1  L3.
Proof ?
 2004 SDU
15
NP-complete
•NP-complete: If LNP, and for each L’NP, L’  L, then
we call L NP-complete. Denote L NPC.
•Properties of NP-completeness
(1)If L1,L2NP, L1NPC, and L1  L2, then L2NPC.
(2)If LNPC, then LP  P = NP.
(3)If P  NP, then NPCP=.
Proofs?
 2004 SDU
16
Cook’s theorem—the first NPC problem
•A boolean formula (in conjunctive normal form)is a conjunction of
clauses:
•A finite set of boolean variables: U={u1,u2,...,um}
•Literals: u and u
•Clause: disjunction of finite literals
•Truth assignment for a boolean formula: A set of values for the
variables.
•Satisfying assignment: A truth assignment that causes a formula to
evaluate to 1.
•SAT problem: Given a boolean formula, does there exist a satisfying
assignment?
 2004 SDU
17
Cook’s theorem—the first NPC problem
Cook’s Theorem: SAT is in NPC.
1.
2.
SATNP.
A verifier is as follows: Guesses a truth assignment for an input
instance, and then tests whether this is a satisfying assignment.
This can be finished within polynomial time.
For each L  NP, L  SAT.
The proof is left to the interested people.
There are many other NPC problems, you may find one…
 2004 SDU
18