Document

Lecture15 P,NP,NP-complete
 2005 SDU
The PATH problem
PATH = {<G,s,t> | G is a directed graph that has a directed path from s to t}
2
3
1
4
5
7
6
s
8
t
9
10
12
11
15
14
 2005 SDU
13
16
2
An NP algorithm for the PATH problem
N= “On input <G,s,t> where G is a directed graph and s,t are nodes of G:
1. c:=s; V:={}
2. Repeat while cV and there is an outgoing edge from c:
3. Guess a node b such that G has the edge (c,b);
4. V:=V{c}; c:=b;
5. If tV, accept. Otherwise reject.
2
3
1
4
5
7
6
s
8
t
9
10
12
11
15
14
 2005 SDU
13
16
3
A P algorithm for the PATH problem
N= “On input <G,s,t> where G is a directed graph and s,t are nodes of G:
1. Mark s.
2. Repeat until no additional nodes are marked:
3. Scan all the edges of G. If an edge (a,b) is found going from a marked
node a to an unmarked node b, mark node b.
4. If t is marked, accept. Otherwise reject.
2
3
1
4
5
7
6
s
8
t
9
10
12
11
15
14
 2005 SDU
13
16
4
The Hamiltonian path problem
HAMPATH = {<G,s,t> | G is a directed graph that has a directed path from s to t
that goes through every node exactly once}
2
3
1
4
5
7
6
s
8
t
9
10
12
11
15
14
 2005 SDU
13
16
5
Polynomial time reduction
Definition. A function f is polynomial time
computable if there exists a polynomial time TM
that halts on each input x with only f(x) on the
tape.
Definition. A language A is polynomial time
(mapping) reducible to a language B (write A p
B) if A is mapping reducible to B via a
polynomial time computable function.
 2005 SDU
6
NP-completeness
Definition. A language A is NP-complete if A is in NP
and every language in NP is polynomial time reducible
to A.
Theorem. A language A is NP-complete and A  P, then
P = NP.
We may use the following to prove something is NPcomplete.
Theorem. A language A is NP-complete, B  NP, and A
p B, then B is NP-complete.
 2005 SDU
7
SAT is NP-complete
SAT is NP-complete.
 Given a Boolean formula  = (x1x3x7)  (x3x2)
 (x1x8), dose there exist a truth assignment T to
variables x1, …,xn(assignment of 0s and 1s to the
variables), such that (T) = 1( is  satisfiable)?
 x1 variable ; x1, x3 literal
•3SAT is NP-complete.
•HPATH is NP-complete.
•CLIQUE is NP-complete.
……
 2005 SDU
8
3SAT vs. CLIQUE
A clause is the disjunction of some literals, e.g.,
x1x3x7
A Boolean formula is in conjunctive normal form (CNF
in short) if it is in the conjunction () of some clauses.
A 3CNF formula is a formula in CNF in which each
clause consists of three literals.
 (x1x3x7)  (x3x2x7)  (x1x2x8)
3SAT: Given a 3CNF formula, is it satisfiable?
CLIQUE: Given a graph (V, E), and a number k, does G
contain a complete sub-graph with at least k vertices?
Theorem. 3SAT is polynomial time reducible to
CLIQUE.
 2004 SDU
9
Proof of theorem
Given a formula  of k three-literal clauses, construct a graph
G = (V, E), where V = {(i, j)| 1i  k, 1  j 3} and E = {((i, j) (i’, j’))|
(i  i’ and the jth literal in the ith clause and the j’th literal in the i’th
clause do not interfere with each other.)}
 = (x2x1 x3) (x1x2x4) (x2 x4x3)
x1 x2 x4
x2
x1
x3
 2004 SDU
x2
x4
x3
10
Proof of theorem(cont’d)
Claim.  is satisfiable if and only if G has a k-clique.
<=Let S be a k-clique of G. Then S has a node from each
triple so that the selected nodes do not interfere with each
other as assignments.
=> Let A be a satisfying assignment. Select from each
triple a literal that is satisfied by A to construct a set S. |S|
= k and it is a clique.
The mapping is polynomial time computable.
 2004 SDU
11