SAT, Coloring, Hamiltonian Cycle, TSP

Similar documents
Hamiltonian Cycle. Hamiltonian Cycle

NP and Computational Intractability

Polynomial-Time Reductions

NP-Complete Problems. More reductions

Polynomial-time Reductions

NP and Computational Intractability

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

8.5 Sequencing Problems

NP-complete Problems

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

Computational Intractability 2010/4/15. Lecture 2

COP 4531 Complexity & Analysis of Data Structures & Algorithms

NP Complete Problems. COMP 215 Lecture 20

Intro to Theory of Computation

Algorithm Design and Analysis

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

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

CS 583: Algorithms. NP Completeness Ch 34. Intractability

Algorithms Design & Analysis. Approximation Algorithm

Design and Analysis of Algorithms

Polynomial-time reductions. We have seen several reductions:

Lecture 4: NP and computational intractability

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

NP-Complete Reductions 1

CSL 356: Analysis and Design of Algorithms. Ragesh Jaiswal CSE, IIT Delhi

Lecture 24 : Even more reductions

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

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

Chapter 8. NP and Computational Intractability

1. Introduction Recap

More NP-Complete Problems

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

NP-Completeness Part II

Correctness of Dijkstra s algorithm

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

8.5 Sequencing Problems. Chapter 8. NP and Computational Intractability. Hamiltonian Cycle. Hamiltonian Cycle

Theory of Computation Chapter 9

Algorithm Design and Analysis

Complexity, P and NP

Chapter 8. NP and Computational Intractability. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

Automata Theory CS Complexity Theory I: Polynomial Time

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

CS/COE

Lecture 15 - NP Completeness 1

4/12/2011. Chapter 8. NP and Computational Intractability. Directed Hamiltonian Cycle. Traveling Salesman Problem. Directed Hamiltonian Cycle

Algorithms, Lecture 3 on NP : Nondeterminis7c Polynomial Time

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?

NP-Complete Reductions 2

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

Chapter 34: NP-Completeness

4/20/11. NP-complete problems. A variety of NP-complete problems. Hamiltonian Cycle. Hamiltonian Cycle. 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

NP-Completeness Part II

COMP 382. Unit 10: NP-Completeness

Graduate Algorithms CS F-21 NP & Approximation Algorithms

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

NP Completeness and Approximation Algorithms

CS 6505, Complexity and Algorithms Week 7: NP Completeness

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

Today: NP-Completeness (con t.)

SAT, NP, NP-Completeness

Algorithm Design and Analysis

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

NP and NP-Completeness

7.8 Intractability. Overview. Properties of Algorithms. Exponential Growth. Q. What is an algorithm? A. Definition formalized using Turing machines.

Show that the following problems are NP-complete

8.1 Polynomial-Time Reductions. Chapter 8. NP and Computational Intractability. Classify Problems

Introduction to Complexity Theory

Algorithms: COMP3121/3821/9101/9801

6.080 / Great Ideas in Theoretical Computer Science Spring 2008

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

NP-completeness. Chapter 34. Sergey Bereg

CSC 373: Algorithm Design and Analysis Lecture 15

CS 580: Algorithm Design and Analysis

3/22/2018. CS 580: Algorithm Design and Analysis. Circuit Satisfiability. Recap. The "First" NP-Complete Problem. Example.

CSE 135: Introduction to Theory of Computation NP-completeness

CS21 Decidability and Tractability

NP and NP Completeness

DAA Unit IV Complexity Theory Overview

Limitations of Algorithm Power

Essential facts about NP-completeness:

ECS122A Handout on NP-Completeness March 12, 2018

CS154, Lecture 13: P vs NP

Theory of Computation Time Complexity

NP-Complete Problems

Introduction. Pvs.NPExample

1.1 P, NP, and NP-complete

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

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

CSE 421 NP-Completeness

CS311 Computational Structures. NP-completeness. Lecture 18. Andrew P. Black Andrew Tolmach. Thursday, 2 December 2010

COMP Analysis of Algorithms & Data Structures

Una descrizione della Teoria della Complessità, e più in generale delle classi NP-complete, possono essere trovate in:

NP and NP-Completeness

3130CIT Theory of Computation

NP-Completeness. Subhash Suri. May 15, 2018

July 18, Approximation Algorithms (Travelling Salesman Problem)

Algorithms. NP -Complete Problems. Dong Kyue Kim Hanyang University

Transcription:

1 SAT, Coloring, Hamiltonian Cycle, TSP Slides by Carl Kingsford Apr. 28, 2014 Sects. 8.2, 8.7, 8.5

2 Boolean Formulas Boolean Formulas: Variables: x 1, x 2, x 3 (can be either true or false) Terms: t 1, t 2,..., t l : t j is either x i or x i (meaning either x i or not x i ). Clauses: t 1 t 2 t l ( stands for OR ) A clause is true if any term in it is true. Example 1: (x 1 x 2 ), ( x 1 x 3 ), (x 2 v 3 ) Example 2: (x 1 x 2 x 3 ), ( x 2 x 1 )

Boolean Formulas Def. A truth assignment is a choice of true or false for each variable, ie, a function v : X {true, false}. Def. A CNF formula is a conjunction of clauses: C 1 C 2, C k Example: (x 1 x 2 ) ( x 1 x 3 ) (x 2 v 3 ) Def. A truth assignment is a satisfying assignment for such a formula if it makes every clause true.

4 SAT and 3-SAT Problem (Satisfiability (SAT)). Given a set of clauses C 1,..., C k over variables X = {x 1,..., x n } is there a satisfying assignment? Problem (Satisfiability (3-SAT)). Given a set of clauses C 1,..., C k, each of length 3, over variables X = {x 1,..., x n } is there a satisfying assignment?

5 Cook-Levin Theorem Theorem (Cook-Levin). 3-SAT is NP-complete. Proven in early 1970s by Cook. Slightly different proof by Levin independently. Idea of the proof: encode the workings of a Nondeterministic Turing machine for an instance I of problem X NP as a SAT formula so that the formula is satisfiable if and only if the nondeterministic Turing machine would accept instance I. We won t have time to prove this, but it gives us our first hard problem.

Reducing 3-SAT to Independent Set Thm. 3-SAT P Independent Set Proof. Suppose we have an algorithm to solve Independent Set, how can we use it to solve 3-SAT? To solve 3-SAT: you have to choose a term from each clause to set to true, but you can t set both x i and x i to true. How do we do the reduction?

7 3-SAT P Independent Set (x 1 x 2 x 3 ) (x 2 x 3 x 4 ) (x 1 x 2 x 4 ) x 1 x 2 x 1 x 2 x 3 x 3 x 4 x 2 x 4

8 Proof Theorem. This graph has an independent set of size k iff the formula is satisfiable. Proof. = If the formula is satisfiable, there is at least one true literal in each clause. Let S be a set of one such true literal from each clause. S = k and no two nodes in S are connected by an edge. = If the graph has an independent set S of size k, we know that it has one node from each clause triangle. Set those terms to true. This is possible because no 2 are negations of each other.

9 General Proof Strategy General Strategy for Proving Something is NP-complete: 1. Must show that X NP. Do this by showing there is an certificate that can be efficiently checked. 2. Look at some problems that are known to be NP-complete (there are thousands), and choose one Y that seems similar to your problem in some way. 3. Show that Y P X.

Strategy for Showing Y P X One strategy for showing that Y P X often works: 1. Let I Y be any instance of problem Y. 2. Show how to construct an instance I X of problem X in polynomial time such that: If I Y Y, then I X X If IX X, then I Y Y

Hamiltonian Cycle 11

Hamiltonian Cycle Problem Problem (Hamiltonian Cycle). Given a directed graph G, is there a cycle that visits every vertex exactly once? Such a cycle is called a Hamiltonian cycle.

13 Hamiltonian Cycle is NP-complete Theorem. Hamiltonian Cycle is NP-complete. Proof. First, HamCycle NP. Why? Second, we show 3-SAT P Hamiltonian Cycle. Suppose we have a black box to solve Hamiltonian Cycle, how do we solve 3-SAT? In other words: how do we encode an instance I of 3-SAT as a graph G such that I is satisfiable exactly when G has a Hamiltonian cycle. Consider an instance I of 3-SAT, with variables x 1,..., x n and clauses C 1,..., C k.

14 Reduction Idea Reduction Idea (very high level): Create some graph structure (a gadget ) that represents the variables And some graph structure that represents the clauses Hook them up in some way that encodes the formula Show that this graph has a Ham. cycle iff the formula is satisfiable.

15 Gadget Representing the Variables x i... Direction we travel along this chain represents whether to set the variable to true or false. false true

16 Hooking in the Clauses Add a new node for each clause: C k C j Connect it this way if x i in C k Connect it this way if x i in C k x i... Direction we travel along this chain represents whether to set the variable to true or false. false true

17 Connecting up the paths s C 1 C 2 x 1... C k x 2... x 3... x n...... t

18 Connecting up the paths C 1 s C 2 x 1... C k x 2... x 3... x n...... t

19 Hamiltonian Cycle is NP-complete A Hamiltonian path encodes a truth assignment for the variables (depending on which direction each chain is traversed) For there to be a Hamiltonian cycle, we have to visit every clause node We can only visit a clause if we satisfy it (by setting one of its terms to true) Hence, if there is a Hamiltonian cycle, there is a satisfying assignment

20 Hamiltonian Path Hamiltonian Path: Does G contain a path that visits every node exactly once? How could you prove this problem is NP-complete?

20 Hamiltonian Path Hamiltonian Path: Does G contain a path that visits every node exactly once? How could you prove this problem is NP-complete? Reduce Hamiltonian Cycle to Hamiltonian Path. Given instance of Hamiltonian Cycle G, choose an arbitrary node v and split it into two nodes to get graph G : v v'' v' Now any Hamiltonian Path must start at v and end at v.

21 Hamiltonian Path G has a Hamiltonian Path G has a Hamiltonian Cycle. = If G has a Hamiltonian Path, then the same ordering of nodes (after we glue v and v back together) is a Hamiltonian cycle in G. = If G has a Hamiltonian Cycle, then the same ordering of nodes is a Hamiltonian path of G if we split up v into v and v. Hence, Hamiltonian Path is NP-complete.

Traveling Salesman Problem Problem (Traveling Salesman Problem). Given n cities, and distances d(i, j) between each pair of cities, does there exist a path of length k that visits each city? Notes: We have a distance between every pair of cities. In this version, d(i, j) doesn t have to equal d(j, i). And the distances don t have to obey the triangle inequality (d(i, j) d(i, k) + d(k, j) for all i, j, k).

Traveling Salesman is NP-complete Thm. Traveling Salesman is NP-complete. TSP seems a lot like Hamiltonian Cycle. We will show that Hamiltonian Cycle P TSP To do that: Given: a graph G = (V, E) that we want to test for a Hamiltonian cycle, Create: an instance of TSP.

24 Creating a TSP instance A TSP instance D consists of n cities, and n(n 1) distances. Cities We have a city c i for every node v i. Distances Let d(c i, c j ) = { 1 if edge (v i, v j ) E 2 otherwise

25 TSP Reduction Theorem. G has a Hamiltonian cycle D has a tour of length n. Proof. If G has a Ham. Cycle, then this ordering of cities gives a tour of length n in D (only distances of length 1 are used). Suppose D has a tour of length n. The tour length is the sum of n terms, meaning each term must equal 1, and hence cities that are visited consecutively must be connected by an edge in G. Also, TSP NP: a certificate is simply an ordering of the n cities.

26 TSP is NP-complete Hence, TSP is NP-complete. Even TSP restricted to the case when the d(i, j) values come from actual distances on a map is NP-complete.

Graph Coloring 27

Graph Coloring Problem Problem (Graph Coloring Problem). Given a graph G, can you color the nodes with k colors such that the endpoints of every edge are colored differently? Notation: A k-coloring is a function f : V {1,..., k} such that for every edge {u, v} we have f (u) f (v). If such a function exists for a given graph G, then G is k-colorable.

Special case of k = 2 How can we test if a graph has a 2-coloring?

Special case of k = 2 How can we test if a graph has a 2-coloring? Check if the graph is bipartite. Unfortunately, for k 3, the problem is NP-complete. Theorem. 3-Coloring is NP-complete.

Graph Coloring is NP-complete 3-Coloring NP: A valid coloring gives a certificate. We will show that: 3-SAT P 3-Coloring Let x 1,..., x n, C 1,..., C k be an instance of 3-SAT. We show how to use 3-Coloring to solve it.

31 Reduction from 3-SAT We construct a graph G that will be 3-colorable iff the 3-SAT instance is satisfiable. For every variable x i, create 2 nodes in G, one for x i and one for x i. Connect these nodes by an edge: x i x i Create 3 special nodes T, F, and B, joined in a triangle: B T F

32 Connecting them up Connect every variable node to B: x 1 x 1 x 2 x 2 x 3 x 3 B T F

Properties Properties: Each of x i and x i must get different colors Each must be different than the color of B. B, T, and F must get different colors. Hence, any 3-coloring of this graph defines a valid truth assignment! Still have to constrain the truth assignments to satisfy the given clauses, however.

34 Connect Clause (t 1, t 2, t 3 ) up like this: T F t 1 t 2 t 3

35 Suppose Every Term Was False What if every term in the clause was assigned the false color?

36 Connect Clause (t 1, t 2, t 3 ) up like this: B T F t 1 t 2 t 3

36 Connect Clause (t 1, t 2, t 3 ) up like this: B T F t 1 t 2 t 3

36 Connect Clause (t 1, t 2, t 3 ) up like this: B T F t 1 t 2 t 3

36 Connect Clause (t 1, t 2, t 3 ) up like this:?? B T F t 1 t 2 t 3

37 Suppose there is a 3-coloring Top node is colorable iff one of its terms gets the true color. Suppose there is a 3-coloring. We get a satisfying assignment by: Setting x i = true iff v i is colored the same as T Let C be any clause in the formula. At least 1 of its terms must be true, because if they were all false, we couldn t complete the coloring (as shown above).

Suppose there is a satisfying assignment Suppose there is a satisfying assignment. We get a 3-coloring of G by: Coloring T, F, B arbitrarily with 3 different colors If x i = true, color v i with the same color as T and v i with the color of F. If x i = false, do the opposite. Extend this coloring into the clause gadgets. Hence: the graph is 3-colorable iff the formula it is derived from is satisfiable.