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

Similar documents
NP and NP Completeness

SAT, NP, NP-Completeness

More NP-Complete Problems

Chapter 2. Reductions and NP. 2.1 Reductions Continued The Satisfiability Problem (SAT) SAT 3SAT. CS 573: Algorithms, Fall 2013 August 29, 2013

SAT, Coloring, Hamiltonian Cycle, TSP

NP-Complete Problems. More reductions

BBM402-Lecture 11: The Class NP

NP and Computational Intractability

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

Essential facts about NP-completeness:

1. Introduction Recap

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

Design and Analysis of Algorithms

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

NP-Complete Reductions 1

Polynomial-Time Reductions

NP-Hardness reductions

NP and Computational Intractability

COP 4531 Complexity & Analysis of Data Structures & Algorithms

Computational Intractability 2010/4/15. Lecture 2

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

Correctness of Dijkstra s algorithm

Chapter 34: NP-Completeness

Automata Theory CS Complexity Theory I: Polynomial Time

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

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

Intro to Theory of Computation

Announcements. Friday Four Square! Problem Set 8 due right now. Problem Set 9 out, due next Friday at 2:15PM. Did you lose a phone in my office?

CS 583: Algorithms. NP Completeness Ch 34. Intractability

NP-Complete Problems. Complexity Class P. .. Cal Poly CSC 349: Design and Analyis of Algorithms Alexander Dekhtyar..

CS21 Decidability and Tractability

NP Completeness and Approximation Algorithms

More on NP and Reductions

COMP 382. Unit 10: NP-Completeness

Introduction. Pvs.NPExample

Introduction to Computational Complexity

Theory of Computation Time Complexity

CS154, Lecture 15: Cook-Levin Theorem SAT, 3SAT

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

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

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

Geometric Steiner Trees

NP-Completeness. Until now we have been designing algorithms for specific problems

NP-Completeness. Subhash Suri. May 15, 2018

Polynomial-time reductions. We have seen several reductions:

1.1 P, NP, and NP-complete

Theory of Computation Chapter 9

1 Primals and Duals: Zero Sum Games

CSE 421 NP-Completeness

Algorithm Design and Analysis

Lecture 4: NP and computational intractability

CS 5114: Theory of Algorithms. Tractable Problems. Tractable Problems (cont) Decision Problems. Clifford A. Shaffer. Spring 2014

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

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

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

Limitations of Algorithm Power

NP-Completeness Review

CSCI3390-Second Test with Solutions

NP and NP-Completeness

Lecture 18: More NP-Complete Problems

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

P, NP, NP-Complete, and NPhard

Instructor N.Sadagopan Scribe: P.Renjith. Lecture- Complexity Class- P and NP

NP Complete Problems. COMP 215 Lecture 20

P = k T IME(n k ) Now, do all decidable languages belong to P? Let s consider a couple of languages:

COMP Analysis of Algorithms & Data Structures

CS154, Lecture 13: P vs NP

Complexity, P and NP

CSC 373: Algorithm Design and Analysis Lecture 15

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

CSE 135: Introduction to Theory of Computation NP-completeness

CSE 3500 Algorithms and Complexity Fall 2016 Lecture 25: November 29, 2016

NP-complete Problems

Spring Lecture 21 NP-Complete Problems

Lecture 24 : Even more reductions

CS21 Decidability and Tractability

Lecture 15 - NP Completeness 1

Polynomial-time Reductions

6.045: Automata, Computability, and Complexity (GITCS) Class 15 Nancy Lynch

NP-Completeness Part II

Algorithms Design & Analysis. Approximation Algorithm

CMSC 441: Algorithms. NP Completeness

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

P is the class of problems for which there are algorithms that solve the problem in time O(n k ) for some constant k.

Week 3: Reductions and Completeness

Lecture 18: P & NP. Revised, May 1, CLRS, pp

CSCI 1590 Intro to Computational Complexity

Show that the following problems are NP-complete

1 Computational problems

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

6.080 / Great Ideas in Theoretical Computer Science Spring 2008

NP-Complete problems

ENEE 459E/CMSC 498R In-class exercise February 10, 2015

Undecidable Problems. Z. Sawa (TU Ostrava) Introd. to Theoretical Computer Science May 12, / 65

CSI 4105 MIDTERM SOLUTION

Admin NP-COMPLETE PROBLEMS. Run-time analysis. Tractable vs. intractable problems 5/2/13. What is a tractable problem?

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

CISC 4090 Theory of Computation

CHAPTER 3 FUNDAMENTALS OF COMPUTATIONAL COMPLEXITY. E. Amaldi Foundations of Operations Research Politecnico di Milano 1

Transcription:

CS 374: Algorithms & Models of Computation, Spring 2015 NP Completeness Lecture 23 November 19, 2015 Chandra & Lenny (UIUC) CS374 1 Spring 2015 1 / 37

Part I NP-Completeness Chandra & Lenny (UIUC) CS374 2 Spring 2015 2 / 37

P and NP and Turing Machines 1 P: set of decision problems that have polynomial time algorithms. 2 NP: set of decision problems that have polynomial time verification algorithms. Many natural problems we would like to solve are in NP. Every problem in NP has an exponential time algorithm (try verifying each possible certificate). P NP So some problems in NP are in P (example, shortest path problem) Big Question: Does every problem in NP have an efficient algorithm? Same as asking whether P = NP. Chandra & Lenny (UIUC) CS374 3 Spring 2015 3 / 37

Hardest Problems Question What is the hardest problem in NP? How do we define it? Towards a definition 1 Hardest problem must be in NP. 2 Hardest problem must be at least as difficult as every other problem in NP. Chandra & Lenny (UIUC) CS374 4 Spring 2015 4 / 37

NP-Complete Problems Definition A problem X is said to be NP-Complete if 1 X NP, and 2 (Hardness) For any Y NP, Y P X. Chandra & Lenny (UIUC) CS374 5 Spring 2015 5 / 37

NP-Complete Problems Definition A problem X is said to be NP-Complete if 1 X NP, and 2 (Hardness) For any Y NP, Y P X. Recall reduction: Y P X means that an instance of Y can be efficiently modeled as an instance of X. Chandra & Lenny (UIUC) CS374 5 Spring 2015 5 / 37

Solving NP-Complete Problems Proposition Suppose X is NP-Complete. Then X can be solved in polynomial time if and only if P = NP. Proof. Suppose X can be solved in polynomial time 1 Let Y NP. We know Y P X. 2 We showed that if Y P X and X can be solved in polynomial time, then Y can be solved in polynomial time. 3 Thus, every problem Y NP is such that Y P; NP P. 4 Since P NP, we have P = NP. Since P = NP, and X NP, we have a polynomial time algorithm for X. Chandra & Lenny (UIUC) CS374 6 Spring 2015 6 / 37

NP-Hard Problems Definition A problem X is said to be NP-Hard if 1 (Hardness) For any Y NP, we have that Y P X. An NP-Hard problem need not be in NP! Example: Halting problem is NP-Hard (why?) but not NP-Complete. Chandra & Lenny (UIUC) CS374 7 Spring 2015 7 / 37

Consequences of proving NP-Completeness If X is NP-Complete 1 Since we believe P NP, 2 and solving X implies P = NP. Chandra & Lenny (UIUC) CS374 8 Spring 2015 8 / 37

Consequences of proving NP-Completeness If X is NP-Complete 1 Since we believe P NP, 2 and solving X implies P = NP. X is unlikely to be efficiently solvable. Chandra & Lenny (UIUC) CS374 8 Spring 2015 8 / 37

Consequences of proving NP-Completeness If X is NP-Complete 1 Since we believe P NP, 2 and solving X implies P = NP. X is unlikely to be efficiently solvable. At the very least, many smart people before you have failed to find an efficient algorithm for X. Chandra & Lenny (UIUC) CS374 8 Spring 2015 8 / 37

Consequences of proving NP-Completeness If X is NP-Complete 1 Since we believe P NP, 2 and solving X implies P = NP. X is unlikely to be efficiently solvable. At the very least, many smart people before you have failed to find an efficient algorithm for X. (This is proof by mob opinion take with a grain of salt.) Chandra & Lenny (UIUC) CS374 8 Spring 2015 8 / 37

NP-Complete Problems Question Are there any natural problems that are NP-Complete? Answer Yes! Many, many important problems are NP-Complete. Chandra & Lenny (UIUC) CS374 9 Spring 2015 9 / 37

Cook-Levin Theorem Theorem (Cook-Levin) SAT is NP-Complete. Chandra & Lenny (UIUC) CS374 10 Spring 2015 10 / 37

Cook-Levin Theorem Theorem (Cook-Levin) SAT is NP-Complete. Need to show 1 SAT is in NP. 2 every NP problem X reduces to SAT. Will see proof in next lecture. Steve Cook won the Turing award for his theorem. Chandra & Lenny (UIUC) CS374 10 Spring 2015 10 / 37

Proving that a problem X is NP-Complete To prove X is NP-Complete, show 1 Show that X is in NP. 2 Give a polynomial-time reduction from a known NP-Complete problem such as SAT to X Chandra & Lenny (UIUC) CS374 11 Spring 2015 11 / 37

Proving that a problem X is NP-Complete To prove X is NP-Complete, show 1 Show that X is in NP. 2 Give a polynomial-time reduction from a known NP-Complete problem such as SAT to X SAT P X implies that every NP problem Y P X. Why? Chandra & Lenny (UIUC) CS374 11 Spring 2015 11 / 37

Proving that a problem X is NP-Complete To prove X is NP-Complete, show 1 Show that X is in NP. 2 Give a polynomial-time reduction from a known NP-Complete problem such as SAT to X SAT P X implies that every NP problem Y P X. Why? Transitivity of reductions: Y P SAT and SAT P X and hence Y P X. Chandra & Lenny (UIUC) CS374 11 Spring 2015 11 / 37

3-SAT is NP-Complete 3-SAT is in NP SAT P 3-SAT as we saw Chandra & Lenny (UIUC) CS374 12 Spring 2015 12 / 37

NP-Completeness via Reductions 1 SAT is NP-Complete due to Cook-Levin theorem 2 SAT P 3-SAT 3 3-SAT P Independent Set 4 Independent Set P Vertex Cover 5 Independent Set P Clique 6 3-SAT P 3-Color 7 3-SAT P Hamiltonian Cycle Chandra & Lenny (UIUC) CS374 13 Spring 2015 13 / 37

NP-Completeness via Reductions 1 SAT is NP-Complete due to Cook-Levin theorem 2 SAT P 3-SAT 3 3-SAT P Independent Set 4 Independent Set P Vertex Cover 5 Independent Set P Clique 6 3-SAT P 3-Color 7 3-SAT P Hamiltonian Cycle Hundreds and thousands of different problems from many areas of science and engineering have been shown to be NP-Complete. A surprisingly frequent phenomenon! Chandra & Lenny (UIUC) CS374 13 Spring 2015 13 / 37

NP-Completeness via Reductions Chandra & Lenny (UIUC) CS374 14 Spring 2015 14 / 37

Part II Reducing 3-SAT to Independent Set Chandra & Lenny (UIUC) CS374 15 Spring 2015 15 / 37

Independent Set Problem: Independent Set Instance: A graph G, integer k. Question: Is there an independent set in G of size k? Chandra & Lenny (UIUC) CS374 16 Spring 2015 16 / 37

3SAT P Independent Set The reduction 3SAT P Independent Set Input: Given a 3CNF formula ϕ Goal: Construct a graph G ϕ and number k such that G ϕ has an independent set of size k if and only if ϕ is satisfiable. Chandra & Lenny (UIUC) CS374 17 Spring 2015 17 / 37

3SAT P Independent Set The reduction 3SAT P Independent Set Input: Given a 3CNF formula ϕ Goal: Construct a graph G ϕ and number k such that G ϕ has an independent set of size k if and only if ϕ is satisfiable. G ϕ should be constructable in time polynomial in size of ϕ Chandra & Lenny (UIUC) CS374 17 Spring 2015 17 / 37

3SAT P Independent Set The reduction 3SAT P Independent Set Input: Given a 3CNF formula ϕ Goal: Construct a graph G ϕ and number k such that G ϕ has an independent set of size k if and only if ϕ is satisfiable. G ϕ should be constructable in time polynomial in size of ϕ Importance of reduction: Although 3SAT is much more expressive, it can be reduced to a seemingly specialized Independent Set problem. Notice: We handle only 3CNF formulas reduction would not work for other kinds of boolean formulas. Chandra & Lenny (UIUC) CS374 17 Spring 2015 17 / 37

Interpreting 3SAT There are two ways to think about 3SAT Chandra & Lenny (UIUC) CS374 18 Spring 2015 18 / 37

Interpreting 3SAT There are two ways to think about 3SAT 1 Find a way to assign 0/1 (false/true) to the variables such that the formula evaluates to true, that is each clause evaluates to true. Chandra & Lenny (UIUC) CS374 18 Spring 2015 18 / 37

Interpreting 3SAT There are two ways to think about 3SAT 1 Find a way to assign 0/1 (false/true) to the variables such that the formula evaluates to true, that is each clause evaluates to true. 2 Pick a literal from each clause and find a truth assignment to make all of them true Chandra & Lenny (UIUC) CS374 18 Spring 2015 18 / 37

Interpreting 3SAT There are two ways to think about 3SAT 1 Find a way to assign 0/1 (false/true) to the variables such that the formula evaluates to true, that is each clause evaluates to true. 2 Pick a literal from each clause and find a truth assignment to make all of them true. You will fail if two of the literals you pick are in conflict, i.e., you pick x i and x i We will take the second view of 3SAT to construct the reduction. Chandra & Lenny (UIUC) CS374 18 Spring 2015 18 / 37

The Reduction 1 G ϕ will have one vertex for each literal in a clause x 1 x 2 x 1 x 3 x 2 x 1 x 3 x 2 x 4 Figure: Graph for ϕ = ( x 1 x 2 x 3 ) (x 1 x 2 x 3 ) ( x 1 x 2 x 4 ) Chandra & Lenny (UIUC) CS374 19 Spring 2015 19 / 37

The Reduction 1 G ϕ will have one vertex for each literal in a clause 2 Connect the 3 literals in a clause to form a triangle; the independent set will pick at most one vertex from each clause, which will correspond to the literal to be set to true x 1 x 2 x 1 x 3 x 2 x 1 x 3 x 2 x 4 Figure: Graph for ϕ = ( x 1 x 2 x 3 ) (x 1 x 2 x 3 ) ( x 1 x 2 x 4 ) Chandra & Lenny (UIUC) CS374 19 Spring 2015 19 / 37

The Reduction 1 G ϕ will have one vertex for each literal in a clause 2 Connect the 3 literals in a clause to form a triangle; the independent set will pick at most one vertex from each clause, which will correspond to the literal to be set to true x 1 x 2 x 1 x 3 x 2 x 1 x 3 x 2 x 4 Figure: Graph for ϕ = ( x 1 x 2 x 3 ) (x 1 x 2 x 3 ) ( x 1 x 2 x 4 ) Chandra & Lenny (UIUC) CS374 19 Spring 2015 19 / 37

The Reduction 1 G ϕ will have one vertex for each literal in a clause 2 Connect the 3 literals in a clause to form a triangle; the independent set will pick at most one vertex from each clause, which will correspond to the literal to be set to true 3 Connect 2 vertices if they label complementary literals; this ensures that the literals corresponding to the independent set do not have a conflict x 1 x 2 x 1 x 3 x 2 x 1 x 3 x 2 x 4 Figure: Graph for ϕ = ( x 1 x 2 x 3 ) (x 1 x 2 x 3 ) ( x 1 x 2 x 4 ) Chandra & Lenny (UIUC) CS374 19 Spring 2015 19 / 37

The Reduction 1 G ϕ will have one vertex for each literal in a clause 2 Connect the 3 literals in a clause to form a triangle; the independent set will pick at most one vertex from each clause, which will correspond to the literal to be set to true 3 Connect 2 vertices if they label complementary literals; this ensures that the literals corresponding to the independent set do not have a conflict 4 Take k to be the number of clauses x 1 x 2 x 1 x 3 x 2 x 1 x 3 x 2 x 4 Figure: Graph for ϕ = ( x 1 x 2 x 3 ) (x 1 x 2 x 3 ) ( x 1 x 2 x 4 ) Chandra & Lenny (UIUC) CS374 19 Spring 2015 19 / 37

Correctness Proposition ϕ is satisfiable iff G ϕ has an independent set of size k (= number of clauses in ϕ). Proof. Let a be the truth assignment satisfying ϕ Chandra & Lenny (UIUC) CS374 20 Spring 2015 20 / 37

Correctness Proposition ϕ is satisfiable iff G ϕ has an independent set of size k (= number of clauses in ϕ). Proof. Let a be the truth assignment satisfying ϕ 1 Pick one of the vertices, corresponding to true literals under a, from each triangle. This is an independent set of the appropriate size. Why? Chandra & Lenny (UIUC) CS374 20 Spring 2015 20 / 37

Correctness (contd) Proposition ϕ is satisfiable iff G ϕ has an independent set of size k (= number of clauses in ϕ). Proof. Let S be an independent set of size k 1 S must contain exactly one vertex from each clause 2 S cannot contain vertices labeled by conflicting literals 3 Thus, it is possible to obtain a truth assignment that makes in the literals in S true; such an assignment satisfies one literal in every clause Chandra & Lenny (UIUC) CS374 21 Spring 2015 21 / 37

Part III NP-Completeness of Hamiltonian Cycle Chandra & Lenny (UIUC) CS374 22 Spring 2015 22 / 37

Directed Hamiltonian Cycle Input Given a directed graph G = (V, E) with n vertices Goal Does G have a Hamiltonian cycle? Chandra & Lenny (UIUC) CS374 23 Spring 2015 23 / 37

Directed Hamiltonian Cycle Input Given a directed graph G = (V, E) with n vertices Goal Does G have a Hamiltonian cycle? A Hamiltonian cycle is a cycle in the graph that visits every vertex in G exactly once Chandra & Lenny (UIUC) CS374 23 Spring 2015 23 / 37

Is the following graph Hamiltonian? (A) Yes. (B) No. Chandra & Lenny (UIUC) CS374 24 Spring 2015 24 / 37

Directed Hamiltonian Cycle is NP-Complete Directed Hamiltonian Cycle is in NP: Why? Hardness: We will show 3-SAT P Directed Hamiltonian Cycle Chandra & Lenny (UIUC) CS374 25 Spring 2015 25 / 37

Reduction Given 3-SAT formula ϕ create a graph G ϕ such that G ϕ has a Hamiltonian cycle if and only if ϕ is satisfiable G ϕ should be constructible from ϕ by a polynomial time algorithm A Notation: ϕ has n variables x 1, x 2,..., x n and m clauses C 1, C 2,..., C m. Chandra & Lenny (UIUC) CS374 26 Spring 2015 26 / 37

Reduction: First Ideas Viewing SAT: Assign values to n variables, and each clause has multiple ways in which it can be satisfied. Construct graph with 2 n Hamiltonian cycles, where each cycle corresponds to some boolean assignment. Then add more graph structure to encode constraints on assignments imposed by the clauses. Chandra & Lenny (UIUC) CS374 27 Spring 2015 27 / 37

The Reduction: Phase I Traverse path i from left to right iff x i is set to true Each path has 3(m + 1) nodes where m is number of clauses in ϕ; nodes numbered from left to right (1 to 3m + 3) x 1 x 2 x 3 x 4 Chandra & Lenny (UIUC) CS374 28 Spring 2015 28 / 37

The Reduction: Phase II Add vertex c j for clause C j. c j has edge from vertex 3j and to vertex 3j + 1 on path i if x i appears in clause C j, and has edge from vertex 3j + 1 and to vertex 3j if x i appears in C j. x 1 x 2 x 4 x 1 x 2 x 3 x 1 x 2 x 3 x 4 Chandra & Lenny (UIUC) CS374 29 Spring 2015 29 / 37

The Reduction: Phase II Add vertex c j for clause C j. c j has edge from vertex 3j and to vertex 3j + 1 on path i if x i appears in clause C j, and has edge from vertex 3j + 1 and to vertex 3j if x i appears in C j. x 1 x 2 x 4 x 1 x 2 x 3 x 1 x 2 x 3 x 4 Chandra & Lenny (UIUC) CS374 29 Spring 2015 29 / 37

The Reduction: Phase II Add vertex c j for clause C j. c j has edge from vertex 3j and to vertex 3j + 1 on path i if x i appears in clause C j, and has edge from vertex 3j + 1 and to vertex 3j if x i appears in C j. x 1 x 2 x 4 Buffer vertices x 1 x 2 x 3 x 1 x 2 x 3 x 4 Chandra & Lenny (UIUC) CS374 29 Spring 2015 29 / 37

The Reduction: Phase II Add vertex c j for clause C j. c j has edge from vertex 3j and to vertex 3j + 1 on path i if x i appears in clause C j, and has edge from vertex 3j + 1 and to vertex 3j if x i appears in C j. x 1 x 2 x 4 x 1 x 2 x 3 x 1 x 2 x 3 x 4 Chandra & Lenny (UIUC) CS374 29 Spring 2015 29 / 37

The Reduction: Phase II Add vertex c j for clause C j. c j has edge from vertex 3j and to vertex 3j + 1 on path i if x i appears in clause C j, and has edge from vertex 3j + 1 and to vertex 3j if x i appears in C j. x 1 x 2 x 4 x 1 x 2 x 3 x 1 x 2 x 3 x 4 Chandra & Lenny (UIUC) CS374 29 Spring 2015 29 / 37

The Reduction: Phase II Add vertex c j for clause C j. c j has edge from vertex 3j and to vertex 3j + 1 on path i if x i appears in clause C j, and has edge from vertex 3j + 1 and to vertex 3j if x i appears in C j. x 1 x 2 x 4 x 1 x 2 x 3 x 1 x 2 x 3 x 4 Chandra & Lenny (UIUC) CS374 29 Spring 2015 29 / 37

The Reduction: Phase II Add vertex c j for clause C j. c j has edge from vertex 3j and to vertex 3j + 1 on path i if x i appears in clause C j, and has edge from vertex 3j + 1 and to vertex 3j if x i appears in C j. x 1 x 2 x 4 x 1 x 2 x 3 x 1 x 2 x 3 x 4 Chandra & Lenny (UIUC) CS374 29 Spring 2015 29 / 37

Correctness Proof Proposition ϕ has a satisfying assignment iff G ϕ has a Hamiltonian cycle. Proof. Let a be the satisfying assignment for ϕ. Define Hamiltonian cycle as follows If a(x i ) = 1 then traverse path i from left to right If a(x i ) = 0 then traverse path i from right to left For each clause, path of at least one variable is in the right direction to splice in the node corresponding to clause Chandra & Lenny (UIUC) CS374 30 Spring 2015 30 / 37

Hamiltonian Cycle Satisfying assignment Suppose Π is a Hamiltonian cycle in G ϕ If Π enters c j (vertex for clause C j ) from vertex 3j on path i then it must leave the clause vertex on edge to 3j + 1 on the same path i If not, then only unvisited neighbor of 3j + 1 on path i is 3j + 2 Thus, we don t have two unvisited neighbors (one to enter from, and the other to leave) to have a Hamiltonian Cycle Similarly, if Π enters c j from vertex 3j + 1 on path i then it must leave the clause vertex c j on edge to 3j on path i Chandra & Lenny (UIUC) CS374 31 Spring 2015 31 / 37

Example x 1 x 2 x 3 x 4 Chandra & Lenny (UIUC) CS374 32 Spring 2015 32 / 37

Hamiltonian Cycle = Satisfying assignment (contd) Thus, vertices visited immediately before and after C i are connected by an edge We can remove c j from cycle, and get Hamiltonian cycle in G c j Consider Hamiltonian cycle in G {c 1,... c m }; it traverses each path in only one direction, which determines the truth assignment Chandra & Lenny (UIUC) CS374 33 Spring 2015 33 / 37

Hamiltonian Cycle Problem Input Given undirected graph G = (V, E) Goal Does G have a Hamiltonian cycle? That is, is there a cycle that visits every vertex exactly one (except start and end vertex)? Chandra & Lenny (UIUC) CS374 34 Spring 2015 34 / 37

NP-Completeness Theorem Hamiltonian cycle problem for undirected graphs is NP-Complete. Proof. The problem is in NP; proof left as exercise. Hardness proved by reducing Directed Hamiltonian Cycle to this problem Chandra & Lenny (UIUC) CS374 35 Spring 2015 35 / 37

Reduction Sketch Goal: Given directed graph G, need to construct undirected graph G such that G has Hamiltonian cycle iff G has Hamiltonian cycle Chandra & Lenny (UIUC) CS374 36 Spring 2015 36 / 37

Reduction Sketch Goal: Given directed graph G, need to construct undirected graph G such that G has Hamiltonian cycle iff G has Hamiltonian cycle Reduction Replace each vertex v by 3 vertices: v in, v, and v out a b v c d Chandra & Lenny (UIUC) CS374 36 Spring 2015 36 / 37

Reduction Sketch Goal: Given directed graph G, need to construct undirected graph G such that G has Hamiltonian cycle iff G has Hamiltonian cycle Reduction Replace each vertex v by 3 vertices: v in, v, and v out a b v c d a o v i v v o b o c i d i Chandra & Lenny (UIUC) CS374 36 Spring 2015 36 / 37

Reduction Sketch Goal: Given directed graph G, need to construct undirected graph G such that G has Hamiltonian cycle iff G has Hamiltonian cycle Reduction Replace each vertex v by 3 vertices: v in, v, and v out A directed edge (x, y) is replaced by edge (x out, y in ) a b v c d a o v i v v o b o c i d i Chandra & Lenny (UIUC) CS374 36 Spring 2015 36 / 37

Reduction: Wrapup The reduction is polynomial time (exercise) The reduction is correct (exercise) Chandra & Lenny (UIUC) CS374 37 Spring 2015 37 / 37