1 / 32

CSCI 3130: Formal languages and automata theory

Fall 2010. The Chinese University of Hong Kong. CSCI 3130: Formal languages and automata theory. More NP-complete problems. Andrej Bogdanov http://www.cse.cuhk.edu.hk/~andrejb/csc3130. NP-complete problems. NP-complete. DOM SET. MIN COVER. VERTEX COVER. SUBSET SUM. IND SET. HAM CYCLE.

Download Presentation

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 2010 The Chinese University of Hong Kong CSCI 3130: Formal languages and automata theory More NP-complete problems Andrej Bogdanov http://www.cse.cuhk.edu.hk/~andrejb/csc3130

  2. NP-complete problems NP-complete DOM SET MIN COVER VERTEX COVER SUBSET SUM IND SET HAM CYCLE HAM PATH PARTITION CLIQUE 3SAT NP SAT P

  3. 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)

  4. Reducing SAT to 3SAT • Example: f = (x2∨(x1∧x2 ))∧(x1∧(x1∨x2 )) x4x5 x7 x7 = x4 ∧ x5 x10 T T T TT T F FT F T FT F F TF T T FF T F TF F T FF F F T AND (x4∨x5∨x7) x8 x9 (x4∨x5∨x7) OR NOT x6 x7 (x4∨x5∨x7) AND AND (x4∨x5∨x7) x4 x5 x3 NOT NOT OR (x4∨x5∨x7) ∧(x4∨x5∨x7) x2 x1 x2 x1 x1 x2 ∧(x4∨x5∨x7) ∧(x4∨x5∨x7) We add extra variables for every gate (“wire”)

  5. Turning gates into 3CNFs z z z Gj: AND OR NOT x y x y x x y z = y ∧ x x y z = y ∨ x x z = x z z z T T T TT T F FT F T FT F F TF T T FF T F TF F T FF F F T T T T TT T F FT F T TT F F FF T T TF T F FF F T FF F F T T T FT F T F T TF F F (x∨z)∧(x∨z) (x∨y∨z)∧(x∨y∨z) ∧(x∨y∨z)∧(x∨y∨z) (x∨y∨z)∧(x∨y∨z) ∧(x∨y∨z)∧(x∨y∨z) fj: (x∨x∨z)∧(x∨x∨z)

  6. Reducing SAT to 3SAT R Boolean formula f 3CNF formula f’ R:= On input f, where f is a boolean formula Construct and output the following 3CNF formula f’: f’ has extra variables xn+1, ..., xn+t one for each gate Gj in f For each gate Gj, construct the formulafj Output f’ = fn+1 ∧ fn+2 ∧ ... ∧ ft ∧ (xn+t ∨xn+t ∨xn+t ) requires thatoutput of f is true

  7. Example x4 AND f’ := (x2∨x2∨x3)∧(x2∨x2∨x3) NOT gate x3 (x1∨x3∨x4)∧(x1∨x3∨x4) ∧(x1∨x3∨x4)∧(x1∨x3∨x4) ∧ f = AND gate NOT (x4∨x4∨x4) ∧ output x1 x2 T AND T x1 = T, x2 = F, x3 = T, x4 = T NOT is a satisfying assignment of f’ T F

  8. Reducing SAT to 3SAT • Every satisfying assignment of f extends uniquely to a satisfying assignment of f’ • In the other direction, in every satisfying assignment of f’ the part x1, ..., xnis a satisfying assignment of f R Boolean formula f 3CNF formula f’ ✔ f’ is satisfiable f is satisfiable

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

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

  11. How to argue NP-completeness • Step 2: Some NP-complete Lreduces to SUBGRAPH Direction of reduction is important! DOM SET 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?

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

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

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

  15. 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)

  16. Cover for triangles • Step 2: Some NP-complete Lreduces to TRICOVER TRICOVER = {〈G, k〉:G has a k-coverfor triangles} SUBGRAPH DOM SET 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

  17. 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’

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

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

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

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

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

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

  24. Coloring • Step 2: Some NP-complete Lreduces to 3COL 3COL = {〈G〉:G has a valid 3-coloring} SUBGRAPH DOM SET 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

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

  26. 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 )

  27. 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 )

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

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

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

  31. 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 )

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