CSCI 3130: Formal languages and automata theory Andrej Bogdanov The Chinese University of Hong Kong The Cook-Levin.

Slides:



Advertisements
Similar presentations
INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011.
Advertisements

Theory of Computing Lecture 18 MAS 714 Hartmut Klauck.
Polynomial-time reductions We have seen several reductions:
NP-Completeness: Reductions
Department of Computer Science & Engineering
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY
INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011.
Complexity 11-1 Complexity Andrei Bulatov NP-Completeness.
NP-completeness Sipser 7.4 (pages 271 – 283). CS 311 Fall The classes P and NP NP = ∪ k NTIME(n k ) P = ∪ k TIME(n k )
CS21 Decidability and Tractability
February 23, 2015CS21 Lecture 201 CS21 Decidability and Tractability Lecture 20 February 23, 2015.
Computability and Complexity 15-1 Computability and Complexity Andrei Bulatov NP-Completeness.
Graphs 4/16/2017 8:41 PM NP-Completeness.
NP and NP-completeness
1 Polynomial Time Reductions Polynomial Computable function : For any computes in polynomial time.
1 CSE 417: Algorithms and Computational Complexity Winter 2001 Lecture 23 Instructor: Paul Beame.
Fall 2006Costas Busch - RPI1 More NP-complete Problems.
Time Complexity.
NP-Completeness (2) NP-Completeness Graphs 4/17/2017 6:25 AM x x x x x
1 CSE 417: Algorithms and Computational Complexity Winter 2001 Lecture 24 Instructor: Paul Beame.
CS Master – Introduction to the Theory of Computation Jan Maluszynski - HT Lecture NP-Completeness Jan Maluszynski, IDA, 2007
Nattee Niparnan. Easy & Hard Problem What is “difficulty” of problem? Difficult for computer scientist to derive algorithm for the problem? Difficult.
Lecture 22 More NPC problems
INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011.
NP-complete Problems SAT 3SAT Independent Set Hamiltonian Cycle
Week 10Complexity of Algorithms1 Hard Computational Problems Some computational problems are hard Despite a numerous attempts we do not know any efficient.
EMIS 8373: Integer Programming NP-Complete Problems updated 21 April 2009.
CSC401 – Analysis of Algorithms Chapter 13 NP-Completeness Objectives: Introduce the definitions of P and NP problems Introduce the definitions of NP-hard.
Additional NP-complete problems
NP-Complete Problems. Running Time v.s. Input Size Concern with problems whose complexity may be described by exponential functions. Tractable problems.
NP-completeness Section 7.4 Giorgi Japaridze Theory of Computability.
CSE 6311 – Spring 2009 ADVANCED COMPUTATIONAL MODELS AND ALGORITHMS Lecture Notes – Feb. 3, 2009 Instructor: Dr. Gautam Das notes by Walter Wilson.
NPC.
NP Completeness Piyush Kumar. Today Reductions Proving Lower Bounds revisited Decision and Optimization Problems SAT and 3-SAT P Vs NP Dealing with NP-Complete.
NP-Completeness Note. Some illustrations are taken from (KT) Kleinberg and Tardos. Algorithm Design (DPV)Dasgupta, Papadimitriou, and Vazirani. Algorithms.
NP-complete Languages
CSCI 2670 Introduction to Theory of Computing December 2, 2004.
CSCI 2670 Introduction to Theory of Computing December 7, 2005.
CSE 421 Algorithms Richard Anderson Lecture 27 NP-Completeness Proofs.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong NP-complete.
Given this 3-SAT problem: (x1 or x2 or x3) AND (¬x1 or ¬x2 or ¬x2) AND (¬x3 or ¬x1 or x2) 1. Draw the graph that you would use if you want to solve this.
Prof. Busch - LSU1 Busch Complexity Lectures: More NP-complete Problems.
Complexity ©D.Moshkovitz 1 Our First NP-Complete Problem The Cook-Levin theorem A B C.
COSC 3101A - Design and Analysis of Algorithms 14 NP-Completeness.
COMPLEXITY. Satisfiability(SAT) problem Conjunctive normal form(CNF): Let S be a Boolean expression in CNF. That is, S is the product(and) of several.
Computability Examples. Reducibility. NP completeness. Homework: Find other examples of NP complete problems.
1 Design and Analysis of Algorithms Yoram Moses Lecture 13 June 17, 2010
 2005 SDU Lecture15 P,NP,NP-complete.  2005 SDU 2 The PATH problem PATH = { | G is a directed graph that has a directed path from s to t} s t
TU/e Algorithms (2IL15) – Lecture 10 1 NP-Completeness, II.
NP-Completeness (2) NP-Completeness Graphs 4/13/2018 5:22 AM x x x x x
NP and NP-completeness
Richard Anderson Lecture 26 NP-Completeness
NP-Completeness (2) NP-Completeness Graphs 7/23/ :02 PM x x x x
NP-Completeness (2) NP-Completeness Graphs 7/23/ :02 PM x x x x
NP-Completeness Proofs
Richard Anderson Lecture 26 NP-Completeness
NP-complete problems The Chinese University of Hong Kong Fall 2008
NP-Completeness Yin Tat Lee
CS21 Decidability and Tractability
Intro to Theory of Computation
NP-Completeness (2) NP-Completeness Graphs 11/23/2018 2:12 PM x x x x
More NP-complete Problems
NP-Complete Problems.
NP-completeness The Chinese University of Hong Kong Fall 2008
NP-Completeness Yin Tat Lee
CS21 Decidability and Tractability
More on NP-completeness
More NP-complete problems
Instructor: Aaron Roth
NP-Completeness (2) NP-Completeness Graphs 7/9/2019 6:12 AM x x x x x
Presentation transcript:

CSCI 3130: Formal languages and automata theory Andrej Bogdanov 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 CLIQUE VC 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’ LL’L’(CLIQUE)(IS) xy (G, k) (G’, k’) x ∈ Lx ∈ L y ∈ 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 } (x 1 ∨ x 2 ∨ x 2 ) ∧ (x 2 ∨ x 3 ∨ x 4 ) ∧ (x 2 ∨ x 3 ∨ x 5 ) ∧ (x 1 ∨ x 5 ∨ x 5 ) ((x 1 ∨ x 2 ) ∧ (x 1 ∨ x 2 )) ∨ ((x 1 ∨ (x 2 ∧ x 3 )) ∧ x 3 )

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 ∈ Lz ∈ 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 〉 V z | s z2z2 z1z1 q acc … S- th configuration symbol at time T S T … q0q0 b a

NP-completeness of SAT n = length of z height of tableau is O(n c ) for some constant c width is at most n c k possible tableau symbols x T, S, u = true,if the (T, S) cell of tableau contains u if not false, u 1 ≤ S ≤ n c 1 ≤ T ≤ n c 1 ≤ u ≤ k S T z2z2 z1z1 … q0q0 q acc … b a

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

NP-completeness of SAT We want to construct (in time O(n 2c ) ) a formula f : x T, S, u = true,if the (T, S) cell of tableau contains u if not false, 1 ≤ S ≤ n c 1 ≤ T ≤ n c 1 ≤ u ≤ k f(x 1, 1, 1,..., x nc, nc, k ) = true,if the x s represent a legal and accepting tableau if not false,

NP-completeness of SAT f = f cell ∧ f 0 ∧ f move ∧ f acc f cell : “Every cell contains exactly one symbol” “The first row is q 0 z|s ☐... ☐ ” for some s f0:f0: f move : “The moves between rows follow the transitions of V ” f acc : “ q acc appears somewhere in the last row” z2z2 z1z1 q acc … … q0q0 b a

NP-completeness of SAT f cell : “Every cell contains exactly one symbol” f cell = f cell 1, 1 ∧... ∧ f cell nc, nc where f cell T, S = (x T, S, 1 ∨... ∨ x T, S, k ) ∧ (x T, S, 1 ∧ x T, S, 2 ) ∧ (x T, S, 1 ∧ x T, S, 3 ) ∧... ∧ (x T, S, k-1 ∧ x T, S, k ) at least one symbol no cell contains two or more symbols “Exactly one of x S, T, 1 ∨... ∨ x S, T, k is true”

NP-completeness of SAT f0:f0: “The first row is q 0 z 1 z 2...z n |s 1 s 2...s m f 0 = x 1, 1, q0 ∧ x 1, 2, z1 ∧... ∧ x 1, n+1, zn ∧ x 1, n+2, | for some (possible solution) s 1 s 2...s m ”

NP-completeness of SAT f acc : “ q acc appears somewhere in the last row” f acc = x nc, 1, qacc ∨ x nc, 2, qacc ∨... ∨ x nc, nc, qacc

Legal and illegal windows … 6 a 3 b 0 x 0 … … 0 a 6 b 0 x 0 … 0 legal windows … 6 # 3 b 0 a 0 … … 0 # 6 b 0 q 5 … 0 … 6 a 3 q 2 a 0 … … 0 q 5 a 6 x 0 … 0 … 6 q 2 a 0 b 0 … … 0 a 6 b 0 q 2 … 0 illegal windows … 6 a 3 a 0 ☐ 0 … … 0 x 6 a 0 ☐ 0 … 0 q2q2 q5q5 a/xLa/xL … 6 a 3 q 2 a 0 … … 0 q 5 a 6 b 0 … 0 … 6 q 2 q 2 a 0 … … 0 q 2 q 2 x 3 … 0 … 6 # 3 q 2 a 0 … … 0 q 5 # 6 x 0 … 0

NP-completeness of SAT f move : “The moves between rows follow transitions of V ” f move = f move 1, 1 ∧... ∧ f move nc-3, nc-3 a2a2 a1a1 a3a3 a6a6 a4a4 a5a5 f move 2, 2 LW = list of all legal windows = {(a 1, a 2, a 3, a 4, a 5, a 6 ): is legal} a1a1a2a2a3a3 a4a4a5a5a6a6 z2z2 z1z1 q0q0 … q acc … b a f move T, S = (x T, S, a1 ∧ x T, S+1, a2 ∧ x T, S+2, a3 ∧ x T+1, S, a4 ∧ x T+1, S+1, a5 ∧ x T+2, S+1, a6 ) ∨ (a 1, a 2, a 3, a 4, a 5, a 6 ) ∈ LW

NP-completeness of SAT z Boolean formula f z ∈ Lz ∈ L f is satisfiable R Let V be a poly-time verifier TM for L. On input z, Construct the formulas f cell, f 0, f move, and f acc Output the formula f = f cell ∧ f 0 ∧ f move ∧ f acc. R := ✔ V accepts z if and only if f is satisfiable. Then R is computable in time O(n 2c ) and

How to argue NP-completeness SUBGRAPH = { 〈 G, H 〉 : G and H are graphs where H is a subgraph of G} GH SUBGRAPH is NP -complete Every edge of H must be included in G

How to argue NP-completeness Step 1: SUBGRAPH is in NP G H 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 CLIQUE IND 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 GH G 4 CLIQUESUBGRAPH

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(n 3 ) ✔

CLIQUE IND 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 GG’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 v 1,..., v n, and u ij for every edge {v i, v j } of G For every edge {v i, v j } of G, include the edges {v i, v j }, {v i, u ij }, {v j, u ij } 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 GG’G’ 〈 G, k 〉 ∈ VC 〈 G’, k 〉 ∈ TRICOVER G has a k -vertex cover CC 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 GG’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 not come from G ! But we can move them and still cover the same triangle ✔ C’ is obtained after moving some vertices of C Since C’ covers all triangles in G’, it must cover all edges in G ✔

Coloring CSCI 3230 CSCI 2110 CSCI 3160 CSCI 3130 Suppose you need to schedule exams on same day in 3 time slots YRB CSCI 3190 Some people are enrolled in multiple classes, so there may be conflicts Task: Schedule the exams so there are no conflicts

Coloring Given a graph, we want to color the vertices so every edge has endpoints of different colors G YRB 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

CLIQUE IND 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 like any of these problems In such a case it is a good idea 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 x i xixi X xixi Either x i has color of T and x i has color of F Or x i has color of F and x i has color of T Example: (x 1 ∨ x 1 ∨ x 2 ) ∧ (x 1 ∨ x 2 ∨ x 3 ) x1x1 x1x1 x2x2 x2x2 x3x3 x3x3 X TF TFFTFT

Coloring To “encode” the clauses of , we need a gadget Can be colored if and only if at least one literal is colored T T x1x1 x2x2 x3x3 x y z If x or y is colored T, z can be colored T If x and y are colored F, z must be colored F Part 3: For each clause like (x 1 ∨ x 2 ∨ x 3 )

Coloring reduction: An example Example: (x 1 ∨ x 1 ∨ x 2 ) ∧ (x 1 ∨ x 2 ∨ x 3 ) x1x1 x1x1 x2x2 x2x2 x3x3 x3x3 X TF T F F T F T

Coloring reduction: An example Example: (x 1 ∨ x 1 ∨ x 2 ) ∧ (x 1 ∨ x 2 ∨ x 3 ) x1x1 x1x1 x2x2 x2x2 x3x3 x3x3 X TF 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 x i of , add vertices x i and x i and include the triangle x i, x i, X. Output 〈 G 〉. Running time = O(m + n) n = number of variables m = 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 ✔ (x 1 ∨ x 1 ∨ x 2 ) ∧ (x 1 ∨ x 2 ∨ x 3 ) x1x1 x1x1 x2x2 x2x2 x3x3 x3x3 X TF 〈 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 ✔ (x 1 ∨ x 1 ∨ x 2 ) ∧ (x 1 ∨ x 2 ∨ x 3 ) x1x1 x1x1 x2x2 x2x2 x3x3 x3x3 X TF 〈 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 x i = true, if node x i has same color as T false, if node x i has same color as F