Today s Outline. CS 362, Lecture 23. Classes of Problems. NP-Hard. Review NP-Hardness and three more reductions. Jared Saia University of New Mexico

Similar documents
Classes of Problems. CS 461, Lecture 23. NP-Hard. Today s Outline. We can characterize many problems into three classes:

CS 561, Lecture 12. Jared Saia University of New Mexico

Today s Outline. CS 362, Lecture 24. The Reduction. Hamiltonian Cycle. Reduction Wrapup Approximation algorithms for NP-Hard Problems

NP Completeness. CS 374: Algorithms & Models of Computation, Spring Lecture 23. November 19, 2015

CS21 Decidability and Tractability

SAT, Coloring, Hamiltonian Cycle, TSP

P P P NP-Hard: L is NP-hard if for all L NP, L L. Thus, if we could solve L in polynomial. Cook's Theorem and Reductions

Algorithms, Lecture 3 on NP : Nondeterminis7c Polynomial Time

CSCI3390-Lecture 17: A sampler of NP-complete problems

NP and Computational Intractability

NP-Complete Reductions 2

NP-Complete Problems. More reductions

Introduction to Computational Complexity

1.1 P, NP, and NP-complete

Polynomial-time reductions. We have seen several reductions:

NP Complete Problems. COMP 215 Lecture 20

Limits to Approximability: When Algorithms Won't Help You. Note: Contents of today s lecture won t be on the exam

Polynomial-Time Reductions

Design and Analysis of Algorithms

Polynomial-time Reductions

Lecture 4: NP and computational intractability

CS 583: Algorithms. NP Completeness Ch 34. Intractability

CS21 Decidability and Tractability

NP-Completeness. Andreas Klappenecker. [based on slides by Prof. Welch]

NP Completeness and Approximation Algorithms

Computational Intractability 2010/4/15. Lecture 2

1. Introduction Recap

Summer School on Introduction to Algorithms and Optimization Techniques July 4-12, 2017 Organized by ACMU, ISI and IEEE CEDA.

1 Primals and Duals: Zero Sum Games

Algorithms and Theory of Computation. Lecture 22: NP-Completeness (2)

NP-Complete Reductions 1

NP-Hardness reductions

Show that the following problems are NP-complete

Algorithm Design and Analysis

NP and Computational Intractability

Lecture 24 : Even more reductions

Essential facts about NP-completeness:

COP 4531 Complexity & Analysis of Data Structures & Algorithms

Lecture 15 - NP Completeness 1

NP-Completeness. CptS 223 Advanced Data Structures. Larry Holder School of Electrical Engineering and Computer Science Washington State University

1 More finite deterministic automata

Notes for Lecture 21

COMP 382. Unit 10: NP-Completeness

UC Berkeley CS 170: Efficient Algorithms and Intractable Problems Handout 22 Lecturer: David Wagner April 24, Notes 22 for CS 170

NP and NP Completeness

Lecture 18: More NP-Complete Problems

Algorithm Design and Analysis

More NP-Complete Problems

NP-Completeness Review

Limitations of Algorithm Power

Today: NP-Completeness (con t.)

CS 320, Fall Dr. Geri Georg, Instructor 320 NP 1

Theory of Computation CS3102 Spring 2014 A tale of computers, math, problem solving, life, love and tragic death

Lecture 21: NP-Hard Problems

Correctness of Dijkstra s algorithm

Some Algebra Problems (Algorithmic) CSE 417 Introduction to Algorithms Winter Some Problems. A Brief History of Ideas

8.5 Sequencing Problems

VIII. NP-completeness

Topics in Complexity Theory

NP-problems continued

Lecture #14: NP-Completeness (Chapter 34 Old Edition Chapter 36) Discussion here is from the old edition.

Algorithm Design and Analysis

NP-complete Problems

Computer Science 385 Analysis of Algorithms Siena College Spring Topic Notes: Limitations of Algorithms

Introduction. Pvs.NPExample

Intro to Theory of Computation

15-451/651: Design & Analysis of Algorithms October 31, 2013 Lecture #20 last changed: October 31, 2013

Lecture 13, Fall 04/05

Some Algebra Problems (Algorithmic) CSE 417 Introduction to Algorithms Winter Some Problems. A Brief History of Ideas

Computational Complexity and Intractability: An Introduction to the Theory of NP. Chapter 9

CSI 4105 MIDTERM SOLUTION

CS 301: Complexity of Algorithms (Term I 2008) Alex Tiskin Harald Räcke. Hamiltonian Cycle. 8.5 Sequencing Problems. Directed Hamiltonian Cycle

Harvard CS 121 and CSCI E-121 Lecture 22: The P vs. NP Question and NP-completeness

NP-COMPLETE PROBLEMS. 1. Characterizing NP. Proof

SAT, NP, NP-Completeness

Chapter 34: NP-Completeness

NP-Completeness. Subhash Suri. May 15, 2018

More Completeness, conp, FNP,etc. CS254 Chris Pollett Oct 30, 2006.

1 Reductions and Expressiveness

Algorithms Design & Analysis. Approximation Algorithm

NP and NP-Completeness

Easy Problems vs. Hard Problems. CSE 421 Introduction to Algorithms Winter Is P a good definition of efficient? The class P

Lecture 12 Scribe Notes

Geometric Steiner Trees

Complexity, P and NP

Computational Complexity. IE 496 Lecture 6. Dr. Ted Ralphs

Comp487/587 - Boolean Formulas

CS 350 Algorithms and Complexity

CS 350 Algorithms and Complexity

NP-complete problems. CSE 101: Design and Analysis of Algorithms Lecture 20

8. INTRACTABILITY I. Lecture slides by Kevin Wayne Copyright 2005 Pearson-Addison Wesley. Last updated on 2/6/18 2:16 AM

Automata Theory CS Complexity Theory I: Polynomial Time

Lecturer: Shuchi Chawla Topic: Inapproximability Date: 4/27/2007

NP-Completeness I. Lecture Overview Introduction: Reduction and Expressiveness

Lecture 29: NP-Hard Problems [Fa 10]

More on NP and Reductions

4/22/12. NP and NP completeness. Efficient Certification. Decision Problems. Definition of P

NP-problems continued

Computational Complexity

Transcription:

Today s Outline CS 362, Lecture 23 Jared Saia University of New Mexico Review NP-Hardness and three more reductions 1 Classes of Problems NP-Hard We can characterize many problems into three classes: P is the set of yes/no problems that can be solved in polynomial time. Intuitively P is the set of problems that can be solved quickly NP is the set of yes/no problems with the following property: If the answer is yes, then there is a proof of this fact that can be checked in polynomial time co-np is the set of yes/no problems with the following property: If the answer is no, then there is a proof of this fact that can be checked in polynomial time A problem Π is NP-hard if a polynomial-time algorithm for Π would imply a polynomial-time algorithm for every problem in NP In other words: Π is NP-hard iff If Π can be solved in polynomial time, then P=NP In other words: if we can solve one particular NP-hard problem quickly, then we can quickly solve any problem whose solution is quick to check (using the solution to that one special problem as a subroutine) If you tell your boss that a problem is NP-hard, it s like saying: Not only can t I find an efficient solution to this problem but neither can all these other very famous people. (you could then seek to find an approximation algorithm for your problem) 2 3

NP-Complete NP-Hard A problem Π is NP-hard if a polynomial-time algorithm for Π would imply a polynomial-time algorithm for every problem A problem in NP is NP-Easy if it is in NP A problem In otheriswords: NP-Complete Π is NP-hard if it is NP-Hard iff If Π and cannp-easy be solved in In other polynomial words, time, a problem thenisp=np NP-Complete if it is in NP but is atinleast otheraswords: hard as if we all other can solve problems one particular in NP. NP-hard problem quickly, finds athen polynomial-time we can quickly algorithm solve any for even problem one NP- whose If anyone complete solution problem, is quickthen to check that would (usingimply the solution a polynomial-time to that one algorithm specialfor problem every as NP-Complete a subroutine) problem Thousands If you tell ofyour problems boss that havea been problem shown is NP-hard, to be NP-Complete, it s like saying: so a Not polynomial-time only can t I find algorithm an efficient for one solution (i.e. all) to of thisthem problem is incredibly but neither unlikely can all these other very famous people. (you could then seek to find an approximation algorithm for your problem) NP hard co NP NP NP complete P AAdetailed more detailed picture picture of what ofwe what think we the think world the world looks looks like. like. 417 195 Independent Set Vertex Cover Independent Set is the following problem: Does there exist a set of k vertices in a graph G with no edges between them? In the hw, you ll show that independent set is NP-Hard by a reduction from CLIQUE Thus we can now use Independent Set to show that other problems are NP-Hard A vertex cover of a graph is a set of vertices that touches every edge in the graph The problem Vertex Cover is: Does there exist a vertex cover of size k in a graph G? We can prove this problem is NP-Hard by an easy reduction from Independent Set 6 7

Key Observation Key Observation: If I is an independent set in a graph G = (V, E), then V I is a vertex cover. Thus, there is an independent set of size k iff there is a vertex cover of size V k. For the reduction, we want to show that a polynomial time algorithm for Vertex Cover can give a polynomial time algorithm for Independent Set We are given a graph G = (V, E) and a value k and we must determine if there is an independent set of size k in G. To do this, we ask if there is a vertex cover of size V k in G. If so then we return that there is an independent set of size k in G If not, we return that there is not an independent set of size k in G 8 9 Graph Coloring graph G = (V, E), k trivial graph G = (V, E), V k VertexCover True or False O(1) True or False A c-coloring of a graph G is a map C : V {1, 2,..., c} that assigns one of c colors to each vertex so that every edge has two different colors at its endpoints The graph coloring problem is: Does there exist a c-coloring for the graph G? Even when c = 3, this problem is hard. We call this problem 3Colorable i.e. Does there exist a 3-coloring for the graph G? 10 11

3Colorable Reduction To show that 3Colorable is NP-hard, we will reduce from 3Sat 3Colorable This means that we want to show that a polynomial time algorithm for 3Colorable can give a polynomial time algorithm for 3Sat To show that 3Colorable is NP-hard, we will reduce from Recall that the 3-SAT problem is just: Is there any assignment of variables to a 3CNF formula that makes the formula 3Sat This means that we want to show that a polynomial time algorithm for 3Colorable can give a polynomial time algorithm evaluate to true? And a 3CNF formula 3Sat is just a conjunct of a bunch of clauses, each of which Recall contains that the exactly 3-SAT3 problem variables is just: e.g. Is there any assignment of variables to a 3CNF formula that makes the formula clause {}} evaluate { to true? (a b And c) a 3CNF (b c formula d) is (ājust ca conjunct d) (a of b a bunch d) of clauses, each of which contains exactly 3 variables e.g. clause {}}{ (a b c) (b c d) (ā c d) (a b d) 12 The Truth Gadget We are given a 3-CNF formula, F, and we must determine if it has a satisfying assignment To Thedotruth this, gadget we produce is just a triangle a graphwith as three follows vertices T, F The and X, graph whichcontains intuitivelyone standtruth for True, gadget, False, one and variable other gadget for Since each these variable vertices are in the all connected, formula, they andmust onehave clause different colors in any 3-coloring gadget for each clause in the formula For the sake of convenience, we will name those colors True, False, and Other Thus when we say a node is colored True, we just mean that it s colored the same color as the node T T X F 13 The Truth Gadget 12 The Variable Gadgets 14 Reduction The Truth Gadget The Variable Gadgets The truth gadget is just a triangle with three vertices T, F and X, which intuitively stand for True, False, and other Since The truth these gadget vertices is just area triangle all connected, with three vertices they must T, F have different colors in any We are 3-coloring given a 3-CNF formula, F, and we must determine and X, which intuitively stand for True, False, and other Since these vertices are all connected, they must have different colors in any 3-coloring will name those colors True, For the sake of if it convenience, has a satisfying weassignment False, and Other To do this, we produce a graph as follows For the sake of convenience, we will name those colors True, Thus False, and when Other The graph contains one truth gadget, one variable gadget we say a node is colored True, we just mean Thus when we say for aeach nodevariable is colored in True, the formula, we just and mean one clause gadget for that it s colored eachthe clause same in the color formula as the node T that it s colored the same color as the node T T X F The variable gadget for a variable a is also a triangle joining two Thenew variable nodes gadget labeled for a variable a and ato is also node a triangle X in the joining truth gadget Node two newa nodes mustlabeled colored a and aeither to node True X in the truth or False, gadget and so Node a must be colored either True or False, and so node must be colored either False or True, respectively. node a must be colored either False or True, respectively. X a a gadget ensures that each of the literals is colored The variable gadget ensures that each of the literals is colored either True or False either True or False 14 13 15 14 15

The Clause Gadgets The Clause Gadgets Consider the formula (a b c) (b c d) (ā c d) (a b d). Consider the formula (a b c) (b c d) (ā c d) (a b d). Following is the graph created by the reduction: Following is the graph created by the reduction: Each clause gadget joins three literal nodes to node T in the truth Each clause gadget gadget using joins five three newliteral unlabelled nodes tonodes T and in theten edges (as truthingadget the figure) using five new unlabelled nodes and ten edges (as in the figure) This clause gadget ensures that at least one of the three This clause gadget ensures that at least one of the three literal nodes in each clause is colored True literal nodes in each clause is colored True a b T c Note that the 3-coloring of thisaexample graph bcorresponds c to a satisfying assignment of the formula Namely, a = c = True, b = d = False. Note that the final graph contains only one node T, only one node F, only one node ā for each variable a and so on T a b c d X F d 16 16 18 17 17 Consider the formula (a b c) (b c d) (ā c d) (a b d). Following is the graph created by the reduction: Correctness Correctness T F a a b b c c d X Note that the 3-coloring of this example graph corresponds to a satisfying assignment of the formula Namely, a = c = True, b = d = False. Note that the final graph contains only one node T, only one node F, only one node ā for each variable a and so on d The proof of correctness for this reduction is direct If the graph is 3-colorable, then we can extract a satisfying assignment from any 3-coloring, since at least one of the three literal nodes in every clause gadget is colored True The proof of correctness for this reduction is direct Conversely, if the formula is satisfiable, then we can color If the graph is 3-colorable, then we can extract a satisfying the graph according to any satisfying assignment assignment from any 3-coloring, since at least one of the three literal nodes in every clause gadget is colored True Conversely, if the formula is satisfiable, then we can color the graph according to any satisfying assignment 17 19 18 19

Reduction Picture Wrap Up 3CNF formula O(n) graph 3Colorable True or False trivial True or False We ve just shown that if 3Colorable can be solved in polynomial time then 3-SAT can be solved in polynomial time This shows that 3Colorable is NP-Hard To show that 3Colorable is in NP, we just need to note that we can easily verify that a graph has been correctly 3-colored in linear time: just compare the endpoints of every edge Thus, 3Coloring is NP-Complete. This implies that the more general graph coloring problem is also NP-Complete 20 21 In-Class Exercise Hamiltonian Cycle Consider the problem 4Colorable: Does there exist a 4-coloring for a graph G? Q1: Show this problem is in NP by showing that there exists an efficiently verifiable proof of the fact that a graph is 4 colorable. Q2: Show the problem is NP-Hard by a reduction from the problem 3Colorable. In particular, show the following: Given a graph G, you can create a graph G such that G is 4-colorable iff G is 3-colorable. Creating G from G takes polynomial time A Hamiltonian Cycle in a graph is a cycle that visits every vertex exactly once (note that this is very different from an Eulerian cycle which visits every edge exactly once) The Hamiltonian Cycle problem is to determine if a given graph G has a Hamiltonian Cycle We will show that this problem is NP-Hard by a reduction from the vertex cover problem. Note: You ve now shown that 4Colorable is NP-Complete! 22 23

Edge Gadget and Cover Vertices Edge Edge Gadget Gadget and and Cover Cover Vertices Vertices To do the reduction, we need to show that we can solve Vertex Cover in polynomial time if we have a polynomial time solution to Hamiltonian Cycle. Given a graph G and an integer k, we will create another graph G such that G has a Hamiltonian cycle iff G has a vertex cover of size k As for the last reduction, our transformation will consist of putting together several gadgets For each edge (u, v) in G, we have an edge gadget in For Foreach eachedge edge (u, (u, v) v) in in G, G, we have an an edge edge gadget gadgetining G G consisting of twelve vertices and fourteen edges, as shown consistingof of twelve vertices and fourteen edges, as asshown shown below below below (u,v,1) (u,v,2) (u,v,3) (u,v,4) (u,v,5) (u,v,6) (u,v,1) (u,v,2) (u,v,3) (u,v,4) (u,v,5) (u,v,6) (v,u,1) (v,u,1) (v,u,2) (v,u,2) (v,u,3) (v,u,3) (v,u,4) (v,u,4) (v,u,5) (v,u,5) (v,u,6) An edge gadget for (u, v) and the only possible Hamiltonian paths An An edge gadget for (u, v) and the only possible Hamiltonian paths through it. throughit. it. 24 25 25 25 Edge Gadget Cover Vertices The four corner vertices (u, v, 1), (u, v, 6), (v, u, 1), and (v, u, 6) each have an edge leaving the gadget A Hamiltonian cycle can only pass through an edge gadget in one of the three ways shown in the figure These paths through the edge gadget will correspond to one or both of the vertices u and v being in the vertex cover. G also contains k cover vertices, simply numbered 1 through k 26 27

Vertex Chains Vertex Chains For each vertex u in G, we string together all the edge gadgets for edges (u, v) into a single vertex chain and then connect the For endseach of the vertex chain u intog, all wethe string cover together vertices all the edge gadgetssuppose for edges u (u, hasv) dinto neighbors a singlevvertex 1, v 2,.. chain., v d. and Then then G con- Specifically, has the following nect the ends edges: of the chain to all the cover vertices d 1 Specifically, edges between suppose (u, uv i has, 6) dand neighbors (u, v i+1 v 1,, v1) 2,..(for., v d. all Then i G between has1the andfollowing d 1) edges: k edges between d 1 edges the between cover vertices (u, v i, 6) and and (u, (u, v v 1, i+1 1), 1) (for all i k edges between 1the andcover d 1) vertices and (u, v d, 6) k edges between the cover vertices and (u, v 1, 1) k edges between the cover vertices and (u, v d, 6) It s not hard to prove that if {v 1, v 2,..., v k } is a vertex cover of G, then G has a Hamiltonian cycle To get this Hamiltonian cycle, we start at cover vertex 1, traverse through the vertex chain for v 1, then visit cover vertex 2, then traverse the vertex chain for v 2 and so forth, until we eventually return to cover vertex 1 Conversely, The transformation one can from proveg that to G any takeshamiltonian at most O( V cycle 2 ) time, in G alternates so the Hamiltonian between cover cyclevertices problem and is NP-Hard vertex chains, and that the Moreover vertex chains we can correspond easily verify to a Hamiltonian the k vertices cycleinin alinear vertex cover time, ofthus G Hamiltonian cycle is also in NP Thus Hamiltonian Cycle is NP-Complete Thus, G has a vertex cover of size k iff G has a Hamiltonian cycle 28 28 30 29 It s not hard to prove that if {v 1, v 2,..., v k } is a vertex cover of G, then G has a Hamiltonian cycle To get this Hamiltonian cycle, we start at cover vertex 1, traverse through the vertex The transformation from G to G chain for v 1, then takes at most O( V 2 visit cover vertex 2, then traverse the vertex chain for v 2 and ) time, so forth, so the Hamiltonian until we eventually cycle problem return tois cover NP-Hard vertex 1 Moreover Conversely, we can easily one can verify prove a Hamiltonian that any Hamiltonian cycle in cycle linearin G time, thus alternates Hamiltonian between cycle cover is also vertices in NP and vertex chains, and that Thus Hamiltonian the vertexcycle chainsiscorrespond NP-Complete to the k vertices in a vertex cover of G u w v x 1 (u,w) (w,u) (u,v) (v,u) (v,w) (w,v) (w,x) (x,w) (v,x) (x,v) 2 Thus, G has a vertex cover of size k iff G has a Hamiltonian cycle The The original original graph graphg Gwith withvertex cover {v, w}, andthe the transformed graph graph G G with witha acorresponding Hamiltonian cycle cycle (bold (boldedges). edges). Vertex chains are colored to match their corresponding vertices. Vertex chains are colored to match their corresponding vertices. 30 29 31 31

Traveling Sales Person graph G = (V, E), k O( V 2 ) graph G Hamiltonian Cycle True or False O(1) True or False A problem closely related to Hamiltonian cycles is the famous Traveling Salesperson Problem(TSP) The TSP problem is: Given a weighted graph G, find the shortest cycle that visits every vertex. Finding the shortest cycle is obviously harder than determining if a cycle exists at all, so since Hamiltonian Path is NP-hard, TSP is also NP-hard! 32 33 NP-Hard Games Challenge Problem In 1999, Richard Kaye proved that the solitaire game Minesweeper is NP-Hard, using a reduction from Circuit Satifiability. Also in the last few years, Eric Demaine, et. al., proved that the game Tetris is NP-Hard Consider the optimization version of, say, the graph coloring problem: Given a graph G, what is the smallest number of colors needed to color the graph? (Note that unlike the decision version of this problem, this is not a yes/no question) Show that the optimization version of graph coloring is also NP-Hard by a reduction from the decision version of graph coloring. Is the optimization version of graph coloring also NP-Complete? 34 35

Challenge Problem Challenge Problem Consider the problem 4Sat which is: Is there any assignment of variables to a 4CNF formula that makes the formula evaluate to true? Is this problem NP-Hard? If so, give a reduction from 3Sat that shows this. If not, give a polynomial time algorithm which solves it. Consider the following problem: Does there exist a clique of size 5 in some input graph G? Is this problem NP-Hard? If so, prove it by giving a reduction from some known NP-Hard problem. If not, give a polynomial time algorithm which solves it. 36 37