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

Slides:



Advertisements
Similar presentations
NP-Hard Nattee Niparnan.
Advertisements

1 Chapter 8 NP and Computational Intractability Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
NP-Completeness: Reductions
The Theory of NP-Completeness
1 Chapter 8 NP and Computational Intractability Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
Complexity 11-1 Complexity Andrei Bulatov NP-Completeness.
Reduction Techniques Restriction Local Replacement Component Design Examples.
Transitivity of  poly Theorem: Let ,  ’, and  ’’ be three decision problems such that   poly  ’ and  ’  poly  ’’. Then  poly  ’’. Proof:
Computability and Complexity 16-1 Computability and Complexity Andrei Bulatov NP-Completeness.
Polynomial-Time Reductions
1 Chapter 8 NP and Computational Intractability Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
Time Complexity.
NP-Completeness (2) NP-Completeness Graphs 4/17/2017 6:25 AM x x x x x
1 CSE 417: Algorithms and Computational Complexity Winter 2001 Lecture 24 Instructor: Paul Beame.
CSE 421 Algorithms Richard Anderson Lecture 27 NP Completeness.
February 25, 2015CS21 Lecture 211 CS21 Decidability and Tractability Lecture 21 February 25, 2015.
P, NP, and NP-Complete Suzan Köknar-Tezel.
Prof. Swarat Chaudhuri COMP 482: Design and Analysis of Algorithms Spring 2013 Lecture 22.
CSCI-256 Data Structures & Algorithm Analysis Lecture Note: Some slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. 31.
1 Chapter 8 NP and Computational Intractability Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
The Theory of NP-Completeness 1. Nondeterministic algorithms A nondeterminstic algorithm consists of phase 1: guessing phase 2: checking If the checking.
The Theory of NP-Completeness 1. What is NP-completeness? Consider the circuit satisfiability problem Difficult to answer the decision problem in polynomial.
1 The Theory of NP-Completeness 2012/11/6 P: the class of problems which can be solved by a deterministic polynomial algorithm. NP : the class of decision.
Nattee Niparnan. Easy & Hard Problem What is “difficulty” of problem? Difficult for computer scientist to derive algorithm for the problem? Difficult.
1 The TSP : NP-Completeness Approximation and Hardness of Approximation All exact science is dominated by the idea of approximation. -- Bertrand Russell.
MCS 312: NP Completeness and Approximation algorithms Instructor Neelima Gupta
Lecture 22 More NPC problems
CSEP 521 Applied Algorithms Richard Anderson Lecture 10 NP Completeness.
INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011.
NP-complete Problems SAT 3SAT Independent Set Hamiltonian Cycle
Prabhas Chongstitvatana1 NP-complete proofs The circuit satisfiability proof of NP- completeness relies on a direct proof that L  p CIRCUIT-SAT for every.
Final Exam Review Final exam will have the similar format and requirements as Mid-term exam: Closed book, no computer, no smartphone Calculator is Ok Final.
1 Chapter 8 NP and Computational Intractability Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
Basic genres.  Packing problems: SET-PACKING, INDEPENDENT SET.  Covering problems: S ET-COVER, VERTEX-COVER.  Constraint satisfaction problems: SAT,
CSCI-256 Data Structures & Algorithm Analysis Lecture Note: Some slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. 33.
CSE 024: Design & Analysis of Algorithms Chapter 9: NP Completeness Sedgewick Chp:40 David Luebke’s Course Notes / University of Virginia, Computer Science.
EMIS 8373: Integer Programming NP-Complete Problems updated 21 April 2009.
Additional NP-complete problems
1 Chapter 8 NP and Computational Intractability Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
Unit 9: Coping with NP-Completeness
30.
1.1 Chapter 3: Proving NP-completeness Results Six Basic NP-Complete Problems Some Techniques for Proving NP-Completeness Some Suggested Exercises.
CS 3343: Analysis of Algorithms Lecture 25: P and NP Some slides courtesy of Carola Wenk.
CSCI-256 Data Structures & Algorithm Analysis Lecture Note: Some slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. 29.
CS6045: Advanced Algorithms NP Completeness. NP-Completeness Some problems are intractable: as they grow large, we are unable to solve them in reasonable.
1 Chapter 8 NP and Computational Intractability Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
28.
NPC.
CSC 413/513: Intro to Algorithms
CSCI-256 Data Structures & Algorithm Analysis Lecture Note: Some slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. 32.
NP-Completeness Note. Some illustrations are taken from (KT) Kleinberg and Tardos. Algorithm Design (DPV)Dasgupta, Papadimitriou, and Vazirani. Algorithms.
1 Ch 10 - NP-completeness Tractable and intractable problems Decision/Optimization problems Deterministic/NonDeterministic algorithms Classes P and NP.
CSE 421 Algorithms Richard Anderson Lecture 27 NP-Completeness Proofs.
The Theory of NP-Completeness 1. Nondeterministic algorithms A nondeterminstic algorithm consists of phase 1: guessing phase 2: checking If the checking.
COSC 3101A - Design and Analysis of Algorithms 14 NP-Completeness.
1 Chapter 8 NP and Computational Intractability Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
34.NP Completeness. Computer Theory Lab. Chapter 34P.2.
CSE 332: NP Completeness, Part II Richard Anderson Spring 2016.
TU/e Algorithms (2IL15) – Lecture 10 1 NP-Completeness, II.
ICS 353: Design and Analysis of Algorithms NP-Complete Problems King Fahd University of Petroleum & Minerals Information & Computer Science Department.
More NP-Complete and NP-hard Problems
Hard Problems Some problems are hard to solve.
Richard Anderson Lecture 26 NP-Completeness
Richard Anderson Lecture 26 NP-Completeness
ICS 353: Design and Analysis of Algorithms
Richard Anderson Lecture 25 NP-Completeness
Chapter 8 NP and Computational Intractability
Chapter 8 NP and Computational Intractability
Richard Anderson Lecture 27 Survey of NP Complete Problems
Presentation transcript:

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

Basic genres.  Packing problems: SET-PACKING, INDEPENDENT SET.  Covering problems: S ET-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. 8.5 Sequencing Problems

3 Hamiltonian Cycle HAM-CYCLE : given an undirected graph G = (V, E), does there exist a simple cycle  that contains every node in V. YES: vertices and faces of a dodecahedron.

4 Hamiltonian Cycle HAM-CYCLE : given an undirected graph G = (V, E), does there exist a simple cycle  that contains every node in V ' 3' 2 4 2' 4' NO: bipartite graph with odd number of nodes.

5 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? Claim. DIR-HAM-CYCLE  P HAM-CYCLE. Pf. Given a directed graph G = (V, E), construct an undirected graph G' with 3n nodes. v a b c d e v in a out b out c out d in e in G G' vv out

6 Directed Hamiltonian Cycle Claim. G has a Hamiltonian cycle iff G' does. Pf.  n Suppose G has a directed Hamiltonian cycle . n Then G' has an undirected Hamiltonian cycle (same order). Pf.  n Suppose G' has an undirected Hamiltonian cycle  '. n  ' 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, … n Blue nodes in  ' make up directed Hamiltonian cycle  in G, or reverse of one. ▪

7 3-SAT Reduces to Directed Hamiltonian Cycle Claim. 3-SAT  P DIR-HAM-CYCLE. Pf. 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.

8 3-SAT Reduces to Directed Hamiltonian Cycle Construction. Given 3-SAT instance  with n variables x i and k clauses. n Construct G to have 2 n Hamiltonian cycles. n Intuition: traverse path i from left to right  set variable x i = 1. s t 3k + 3 (any number > 2k+2) x1x1 x2x2 x3x3

9 3-SAT Reduces to Directed Hamiltonian Cycle Construction. Given 3-SAT instance  with n variables x i and k clauses. n For each clause: add a node and 6 edges. n A clause can only be traveled of the cycle traverses a path in correct direction. s t clause node x1x1 x2x2 x3x3

10 3-SAT Reduces to Directed Hamiltonian Cycle Claim.  is satisfiable iff G has a Hamiltonian cycle. Pf.  n Suppose 3-SAT instance has satisfying assignment x*. n 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

11 3-SAT Reduces to Directed Hamiltonian Cycle Claim.  is satisfiable iff G has a Hamiltonian cycle. Pf.  n Suppose G has a Hamiltonian cycle . If  enters clause node C j, it must depart on mate edge (why?). – 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. ▪

12 Longest Path SHORTEST-PATH. Given a digraph G = (V, E), does there exists a simple path of length at most k edges? LONGEST-PATH. Given a digraph G = (V, E), does there exists a simple path of length at least k edges? Claim. 3-SAT  P LONGEST-PATH. Pf 1. Redo proof for DIR-HAM-CYCLE, ignoring back-edge from t to s. Pf 2. Show HAM-CYCLE  P LONGEST-PATH.

13 Traveling Salesperson Problem TSP. Given a set of n cities and a pairwise distance function d(u, v), is there a tour of length  D? All 13,509 cities in US with a population of at least 500 Reference:

14 Traveling Salesperson Problem TSP. Given a set of n cities and a pairwise distance function d(u, v), is there a tour of length  D? Optimal TSP tour Reference:

15 Traveling Salesperson Problem TSP. Given a set of n cities and a pairwise distance function d(u, v), is there a tour of length  D? 11,849 holes to drill in a programmed logic array Reference:

16 Traveling Salesperson Problem TSP. Given a set of n cities and a pairwise distance function d(u, v), is there a tour of length  D? Optimal TSP tour Reference:

17 Traveling Salesperson Problem TSP. Given a set of n cities and a pairwise distance function d(u, v), is there a tour of length  D? 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. Pf. n Given instance G = (V, E) of HAM-CYCLE, create n cities with distance function n TSP instance has tour of length  n iff G is Hamiltonian. ▪ n Problem A is a special case of Problem B (method in reduction)

Basic genres.  Packing problems: SET-PACKING, INDEPENDENT SET.  Covering problems: S ET-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. 8.6 Partitioning Problems

19 3-Dimensional Matching 3D-MATCHING. Given n instructors, n courses, and n times, and a list of the possible courses and times each instructor is willing to teach, is it possible to make an assignment so that all courses are taught at different times? InstructorCourseTime WayneCOS 423MW 11-12:20 WayneCOS 423TTh 11-12:20 WayneCOS 226TTh 11-12:20 WayneCOS 126TTh 11-12:20 TardosCOS 523TTh 3-4:20 TardosCOS 423TTh 11-12:20 TardosCOS 423TTh 3-4:20 KleinbergCOS 226TTh 3-4:20 KleinbergCOS 226MW 11-12:20 KleinbergCOS 423MW 11-12:20

20 3-Dimensional Matching 3D-MATCHING. Given disjoint sets X, Y, and Z, each of size n and a set T  X  Y  Z of triples, does there exist a set of n triples in T such that each element of X  Y  Z is in exactly one of these triples? Claim. 3-SAT  P INDEPENDENT-COVER. Pf. Given an instance  of 3-SAT, we construct an instance of 3D- matching that has a perfect matching iff  is satisfiable.

Basic genres.  Packing problems: SET-PACKING, INDEPENDENT SET.  Covering problems: S ET-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. 8.7 Graph Coloring

22 3-Colorability 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? yes instance

23 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.

24 3-Colorability Claim. 3-SAT  P 3-COLOR. Pf. Given 3-SAT instance , we construct an instance of 3-COLOR that is 3-colorable iff  is satisfiable. Construction. i. For each literal (Boolean variable), create a node and a negation node. ii. Create 3 new nodes T, F, B; connect them in a triangle, and connect each literal and its negation 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

25 3-Colorability Claim. Graph is 3-colorable iff  is satisfiable. Pf.  Suppose graph is 3-colorable. n Consider assignment that sets all T literals to true. n (ii) ensures each literal is T or F. n (iii) ensures a literal and its negation are opposites. T B F true false base

26 3-Colorability Claim. Graph is 3-colorable iff  is satisfiable. Pf.  Suppose graph is 3-colorable. n Consider assignment that sets all T literals to true. n (ii) ensures each literal is T or F (because Base is Blue color). n (iii) ensures a literal and its negation are opposites. n (iv) ensures at least one literal in each clause is T. TF B 6-node gadget true false

27 3-Colorability Claim. Graph is 3-colorable iff  is satisfiable. Pf.  Suppose graph is 3-colorable. n Consider assignment that sets all T literals to true. n (ii) ensures each literal is T or F. n (iii) ensures a literal and its negation are opposites (because of neighborhood relationship). n (iv) ensures at least one literal in each clause is T. TF B not 3-colorable if all are red true false contradiction

28 3-Colorability Claim. Graph is 3-colorable iff  is satisfiable. Pf.  Suppose 3-SAT formula  is satisfiable. n Color all true literals T. n Color node below green node F, and node below that B. n Color remaining middle row nodes B. n Color remaining bottom nodes T or F as forced. ▪ TF B a literal set to true in 3-SAT assignment true false

Basic genres.  Packing problems: SET-PACKING, INDEPENDENT SET.  Covering problems: S ET-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. 8.8 Numerical Problems

30 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 = Yes = Remark. With arithmetic problems, input integers are encoded in binary. Polynomial reduction must be polynomial in binary encoding. Claim. 3-SAT  P SUBSET-SUM. Pf. Given an instance  of 3-SAT, we construct an instance of SUBSET- SUM that has solution iff  is satisfiable.

31 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. Pf. No carries possible. dummies to get clause columns to sum to 4 y x z xyzC1C1 C2C2 C3C  x x  y y  z z W ,001 10,011 10, , ,010 1, ,444

1. Proof:  (if subsum solution exists) 2. Variable column: one and only one row is picked (each variable is set either true or false) 3. Clause column: dummy rows sum is 3, so at least one variable row is chosen 1. The clause is true if one or more variable in it is set to be true 32 y x z xyzC1C1 C2C2 C3C  x x  y y  z z W ,001 10,011 10, , ,010 1, ,444

8.10 A Partial Taxonomy of Hard Problems

34 Polynomial-Time Reductions 3-SAT DIR-HAM-CYCLEINDEPENDENT SET VERTEX COVER Dick Karp (1972) 1985 Turing Award 3-SAT reduces to INDEPENDENT SET GRAPH 3-COLOR HAM-CYCLE TSP SUBSET-SUM SCHEDULING PLANAR 3-COLOR SET COVER packing and covering sequencingpartitioningnumerical constraint satisfaction