1 / 40

CSCI 3130: Formal languages and automata theory

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.

Télécharger la présentation

CSCI 3130: Formal languages and automata theory

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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

  2. NP-completeness IS reduces to VC CLIQUE Cook-Levin theorem: 3SAT SAT NP-complete Everythingin NP reduces to SAT P NP (easy to solve) (easy to verify solution)

  3. Polynomial-time reductions • Language Lpolynomial-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 (CLIQUE) L’ (IS) R (G, k) x y (G’, k’) x ∈ L y ∈ L’ (G has clique of size k) (G’ has IS of size k’)

  4. SAT and 3SAT SAT = {〈f〉: fis a satisfiable Boolean formula} ((x1∨x2 ) ∧ (x1∨x2)) ∨ ((x1∨(x2 ∧ x3)) ∧x3) 3SAT = {〈f〉: fis a satisfiable 3CNF formula} (x1∨x2∨x2 ) ∧ (x2∨x3∨x4) ∧ (x2∨x3∨x5) ∧ (x1∨x5∨x5)

  5. The Cook-Levin Theorem • To show this, we need a reduction R such that: Every L∈NP reduces to SAT R z Boolean formula f f is satisfiable z ∈ L

  6. NP-completeness of SAT • All we know: L has a polynomial-time verifierV • Look at the computation tableau of V on input 〈z, s〉 S z | s V … q0 z1 z2 S-th configuration symbol at time T T … qacc a b

  7. NP-completeness of SAT S … q0 z1 n = length of z z2 height of tableau isO(nc) for some constantc T u width is at most nc k possible tableau symbols … qacc a b true, if the (T, S) cell of tableau contains u 1 ≤ S ≤ nc xT, S, u = 1 ≤ T ≤ nc false, if not 1 ≤ u ≤ k

  8. NP-completeness of SAT • We will design a formula f such that: R z Boolean formula f f is satisfiable z ∈ L variables of f : xT, S, u assignment to xT, S, u way to fill up the tableau accepting computation tableau satisfying assignment f is satisfiable V accepts 〈z, s〉for some s

  9. NP-completeness of SAT • We want to construct (in time O(n2c)) a formula f : true, if the (T, S) cell of tableau contains u 1 ≤ S ≤ nc xT, S, u = 1 ≤ T ≤ nc false, if not 1 ≤ u ≤ k true, if the xs represent a legal and accepting tableau f(x1, 1, 1, ..., xnc, nc, k) = false, if not

  10. NP-completeness of SAT f = fcell ∧ f0 ∧ fmove ∧ facc … q0 z1 z2 fcell: “Every cell contains exactly one symbol” f0: “The first row is q0z|s☐...☐” for some s … qacc a b fmove: “The moves between rows follow the transitions of V” facc: “qacc appears somewhere in the last row”

  11. NP-completeness of SAT fcell: “Every cell contains exactly one symbol” “Exactly one of xS, T, 1 ∨ ... ∨ xS, T, k is true” fcell = fcell1, 1 ∧ ... ∧ fcellnc,nc where fcellT, 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

  12. NP-completeness of SAT f0: “The first row is q0z1z2...zn|s1s2...sm for some (possible solution) s1s2...sm” f0 = x1, 1, q0 ∧ x1, 2, z1 ∧ ... ∧ x1, n+1,zn ∧ x1, n+2, |

  13. NP-completeness of SAT facc: “qacc appears somewhere in the last row” facc = xnc, 1, qacc ∨ xnc, 2, qacc ∨ ... ∨ xnc, nc, qacc

  14. Legal and illegal windows legal windows illegal windows … 6a3b0x0 … … 0a6b0x0…0 … 6q2a0b0 … … 0a6b0q2 …0 … 6a3q2a0 … … 0q5a6x0…0 … 6q2q2a0 … … 0q2q2x3…0 q2 a/xL … 6#3b0a0 … … 0#6b0q5 …0 … 6a3q2a0 … … 0q5a6b0…0 q5 … 6a3a0☐0 … … 0x6a0☐0…0 … 6#3q2a0 … … 0q5#6x0…0

  15. NP-completeness of SAT … q0 z1 z2 fmove: “The moves between rows follow transitions of V” a2 a3 a1 a4 a5 a6 LW = list of all legal windows fmove2, 2 = {(a1, a2, a3, a4, a5, a6): is legal} … qacc a b fmove = fmove1, 1 ∧ ... ∧ fmovenc-3, nc-3 ∨ fmoveT, 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 (a1, a2, a3, a4, a5, a6) ∈ LW a4 a5 a6

  16. NP-completeness of SAT R z Boolean formula f ✔ f is satisfiable z ∈ L Let V be a poly-time verifier TM for L. R := On input z, Construct the formulas fcell,f0,fmove, andfacc Output the formula f = fcell ∧ f0 ∧ fmove ∧ facc. Then R is computable in time O(n2c) and V accepts z if and only if f is satisfiable.

  17. How to argue NP-completeness SUBGRAPH = {〈G, H〉: Gand H are graphs where H is a subgraph of G} 6 7 4 5 4 Every edge of H must be included in G 3 1 2 1 2 3 G H SUBGRAPH is NP-complete

  18. How to argue NP-completeness ✔ • Step 1: SUBGRAPH is in NP What is a solution for SUBGRAPH? H G 6 7 4 A solution s is a map from vertices of H to vertices of G 5 4 3 (1➝4)(2➝2)(3➝5)(4➝7) 1 2 1 2 3 V := On input 〈G, H, s〉 Running time = O(m) m = number edges in H 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.

  19. How to argue NP-completeness • Step 2: Some NP-complete Lreduces to SUBGRAPH Direction of reduction is important! You want to show SUBGRAPH is harder than L VERTEX COVER So you assume you can solve SUBGRAPH, and show how to solve L IND SET CLIQUE SAT 3SAT This requires converting instances of L intoinstances of SUBGRAPH How to choose L?

  20. 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 4 G G H 6 7 4 CLIQUE 5 SUBGRAPH 4 3 1 2 1 2 3

  21. How to argue NP-completeness ✔ • Step 3: Reduce CLIQUE to SUBGRAPH CLIQUE = {〈G, k〉: Ghas a k-clique} SUBGRAPH = {〈G, H〉:H is a subgraph of G} R := On input 〈G, k〉 Ghas a k-clique Construct the k-clique H Output 〈G, H〉 H is a subgraph of G

  22. 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? Yes Does it have a 1-cover for triangles? No, because it has two vertex-disjoint triangles TRICOVER = {〈G, k〉:G has a k-coverfor triangles} TRICOVER is NP-complete

  23. Cover for triangles 6 7 ✔ • Step 1: TRICOVER is in NP 5 4 What is a solution for TRICOVER? 1 2 3 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, orw are ins, reject. Otherwise, accept. Running time = O(n3)

  24. Cover for triangles • Step 2: Some NP-complete Lreduces to TRICOVER TRICOVER = {〈G, k〉:G has a k-coverfor triangles} SUBGRAPH VERTEX COVER Some vertex in every triangle is covered CLIQUE IND SET VC = {〈G, k〉:G has a k-vertex cover} SAT 3SAT Some endpoint of every edge is covered

  25. Cover for triangles • Step 3: Reduce VC to TRICOVER VC = {〈G, k〉:G has a k-vertex cover (for edges)} TRICOVER = {〈G’, k’〉:G’ has k’-coverfor triangles} Idea: Replace edges by triangles G G’ vertex-cover in G cover for triangles in G’

  26. Cover for triangles • Step 3: Reduce VC to TRICOVER R := On input 〈G, k〉, where G has nvertices andmedges Construct the following graph G’: G’ has n + mvertices v1, ..., vn, anduij 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

  27. Cover for triangles • Step 4: Argue that the reduction is correct 〈G, k〉 ∈ VC 〈G’, k〉 ∈ TRICOVER G ✔ G’ 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

  28. Cover for triangles • Step 4: Argue that the reduction is correct ✔ 〈G, k〉 ∈ VC 〈G’, k〉 ∈ TRICOVER G G’ ✔ G has a k-vertex cover C’ G’ has a k-vertex cover C C’ is obtained after moving some vertices of C Some vertices in C may not come from G! Since C’covers all triangles in G’, it must cover all edges in G But we can move them and still cover the same triangle

  29. Coloring Suppose you need to schedule exams on same day in 3 time slots CSCI 3190 CSCI 3230 CSCI 2110 Y R B 1030-1230 130-330 430-630 CSCI 3130 CSCI 3160 Some people are enrolled in multiple classes, so there may be conflicts Task: Schedule the exams so there are no conflicts

  30. Coloring Given a graph, we want to color the 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

  31. Coloring ✔ 5 • Step 1: 3COL is in NP 4 G 3 What is a solution for 3COL? 1 2 A solution s is a coloring of vertices like {1B,2R,3Y,4R,5B} V := On input 〈G, s〉 Running time = O(m) For every edge {u, v} of G: If uand v are assigned same color in s, reject. Otherwise, accept.

  32. Coloring • Step 2: Some NP-complete Lreduces to 3COL 3COL = {〈G〉:G has a valid 3-coloring} SUBGRAPH 3COL does not look like any of these problems VERTEX COVER CLIQUE IND SET In such a case it is a good idea to start with 3SAT SAT 3SAT

  33. Coloring • Step 3: Reduce 3SAT to 3COL 3SAT = {〈f〉:f is a 3CNF that has a satisfying assignment} 3COL = {〈G〉:G has a valid 3-coloring} Idea: Assignment of f Coloring of G G X T F Part I: 3 special vertices T (true), F (false), and X

  34. Coloring Either xi has color of T and xi has color of F X xi xi Or xi has color of F and xi has color of T Part 2: For each variable xi T F F T F T x1 x1 x2 x2 x3 x3 X T F Example: (x1∨x1∨x2)∧(x1∨x2∨x3 )

  35. Coloring • To “encode” the clauses of f, we need a gadget x If xory is colored T, zcan be colored T z If xandy are colored F, zmust be colored F y x1 Can be colored if and only if at least one literal is colored T x2 T x3 Part 3: For each clause like (x1∨x2∨x3 )

  36. Coloring reduction: An example x1 x1 x2 x2 x3 x3 X T F Example: (x1∨x1∨x2)∧(x1∨x2∨x3 ) T T T F F F

  37. Coloring reduction: An example x1 x1 x2 x2 x3 x3 X T F Example: (x1∨x1∨x2)∧(x1∨x2∨x3 ) T T T F F F

  38. Coloring • Step 3: Reduce 3SAT to 3COL Running time = O(m + n) n = number of variables m = number of clauses R := On input 〈f〉, where f is a 3CNF: Construct the following graph G: Add 3 special vertices T, F, X connected by a triangle. For every variable xiof f, add vertices xi and xi and include the triangle xi, xi, X. u For every clause u∨v∨wof f, connect u, v, w,and T using the gadget below. v w Output 〈G〉. T

  39. Coloring • Step 4: Argue that the reduction is correct 〈f〉 ∈ 3SAT 〈G〉 ∈ 3COL ✔ x1 x1 x2 x2 x3 x3 X f has a SAT assignment a G has a valid 3-coloring T F Each literal gets “color” as in a Each clause gadget contains a true literal, so it can be colored (x1∨x1∨x2)∧(x1∨x2∨x3 )

  40. Coloring • Step 4: Argue that the reduction is correct 〈f〉 ∈ 3SAT 〈G〉 ∈ 3COL ✔ x1 x1 x2 x2 x3 x3 f has a SAT assignment G has a valid 3-coloring c X Each variable gets value as in G T F true, if node xi has same color as T xi = false, if node xi has same color as F (x1∨x1∨x2)∧(x1∨x2∨x3 ) Since each clause gadget is colored properly, each clause must contain a true literal

More Related