Reductions & NP-completeness as part of Foundations of Computer Science undergraduate course Alex Angelopoulos, NTUA January 22, 2015
Outline Alex Angelopoulos (NTUA) FoCS: Reductions & NP-completeness- 0/1 Integer Programming 2/26 0/1 Integer Programming Vertex Cover 3-colorability Hamilton Path (HP) Traveling Salesman Problem (TSP)
Reducing 3-SAT to 0/1 IP Definition 1 (0/1 IP). Input: an integer matrix C and vector b. Output: decide if there is a 0/1 vector x such that: Cx b. 0/1 IP NP (why?) We choose 3-SAT as our known NP-complete problem and consider the formula: φ = C 1 C 2... C m, literals x 1,..., x n We will construct our m n matrix C : 1, if x j C i c ij = 1, if x j C i 0, otherwise b i = 1 (the number of complemented variables in C i ) Alex Angelopoulos (NTUA) FoCS: Reductions & NP-completeness- 0/1 Integer Programming 3/26
Reducing 3-SAT to 0/1 IP Alex Angelopoulos (NTUA) FoCS: Reductions & NP-completeness- 0/1 Integer Programming 4/26 Note that: Cx b actually means n j=1 c ijx j b i, i. If 3-SAT is satisfiable, then every C i is True. Focus on a line of C and discard the zeros: c ij1 x j1 + c ij2 x j2 + c ij3 x j3 1 #(complemented) = 1x j1 + 1x j2 + 1x j3 1 1x j1 + 1x j2 1x j3 0 1x j1 1x j2 1x j3 1 1x j1 1x j2 1x j3 2 3-SAT P 0/1 IP
Outline Alex Angelopoulos (NTUA) FoCS: Reductions & NP-completeness- Vertex Cover 5/26 0/1 Integer Programming Vertex Cover 3-colorability Hamilton Path (HP) Traveling Salesman Problem (TSP)
From 3-SAT to Vertex Cover Alex Angelopoulos (NTUA) FoCS: Reductions & NP-completeness- Vertex Cover 6/26 Definition 2 (Vertex Cover (VC)). Input: a graph G(V, E). Output: decide if there is a set S V of size S k such that every edge is adjacent to a vertex v S. VC NP (why?) We choose 3-SAT as our known NP-complete problem and consider (again) the formula: φ = C 1 C 2... C m, with literals x 1,..., x n
Intro to gadgets! Alex Angelopoulos (NTUA) FoCS: Reductions & NP-completeness- Vertex Cover 7/26 A gadget is anything (in the context of the target problem) that can help you fix the desired instance... z y y x x x y z z Size of a VC here: 5 = 3 (literals) + 2 (2 clause)
G φ and the if and only if check Alex Angelopoulos (NTUA) FoCS: Reductions & NP-completeness- Vertex Cover 8/26 φ = (x y z) ( y z w) x x y y z z w w z w x y y z ( ) {x, y, z, w} = {T, F, T, T } is a satisfying assignment. See that we need 2 nodes from each clause gadget in order to get a valid VC of size k = n + 2m.
Alex Angelopoulos (NTUA) FoCS: Reductions & NP-completeness- Vertex Cover 9/26 G φ and the if and only if check x x y y z z w w z w x y y z ( ) For a VC we must get: At least 1 vertex of each literal gadget Clause gadget s vetrices cannot cover the literal gadget s edges. At least 2 vertices of each clause gadget (1 cannot cover the triangle). If there is a cover of size n + 2m then the literal gadgets indicate the satisfying assignment!
Outline Alex Angelopoulos (NTUA) FoCS: Reductions & NP-completeness- 3-colorability 10/26 0/1 Integer Programming Vertex Cover 3-colorability Hamilton Path (HP) Traveling Salesman Problem (TSP)
Reducing 3-SAT to 3-COLOR Alex Angelopoulos (NTUA) FoCS: Reductions & NP-completeness- 3-colorability 11/26 Definition 3 (3-COLOR). Input: a graph G(V, E). Output: decide if χ(g) 3? 3-COLOR NP (why?) We choose 3-SAT as our known NP-complete problem and consider (yet again) the formula: φ = C 1 C 2... C m, with literals x 1,..., x n
Alex Angelopoulos (NTUA) FoCS: Reductions & NP-completeness- 3-colorability 12/26 Constructing the graph G φ We ll consider the forumla φ = (x y z) ( y z w). Let s start with the vertices of the literals: for each x i we create v i and v i. In order to dictate an equivalent True/False coloring of v i, v i, we draw all edges v i v i plus we link all v i, v i with a base vertex b. Check that now we have n triangles, all having b in common. b x x y y z z w w
c Alex Angelopoulos (NTUA) FoCS: Reductions & NP-completeness- 3-colorability 13/26 Constructing the graph G φ The gadget: a color-driven or gate C i s literals as input a b c C i evaluation If all a,b,c are colored False, the output vertex has to be False. If a or b or c is True, then the output vertex can also be True.
Alex Angelopoulos (NTUA) FoCS: Reductions & NP-completeness- 3-colorability 14/26 Completing G φ φ = (x y z) ( y z w) t f b x x Let s satisfy φ... χ(g φ ) 3 y y G 1 z z w w G 2
Checking the if and only if Alex Angelopoulos (NTUA) FoCS: Reductions & NP-completeness- 3-colorability 15/26 Now let G φ be 3-colorable. And pay attention to the coloring of u i, ū i t f b 3-SAT P 3-COLOR u1 u1 u2 u2 G1 u3 u3 u4 u4. G2. Since the gadgets output orange, they must each have an orange input. So our true color is the orange, and an assignment that satisfies φ follows the orange u-nodes.
Outline Alex Angelopoulos (NTUA) FoCS: Reductions & NP-completeness- Hamilton Path (HP) 16/26 0/1 Integer Programming Vertex Cover 3-colorability Hamilton Path (HP) Traveling Salesman Problem (TSP)
Reducing 3-SAT to Hamilton Path Alex Angelopoulos (NTUA) FoCS: Reductions & NP-completeness- Hamilton Path (HP) 17/26 Definition 4 (Hamilton Path). Input: graph G. Output: decide whether G allows a path visiting all nodes excatly once. Hamilton Path NP. We can guess n 1 edges and verify if they add up to a Hamilton Path. We need 3 gadgets for this problem..
Alex Angelopoulos (NTUA) FoCS: Reductions & NP-completeness- Hamilton Path (HP) 18/26 Gadgets (1/3) The choice gadget - one per literal T F Actually, the colored edges will become subgraphs that allow a path between the blue nodes. They sure translate to an evaluation True of False for the literal.
Alex Angelopoulos (NTUA) FoCS: Reductions & NP-completeness- Hamilton Path (HP) 19/26 Gadgets (2/3) The consistency gadget - an xor gate A part o a Hamilton Path must either enter and exit this subgraph using both top vertices or both bottom vertices. That exclusive or functionality will be the hint for gadget 3 to prove useful.
Gadgets (3/3) Alex Angelopoulos (NTUA) FoCS: Reductions & NP-completeness- Hamilton Path (HP) 20/26 The constraint gadget - one per clause x 3 x 3 x 1 x 1 C i x 2 x 2 Let s take C i = (x 1 x 2 x 3 ) We must force that the edges (paths) of the triangle are traversed by a Hamilton Path if and only if the corresponding literal is false. Then the clause is True, or else there would be no Hamilton Path!
Constructing the full R(φ) Alex Angelopoulos (NTUA) FoCS: Reductions & NP-completeness- Hamilton Path (HP) 21/26 Let φ = (x 1 x 2 x 3 ) ( x 1 x 2 x 3 ) ( x 1 x 2 x 3 ) s t Orange nodes form a clique
Alex Angelopoulos (NTUA) FoCS: Reductions & NP-completeness- Hamilton Path (HP) 22/26 φ is satisfiable R(φ) has a Hamilton Path Let φ = (x 1 x 2 x 3 ) ( x 1 x 2 x 3 ) ( x 1 x 2 x 3 ) s t
Alex Angelopoulos (NTUA) FoCS: Reductions & NP-completeness- Hamilton Path (HP) 23/26 R(φ) has a Hamilton Path φ is satisfiable Remember the costraint gadget. If the red edge- xor path belongs to the Hamilton Path, then both green edges do not belong to the path. But this defines a truth assignment, where no clause gets all 3 literals false. t3-sat P Hamilton Path
Outline Alex Angelopoulos (NTUA) FoCS: Reductions & NP-completeness- Traveling Salesman Problem (TSP) 24/26 0/1 Integer Programming Vertex Cover 3-colorability Hamilton Path (HP) Traveling Salesman Problem (TSP)
The Traveling Salesman Problem Alex Angelopoulos (NTUA) FoCS: Reductions & NP-completeness- Traveling Salesman Problem (TSP) 25/26 Definition 5 (TSP). Given a set of n cities and the distance between any two of them, find the shortest tour covering all cities. Definition 6 (TSP (Decision problem)). Input: a complete graph G with weighted edges, budget (target cost) B Output: is there a tour (cycle) visiting every vertex of G with total cost B? Verify that TSP(D) belongs to class NP... We shall use Hamilton Path as ou known NP-complete problem.
Alex Angelopoulos (NTUA) FoCS: Reductions & NP-completeness- Traveling Salesman Problem (TSP) 26/26 Hamilton Path P TSP(D) Take any instance of Hamilton Path (i.e. any graph G with n vertices) and take a copy of it, Ḡ. Set all edges of Ḡ to have a weight equal to 1. Insert all missing edges of Ḡ with weight 2. To finalize the instance of TSP(D), take B = n + 1. G has a Hamilton Path Ḡ has a tour of cost n + 1... Hamilton Path P TSP(D) Ḡ has a tour of cost n + 1 G has a Hamilton Path...