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

Similar documents
8.5 Sequencing Problems

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

4/20/11. NP-complete problems. A variety of NP-complete problems. Hamiltonian Cycle. Hamiltonian Cycle. Directed Hamiltonian Cycle

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

Chapter 8. NP and Computational Intractability

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

4/30/14. Chapter Sequencing Problems. NP and Computational Intractability. Hamiltonian Cycle

NP and Computational Intractability

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

CS 580: Algorithm Design and Analysis

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

Polynomial-Time Reductions

Computational Intractability 2010/4/15. Lecture 2

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

NP completeness and computational tractability Part II

NP and Computational Intractability

CS 580: Algorithm Design and Analysis

CS 583: Algorithms. NP Completeness Ch 34. Intractability

SAT, Coloring, Hamiltonian Cycle, TSP

More NP-Complete Problems

COP 4531 Complexity & Analysis of Data Structures & Algorithms

Algorithm Design and Analysis

NP-complete Problems

Algorithm Design and Analysis

NP-Complete Problems. More reductions

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

Algorithms Design & Analysis. Approximation Algorithm

NP-Complete Problems

Design and Analysis of Algorithms

1.1 P, NP, and NP-complete

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

Automata Theory CS Complexity Theory I: Polynomial Time

Chapter 11. Approximation Algorithms. Slides by Kevin Wayne Pearson-Addison Wesley. All rights reserved.

Chapter 3: Proving NP-completeness Results

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

NP and NP-Completeness

Theory of Computation Chapter 9

Lecture 18: More NP-Complete Problems

Polynomial-time Reductions

CS 580: Algorithm Design and Analysis. Jeremiah Blocki Purdue University Spring 2018

CSE 421 NP-Completeness

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

NP-Completeness. NP-Completeness 1

Chapter 8. NP and Computational Intractability. CS 350 Winter 2018

1. Introduction Recap

CS21 Decidability and Tractability

Today: NP-Completeness (con t.)

Announcements. Analysis of Algorithms

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

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

Theory of Computer Science. Theory of Computer Science. E5.1 Routing Problems. E5.2 Packing Problems. E5.3 Conclusion.

CS/COE

CS 580: Algorithm Design and Analysis. Jeremiah Blocki Purdue University Spring 2018

3/22/2018. CS 580: Algorithm Design and Analysis. 8.3 Definition of NP. Chapter 8. NP and Computational Intractability. Decision Problems.

NP-Completeness. Subhash Suri. May 15, 2018

Algorithm Design and Analysis

COMP 382. Unit 10: NP-Completeness

NP Complete Problems. COMP 215 Lecture 20

Hamiltonian Cycle. Hamiltonian Cycle

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

NP-COMPLETE PROBLEMS. 1. Characterizing NP. Proof

ECS122A Handout on NP-Completeness March 12, 2018

CSC373: Algorithm Design, Analysis and Complexity Fall 2017

Intro to Theory of Computation

Limitations of Algorithm Power

Discrete Optimization 2010 Lecture 10 P, N P, and N PCompleteness

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

NP-Complete Reductions 1

max bisection max cut becomes max bisection if we require that It has many applications, especially in VLSI layout.

Computability and Complexity

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

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

Reductions. Reduction. Linear Time Reduction: Examples. Linear Time Reductions

NP-completeness. Chapter 34. Sergey Bereg

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

More on NP and Reductions

Lecture 24 : Even more reductions

CSI 4105 MIDTERM SOLUTION

4/19/11. NP and NP completeness. Decision Problems. Definition of P. Certifiers and Certificates: COMPOSITES

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

CSC 373: Algorithm Design and Analysis Lecture 15

NP-Complete Reductions 3

Algorithms: COMP3121/3821/9101/9801

CMSC 441: Algorithms. NP Completeness

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

NP Completeness and Approximation Algorithms

NP-problems continued

Graduate Algorithms CS F-21 NP & Approximation Algorithms

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

NP-Hardness reductions

Analysis of Algorithms. Unit 5 - Intractable Problems

Show that the following problems are NP-complete

VIII. NP-completeness

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

NP-Complete Reductions 2

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

Chapter 34: NP-Completeness

The P versus NP Problem. Ker-I Ko. Stony Brook, New York

Transcription:

8.5 Sequencing Problems Basic genres. Packing problems: SET-PACKING, INDEPENDENT SET. Covering problems: SET-COVER, VERTEX-COVER. Constraint satisfaction problems: SAT, 3-SAT. Sequencing problems: HAMILTONIAN-CYCLE, TSP. Partitioning problems: 3D-MATCHING, 3-COLOR. Numerical problems: SUBSET-SUM, KNAPSACK. Hamiltonian Cycle HAM-CYCLE: given an undirected graph G = (V, E), does there exist a simple cycle that contains every node in V. 2 Hamiltonian Cycle HAM-CYCLE: given an undirected graph G = (V, E), does there exist a simple cycle that contains every node in V. Directed Hamiltonian Cycle DIR-HAM-CYCLE: given a digraph G = (V, E), does there exists a simple directed cycle that contains every node in V? 1 1' Claim. DIR-HAM-CYCLE P HAM-CYCLE. 2 2' Given a directed graph G = (V, E), construct an undirected graph G' with 3n nodes. 3 3' 4 5 4' a b c v G d e ao b o c o v i v G' v o d i e i NO: bipartite graph with odd number of nodes. 3 4 1

Directed Hamiltonian Cycle Claim. G has a Hamiltonian cycle iff G' does. Claim. 3-SAT P DIR-HAM-CYCLE. Suppose G has a directed Hamiltonian cycle. Then G' has an undirected Hamiltonian cycle (same order). Suppose G' has an undirected Hamiltonian cycle '. ' must visit nodes in G' using one of following two orders:, B, G, R, B, G, R, B, G, R, B,, B, R, G, B, R, G, B, R, G, B, Blue nodes in ' make up directed Hamiltonian cycle reverse of one. in G, or Given an instance of 3-SAT, we construct an instance of DIR-HAM-CYCLE that has a Hamiltonian cycle iff is satisfiable. Construction. First, create graph that has 2 n Hamiltonian cycles which correspond in a natural way to 2 n possible truth assignments. 5 6 Construction. Given 3-SAT instance with n variables x i and k clauses. Construct G to have 2 n Hamiltonian cycles. Intuition: traverse path i from left to right set x i = 1. s Construction. Given 3-SAT instance with n variables x i and k clauses. For each clause: add a node and 6 edges. clause node clause node s x1 x1 x2 x2 x3 x3 t t 3k + 3 7 8 2

Claim. is satisfiable iff G has a Hamiltonian cycle. Claim. is satisfiable iff G has a Hamiltonian cycle. Suppose 3-SAT instance has satisfying assignment x*. Then, define Hamiltonian cycle in G as follows: if x i * = 1, traverse row i from left to right if x i * = 0, traverse row i from right to left for each clause C j, there will be at least one row i in which we are going in "correct" direction to splice node C j into tour Suppose G has a Hamiltonian cycle. If enters clause node C j, it must depart on mate edge. thus, nodes immediately before and after C j are connected by an edge e in G removing C j from cycle, and replacing it with edge e yields Hamiltonian cycle on G - { C j } Continuing in this way, we are left with Hamiltonian cycle ' in G - { C 1, C 2,..., C k }. Set x i * = 1 iff ' traverses row i left to right. Since visits each clause node C j, at least one of the paths is traversed in "correct" direction, and each clause is satisfied. 9 10 All 13,509 cities in US with a population of at least 500 Reference: http://www.tsp.gatech.edu Optimal TSP tour Reference: http://www.tsp.gatech.edu 11 12 3

11,849 holes to drill in a programmed logic array Reference: http://www.tsp.gatech.edu Optimal TSP tour Reference: http://www.tsp.gatech.edu 13 14 HAM-CYCLE: given a graph G = (V, E), does there exists a simple cycle that contains every node in V? Claim. HAM-CYCLE P TSP. Given instance G = (V, E) of HAM-CYCLE, create n cities with distance function 1 if (u, v) E d(u, v) 2 if (u, v) E Partitioning Problems Basic genres. Packing problems: SET-PACKING, INDEPENDENT SET. Covering problems: SET-COVER, VERTEX-COVER. Constraint satisfaction problems: SAT, 3-SAT. Sequencing problems: HAMILTONIAN-CYCLE, TSP. Partitioning problems: 3D-MATCHING, 3-COLOR. Numerical problems: SUBSET-SUM, KNAPSACK. TSP instance has tour of length n iff G is Hamiltonian. Remark. TSP instance in reduction satisfies -inequality. 15 4

Graph Coloring Basic genres. Packing problems: SET-PACKING, INDEPENDENT SET. Covering problems: SET-COVER, VERTEX-COVER. Constraint satisfaction problems: SAT, 3-SAT. Sequencing problems: HAMILTONIAN-CYCLE, TSP. Partitioning problems: 3D-MATCHING, 3-COLOR. Numerical problems: SUBSET-SUM, KNAPSACK. 3-COLOR: Given an undirected graph G does there exists a way to color the nodes red, green, and blue so that no adjacent nodes have the same color? 25 Register Allocation Register allocation. Assign program variables to machine register so that no more than k registers are used and no two program variables that are needed at the same time are assigned to the same register. Interference graph. Nodes are program variables names, edge between u and v if there exists an operation where both u and v are "live" at the same time. Observation. [Chaitin 1982] Can solve register allocation problem iff interference graph is k-colorable. Fact. 3-COLOR P k-register-allocation for any constant k 3. Claim. 3-SAT P 3-COLOR. Given 3-SAT instance, we construct an instance of 3-COLOR that is 3-colorable iff is satisfiable. Construction. i. For each literal, create a node. ii. Create 3 new nodes T, F, B; connect them in a triangle, and connect each literal to B. iii. Connect each literal to its negation. iv. For each clause, add gadget of 6 nodes and 13 edges. to be described next 26 27 5

Claim. Graph is 3-colorable iff is satisfiable. Claim. Graph is 3-colorable iff is satisfiable. Suppose graph is 3-colorable. Consider assignment that sets all T literals to true. (literals with the same color as the T node) (ii) ensures each literal is T or F. (iii) ensures a literal and its negation are opposites. true false Suppose graph is 3-colorable. Consider assignment that sets all T literals to true. (ii) ensures each literal is T or F. (iii) ensures a literal and its negation are opposites. (iv) ensures at least one literal in each clause is T. B T F B base 6-node gadget true T F false 28 29 Claim. Graph is 3-colorable iff is satisfiable. Claim. Graph is 3-colorable iff is satisfiable. Suppose graph is 3-colorable. Consider assignment that sets all T literals to true. (ii) ensures each literal is T or F. (iii) ensures a literal and its negation are opposites. (iv) ensures at least one literal in each clause is T. B not 3-colorable if all are red Suppose 3-SAT formula is satisfiable. Color all true literals T and false literals F. Color node below green node F, and node below that B. Color remaining middle row nodes B. Color remaining bottom nodes T or F as forced. a literal set to true in B 3-SAT assignment 6-node gadget 6-node gadget contradiction true T F false true T F false 30 6

Numerical Problems Basic genres. Packing problems: SET-PACKING, INDEPENDENT SET. Covering problems: SET-COVER, VERTEX-COVER. Constraint satisfaction problems: SAT, 3-SAT. Sequencing problems: HAMILTONIAN-CYCLE, TSP. Partitioning problems: 3-COLOR, 3D-MATCHING. Numerical problems: SUBSET-SUM, KNAPSACK. Subset Sum SUBSET-SUM. Given natural numbers w 1,, w n and an integer W, is there a subset that adds up to exactly W? Ex: { 1, 4, 16, 64, 256, 1040, 1041, 1093, 1284, 1344 }, W = 3754. Yes. 1 + 16 + 64 + 256 + 1040 + 1093 + 1284 = 3754. Remark. With arithmetic problems, input integers are encoded in binary. Polynomial reduction must be polynomial in binary encoding. Claim. 3-SAT P SUBSET-SUM. Given an instance of 3-SAT, we construct an instance of SUBSET-SUM that has solution iff is satisfiable. 33 Subset Sum Construction. Given 3-SAT instance with n variables and k clauses, form 2n + 2k decimal integers, each of n+k digits, as illustrated below. Claim. is satisfiable iff there exists a subset that sums to W. No carries possible. dummies to get clause columns to sum to 4 x x y y z z W x y z C1 C2 C3 1 0 0 0 1 0 1 0 0 1 0 1 0 1 0 1 0 0 0 1 0 0 1 1 0 0 1 1 1 0 0 0 1 0 0 1 0 0 0 1 0 0 0 0 0 2 0 0 0 0 0 0 1 0 0 0 0 0 2 0 0 0 0 0 0 1 0 0 0 0 0 2 1 1 1 4 4 4 Scheduling With Release Times SCHEDULE-RELEASE-TIMES. Given a set of n jobs with processing time t i, release time r i, and deadline d i, is it possible to schedule all jobs on a single machine such that job i is processed with a contiguous slot of t i time units in the interval [r i, d i ]? Claim. SUBSET-SUM P SCHEDULE-RELEASE-TIMES. Given an instance of SUBSET-SUM w 1,, w n, and target W, Create n jobs with processing time t i = w i, release time r i = 0, and no deadline (d i = 1 + j w j ). Create job 0 with t 0 = 1, release time r 0 = W, and deadline d 0 = W+1. 0 Can schedule jobs 1 to n anywhere but [W, W+1] job 0 W W+1 S+1 34 35 7

Polynomial-Time Reductions Extra Slides: 4 Color Theorem constraint satisfaction 3-SAT INDEPENDENT SET DIR-HAM-CYCLE GRAPH 3-COLOR SUBSET-SUM VERTEX COVER HAM-CYCLE PLANAR 3-COLOR SCHEDULING SET COVER TSP packing and covering sequencing partitioning numerical 36 Planarity Definition. A graph is planar if it can be embedded in the plane in such a way that no two edges cross. Applications: VLSI circuit design, computer graphics. Planarity Testing Planarity testing. [Hopcroft-Tarjan 1974] O(n). simple planar graph can have at most 3n edges Remark. Many intractable graph problems can be solved in polytime if the graph is planar; many tractable graph problems can be solved faster if the graph is planar. Planar K5: non-planar K3,3: non-planar Kuratowski's Theorem. An undirected graph G is non-planar iff it contains a subgraph homeomorphic to K 5 or K 3,3. homeomorphic to K3,3 38 39 8

Planar PLANAR-3-COLOR. Given a planar map, can it be colored using 3 colors so that no adjacent regions have the same color? Planar PLANAR-3-COLOR. Given a planar map, can it be colored using 3 colors so that no adjacent regions have the same color? YES instance. NO instance. 40 41 Planar Claim. 3-COLOR P PLANAR-3-COLOR. Proof sketch: Given instance of 3-COLOR, draw graph in plane, letting edges cross if necessary. Replace each edge crossing with the following planar gadget W. in any 3-coloring of W, opposite corners have the same color any assignment of colors to the corners in which opposite corners have the same color extends to a 3-coloring of W Planar k-colorability PLANAR-2-COLOR. Solvable in linear time. PLANAR-3-COLOR. NP-complete. PLANAR-4-COLOR. Solvable in O(1) time Theorem. [Appel-Haken, 1976] Every planar map is 4-colorable. Resolved century-old open problem. Used 50 days of computer time to deal with many special cases. First major theorem to be proved using computer. False intuition. If PLANAR-3-COLOR is hard, then so is PLANAR-4-COLOR and PLANAR-5-COLOR. 42 43 9