View
66
Download
1
Category
Preview:
DESCRIPTION
Fall 2011. The Chinese University of Hong Kong. CSCI 3130: Formal languages and automata theory. The Cook-Levin Theorem. Andrej Bogdanov http://www.cse.cuhk.edu.hk/~andrejb/csc3130. NP-completeness. IS. reduces to. VC. CLIQUE. Cook-Levin theorem:. 3SAT. SAT. NP-complete. - PowerPoint PPT Presentation
Citation preview
CSCI 3130: Formal languages and automata theory
Andrej Bogdanov
http://www.cse.cuhk.edu.hk/~andrejb/csc3130
The Chinese University of Hong Kong
The Cook-Levin Theorem
Fall 2011
NP-completeness
P NP(easy to solve)(easy to verify solution)
SAT
IS
CLIQUEVC
3SAT
reduces to
Cook-Levin theorem:
Everything in NP reduces to SAT
NP-complete
Polynomial-time reductions
• Language L polynomial-time reduces to L ’ if
there exists a polynomial-time computable map R that takes an instance x of L into instance y of L ’ s.t.
x ∈ L if and only if y ∈ L ’
L L ’(CLIQUE) (IS)
x y(G, k) (G ’, k’)
x ∈ L y ∈ L ’(G has clique of size k) (G ’ has IS of size k ’)
R
SAT and 3SAT
SAT = { 〈〉 : is a satisfiable Boolean formula}
3SAT = { 〈〉 : is a satisfiable 3CNF formula}
(x1∨x2∨x2 ) ∧ (x2∨x3∨x4) ∧ (x2∨x3∨x5) ∧ (x1∨x5∨x5)
((x1∨x2 ) ∧ (x1∨x2)) ∨ ((x1∨(x2 ∧ x3)) ∧ x3)
The Cook-Levin Theorem
• To show this, we need a reduction R such that:
Every L ∈ NP reduces to SAT
z Boolean formula f
z ∈ L f is satisfiable
R
NP-completeness of SAT
• All we know: L has a polynomial-time verifier V– Look at the computation tableau of V on input 〈 z, s 〉
Vz | s
z2z1
qacc …
S-th configuration symbol at time T
S
T
…q0
ba
NP-completeness of SAT
n = length of z
height of tableau is O(nc) for some constant c
width is at most nc
k possible tableau symbols
xT, S, u = true,if the (T, S) cell of
tableau contains uif notfalse,
u
1 ≤ S ≤ nc
1 ≤ T ≤ nc
1 ≤ u ≤ k
S
T
z2z1 …q0
qacc …ba
NP-completeness of SAT
• We will design a formula f such that:
z Boolean formula f
z ∈ L f is satisfiable
R
assignment to xT, S, u way to fill up the tableau
satisfying assignment accepting computation tableau
variables of f :xT, S, u
f is satisfiable V accepts 〈 z, s 〉 for some s
NP-completeness of SAT
• We want to construct (in time O(n2c)) a formula f :
xT, S, u = true,if the (T, S) cell of
tableau contains uif notfalse,
1 ≤ S ≤ nc
1 ≤ T ≤ nc
1 ≤ u ≤ k
f(x1, 1, 1, ..., xnc, nc, k) = true,if the xs represent a legal
and accepting tableauif notfalse,
NP-completeness of SAT
f = fcell ∧ f0 ∧ fmove ∧ facc
fcell:“Every cell contains exactly one symbol”
“The first row is q0z|s☐...☐” for some s
f0:
fmove:“The moves between rows follow the transitions of V ”
facc: “qacc appears somewhere in the last row”
z2z1
qacc …
…q0
ba
NP-completeness of SAT
fcell: “Every cell contains exactly one symbol”
fcell = fcell 1, 1 ∧ ... ∧ fcell nc, nc where
fcell T, S = (xT, S, 1 ∨ ... ∨ xT, S, k) ∧ (xT, S, 1 ∧ xT, S, 2) ∧ (xT, S, 1 ∧ xT, S, 3) ∧ ... ∧ (xT, S, k-1 ∧ xT, S, k)
at least one symbol
no cell containstwo or more symbols
“Exactly one of xS, T, 1 ∨ ... ∨ xS, T, k is true”
NP-completeness of SAT
f0:“The first row is q0z1z2...zn|s1s2...sm
f0 = x1, 1, q0 ∧ x1, 2, z1 ∧ ... ∧ x1, n+1, zn ∧ x1, n+2, |
for some (possible solution) s1s2...sm”
NP-completeness of SAT
facc: “qacc appears somewhere in the last row”
facc = xnc, 1, qacc ∨ xnc, 2, qacc ∨ ... ∨ xnc, nc, qacc
Legal and illegal windows
… 6a3b0x0 …… 0a6b0x0 …0
legal windows
… 6#3b0a0 …… 0#6b0q5 …0
… 6a3q2a0 …… 0q5a6x0 …0
… 6q2a0b0 …… 0a6b0q2 …0
illegal windows
… 6a3a0☐0 …… 0x6a0☐0 …0
q2
q5
a/xL
… 6a3q2a0 …… 0q5a6b0 …0
… 6q2q2a0 …… 0q2q2x3 …0
… 6#3q2a0 …… 0q5#6x0 …0
NP-completeness of SAT
fmove:“The moves between rows follow transitions of V ”
fmove = fmove 1, 1 ∧ ... ∧ fmove nc-
3, nc-3
a2a1 a3
a6a4 a5
fmove 2, 2 LW = list of all legal windows
= {(a1, a2, a3, a4, a5, a6): is legal}a1a2a3a4a5a6
z2z1q0 …
qacc …ba
fmove T, S = (xT, S, a1 ∧ xT, S+1, a2 ∧ xT, S+2, a3
∧ xT+1, S, a4 ∧ xT+1, S+1, a5 ∧ xT+2, S+1,
a6)
∨(a1, a2, a3, a4, a5, a6) ∈ LW
NP-completeness of SAT
z Boolean formula f
z ∈ L f is satisfiable
R
Let V be a poly-time verifier TM for L.
On input z,Construct the formulas fcell, f0, fmove, and facc
Output the formula f = fcell ∧ f0 ∧ fmove ∧ facc.
R :=
✔
V accepts z if and only if f is satisfiable.Then R is computable in time O(n2c) and
How to argue NP-completeness
SUBGRAPH = { 〈 G, H 〉 : G and H are graphs whereH is a subgraph of G}
G H
SUBGRAPH is NP-complete
1 2 3
4 5
6 7
1 2
3
4
Every edge of H must be included in G
1 2 3
4 5
6 7
How to argue NP-completeness
• Step 1: SUBGRAPH is in NP
G H1 2
3
4
What is a solution for SUBGRAPH?
A solution s is a map from vertices of H to vertices of G(1 4)(2 2)(3 5)(4 7)➝ ➝ ➝ ➝
V := On input 〈 G, H, s 〉For every edge {u, v} of H:
Find u ’ and v ’ such that u➝u ’ and v➝v ’ in s.
If {u ’, v ’} is not an edge in G, reject.
Otherwise, accept.
Running time = O(m)m = number edges in H
✔
How to argue NP-completeness
• Step 2: Some NP-complete L reduces to SUBGRAPH
CLIQUEIND SET
VERTEX COVER
SAT 3SAT
Direction of reduction is important!
You want to show SUBGRAPH is harder than L
So you assume you can solve SUBGRAPH, and show how to solve L
This requires converting instances of L into instances of SUBGRAPH How to choose L?
Tips on choosing L
• Both CLIQUE and SUBGRAPH are about graph containment, so their complexities may be related
• It usually makes sense to try and reduce from the problem that looks the most related
G H1 2 3
4 5
6 7
1 2
3
4
G
4
CLIQUE SUBGRAPH
How to argue NP-completeness
• Step 3: Reduce CLIQUE to SUBGRAPH
SUBGRAPH = { 〈 G, H 〉 : H is a subgraph of G}
CLIQUE = { 〈 G, k 〉 : G has a k-clique}
R := On input 〈 G, k 〉Construct the k-clique H
Output 〈 G, H 〉
G has a k-clique
H is a subgraph of G
✔
Cover for triangles
• A graph has a k-cover for triangles if there are k vertices that touch all the triangles
Does it have a 2-cover for triangles?
Does it have a 1-cover for triangles?
No, because it has two vertex-disjoint triangles
Yes
TRICOVER = { 〈 G, k 〉 : G has a k-cover for triangles}
TRICOVER is NP-complete
Cover for triangles
• Step 1: TRICOVER is in NP
What is a solution for TRICOVER?
A solution s is a subset of vertices like {2,5}V := On input 〈 G, k, s 〉 , where s is a set of vertices of size k
For every triple {u, v, w} of vertices:
If {u, v}, {u, w}, {v, w}, are all edges in G:
If none of u, v, or w are in s, reject.
Otherwise, accept. Running time = O(n3)
✔
1 2 3
45
6 7
CLIQUEIND SET
VERTEX COVER
SAT 3SAT
SUBGRAPH
Cover for triangles
• Step 2: Some NP-complete L reduces to TRICOVER
TRICOVER = { 〈 G, k 〉 : G has a k-cover for triangles}
Some vertex in every triangle is covered
Some endpoint of every edge is covered
VC = { 〈 G, k 〉 : G has a k-vertex cover}
Cover for triangles
• Step 3: Reduce VC to TRICOVER
TRICOVER = { 〈 G ’, k ’〉 : G ’ has k ’-cover for triangles}
VC = { 〈 G, k 〉 : G has a k-vertex cover (for edges)}
Idea: Replace edges by triangles
G G ’
vertex-cover in G cover for triangles in G ’
Cover for triangles
• Step 3: Reduce VC to TRICOVER
R := On input 〈 G, k 〉 , where G has n vertices and m edges
Construct the following graph G ’:G ’ has n + m vertices v1, ..., vn, and uij for every edge {vi, vj} of G
For every edge {vi, vj} of G, include the edges {vi, vj}, {vi, uij}, {vj, uij} in G ’
Output 〈 G ’, k 〉 .Running time = O(m)m = number of edges in G
Cover for triangles
• Step 4: Argue that the reduction is correct
G G ’
〈 G, k 〉 ∈ VC 〈 G ’, k 〉 ∈ TRICOVER
G has a k-vertex cover C C is a k-triangle cover of G ’Old triangles from G are covered
New triangles in G ’ also covered
✔
Cover for triangles
• Step 4: Argue that the reduction is correct
G G ’
〈 G, k 〉 ∈ VC 〈 G ’, k 〉 ∈ TRICOVER
G has a k-vertex cover C ’ G ’ has a k-vertex cover C
Some vertices in C may notcome from G!
But we can move them and stillcover the same triangle
✔
C ’ is obtained after moving somevertices of C
Since C ’ covers all triangles in G ’,it must cover all edges in G
✔
Coloring
CSCI 3230
CSCI 2110
CSCI 3160CSCI 3130
Suppose you need to schedule exams on same day in 3 time slots
Y R B
1030-1230130-330 430-630
CSCI 3190
Some people are enrolled inmultiple classes, so there may be conflicts
Task: Schedule the exams so there are no conflicts
Coloring
Given a graph, we want to colorthe vertices so every edge has endpoints of different colors G
Y R B
This is called a valid 3-coloring
3COL = { 〈 G 〉 : G has a valid 3-coloring}
3COL is NP-complete
Coloring
• Step 1: 3COL is in NP
What is a solution for 3COL?
A solution s is a coloring of vertices like {1B,2R,3Y,4R,5B}
V := On input 〈 G, s 〉For every edge {u, v} of G:
If u and v are assigned same color in s, reject.
Otherwise, accept.
Running time = O(m)
✔
G
1 2
3
4 5
CLIQUEIND SET
VERTEX COVER
SAT 3SAT
SUBGRAPH
Coloring
• Step 2: Some NP-complete L reduces to 3COL
3COL = { 〈 G 〉 : G has a valid 3-coloring}
3COL does not look likeany of these problems
In such a case it is a goodidea to start with 3SAT
Coloring
• Step 3: Reduce 3SAT to 3COL
3COL = { 〈 G 〉 : G has a valid 3-coloring}
3SAT = { 〈〉 : is a 3CNF that has a satisfying assignment}
Idea: Assignment of Coloring of G
Part I: 3 special vertices T (true), F (false), and X
T F
X G
Coloring
Part 2: For each variable xi
xi
X
xi
Either xi has color of T and xi has color of F
Or xi has color of F and xi has color of T
Example: (x1∨x1∨x2)∧(x1∨x2∨x3 )
x1 x1 x2 x2 x3 x3
X
T F
T F F T F T
Coloring
• To “encode” the clauses of , we need a gadget
Can be colored if and only if at least one literal is colored TT
x1
x2
x3
x
yz
If x or y is colored T, z can be colored TIf x and y are colored F, z must be colored F
Part 3: For each clause like (x1∨x2∨x3 )
Coloring reduction: An example
Example: (x1∨x1∨x2)∧(x1∨x2∨x3 )
x1 x1 x2 x2 x3 x3
X
T F
T F F T F T
Coloring reduction: An example
Example: (x1∨x1∨x2)∧(x1∨x2∨x3 )
x1 x1 x2 x2 x3 x3
X
T F
T F F T F T
Coloring
• Step 3: Reduce 3SAT to 3COL
R := On input 〈〉 , where is a 3CNF:
Construct the following graph G:Add 3 special vertices T, F, X connected by a triangle.
For every variable xi of , add vertices xi and xi and include the triangle xi, xi, X.
Output 〈 G 〉 .
Running time = O(m + n)n = number of variablesm = number of clauses
For every clause u∨v∨w of , connect u, v, w, and T using the gadget below.
T
u
v
w
Coloring
• Step 4: Argue that the reduction is correct
〈〉 ∈ 3SAT
has a SAT assignment a
✔(x1∨x1∨x2)∧(x1∨x2∨x3 )
x1 x1 x2 x2 x3 x3
X
T F
〈 G 〉 ∈ 3COL
G has a valid 3-coloring
Each literal gets “color” as in a
Each clause gadget contains a true literal, so it can be colored
Coloring
• Step 4: Argue that the reduction is correct
〈〉 ∈ 3SAT
has a SAT assignment
✔(x1∨x1∨x2)∧(x1∨x2∨x3 )
x1 x1 x2 x2 x3 x3
X
T F
〈 G 〉 ∈ 3COL
G has a valid 3-coloring c
Each variable gets value as in G
Since each clause gadget is colored properly,each clause must contain a true literal
xi = true, if node xi has same color as T false, if node xi has same color as F
Recommended