Chapter 8. NP-complete problems. Search problems. cient algorithms. Exponential search space

Similar documents
Chapter 8. NP-complete problems

Chapter 8. NP-complete problems

P and NP CISC4080, Computer Algorithms CIS, Fordham Univ. Instructor: X. Zhang

P and NP CISC5835, Algorithms for Big Data CIS, Fordham Univ. Instructor: X. Zhang

Unit 8: Coping with NP-Completeness. Complexity classes Reducibility and NP-completeness proofs Coping with NP-complete problems. Y.-W.

NP-complete problems. Chapter Search problems

Some Hardness Proofs

CMPSCI611: The SUBSET-SUM Problem Lecture 18

NP-Hardness. We start by defining types of problem, and then move on to defining the polynomial-time reductions.

NP-Completeness. Algorithms

Final. Name: TA: Section Time: Course Login: Person on Left: Person on Right: U.C. Berkeley CS170 : Algorithms, Fall 2013

Best known solution time is Ω(V!) Check every permutation of vertices to see if there is a graph edge between adjacent vertices

Theorem 2.9: nearest addition algorithm

8 NP-complete problem Hard problems: demo

Computability Theory

W4231: Analysis of Algorithms

8.1 Polynomial-Time Reductions

Chapter 10 Part 1: Reduction

Computational problems. Lecture 2: Combinatorial search and optimisation problems. Computational problems. Examples. Example

1 Definition of Reduction

NP-complete Reductions

Lecture 24: More Reductions (1997) Steven Skiena. skiena

Vertex Cover Approximations

NP-Complete Reductions 2

Questions? You are given the complete graph of Facebook. What questions would you ask? (What questions could we hope to answer?)

NP and computational intractability. Kleinberg and Tardos, chapter 8

Decision Problems. Observation: Many polynomial algorithms. Questions: Can we solve all problems in polynomial time? Answer: No, absolutely not.

The Satisfiability Problem [HMU06,Chp.10b] Satisfiability (SAT) Problem Cook s Theorem: An NP-Complete Problem Restricted SAT: CSAT, k-sat, 3SAT

! Greed. O(n log n) interval scheduling. ! Divide-and-conquer. O(n log n) FFT. ! Dynamic programming. O(n 2 ) edit distance.

6. Lecture notes on matroid intersection

11/22/2016. Chapter 9 Graph Algorithms. Introduction. Definitions. Definitions. Definitions. Definitions

Chapter 9 Graph Algorithms

Notes for Lecture 24

CS270 Combinatorial Algorithms & Data Structures Spring Lecture 19:

P and NP (Millenium problem)

! Greed. O(n log n) interval scheduling. ! Divide-and-conquer. O(n log n) FFT. ! Dynamic programming. O(n 2 ) edit distance.

1. Suppose you are given a magic black box that somehow answers the following decision problem in polynomial time:

Chapter 9 Graph Algorithms

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

Chapter 9 Graph Algorithms

NP Completeness. Andreas Klappenecker [partially based on slides by Jennifer Welch]

Lecture 13. Reading: Weiss, Ch. 9, Ch 8 CSE 100, UCSD: LEC 13. Page 1 of 29

Lecture 11: Maximum flow and minimum cut

CS483 Design and Analysis of Algorithms

Reductions. Linear Time Reductions. Desiderata. Reduction. Desiderata. Classify problems according to their computational requirements.

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Approximation algorithms Date: 11/27/18

8.1 Polynomial-Time Reductions

Lecture 20: Satisfiability Steven Skiena. Department of Computer Science State University of New York Stony Brook, NY

Hardness of Approximation for the TSP. Michael Lampis LAMSADE Université Paris Dauphine

A Simplied NP-complete MAXSAT Problem. Abstract. It is shown that the MAX2SAT problem is NP-complete even if every variable

Last topic: Summary; Heuristics and Approximation Algorithms Topics we studied so far:

Assignment 4 Solutions of graph problems

Steven Skiena. skiena

Lecture 1. 2 Motivation: Fast. Reliable. Cheap. Choose two.

Module 6 NP-Complete Problems and Heuristics

Module 6 NP-Complete Problems and Heuristics

PCP and Hardness of Approximation

More NP-Complete Problems [HMU06,Chp.10b] Node Cover Independent Set Knapsack Real Games

Module 6 NP-Complete Problems and Heuristics

1 Variations of the Traveling Salesman Problem

Complexity Classes and Polynomial-time Reductions

Approximation Algorithms

Discrete Optimization. Lecture Notes 2

Modules. 6 Hamilton Graphs (4-8 lectures) Introduction Necessary conditions and sufficient conditions Exercises...

CMSC 451: Lecture 22 Approximation Algorithms: Vertex Cover and TSP Tuesday, Dec 5, 2017

FINAL EXAM SOLUTIONS

CS 580: Algorithm Design and Analysis

3/7/2018. CS 580: Algorithm Design and Analysis. 8.1 Polynomial-Time Reductions. Chapter 8. NP and Computational Intractability

Recitation 4: Elimination algorithm, reconstituted graph, triangulation

Introduction to Algorithms / Algorithms I Lecturer: Michael Dinitz Topic: Approximation algorithms Date: 11/18/14

Module 6 P, NP, NP-Complete Problems and Approximation Algorithms

NP-Completeness of 3SAT, 1-IN-3SAT and MAX 2SAT

Treewidth and graph minors

Approximation scheme for the traveling salesman problem

6.2. Paths and Cycles

CSE 417 Branch & Bound (pt 4) Branch & Bound

Theory of Computing. Lecture 10 MAS 714 Hartmut Klauck

5. Lecture notes on matroid intersection

Notes for Recitation 9

CS261: A Second Course in Algorithms Lecture #16: The Traveling Salesman Problem

S. Dasgupta, C.H. Papadimitriou, and U.V. Vazirani 241

9.1 Cook-Levin Theorem

Recognizing Interval Bigraphs by Forbidden Patterns

COMP 355 Advanced Algorithms Approximation Algorithms: VC and TSP Chapter 11 (KT) Section (CLRS)

Example of a Demonstration that a Problem is NP-Complete by reduction from CNF-SAT

In this lecture we discuss the complexity of approximation problems, and show how to prove they are NP-hard.

More NP-complete Problems. CS255 Chris Pollett May 3, 2006.

Math 443/543 Graph Theory Notes

Advanced Algorithms Class Notes for Monday, October 23, 2012 Min Ye, Mingfu Shao, and Bernard Moret

Eulerian disjoint paths problem in grid graphs is NP-complete

3 Euler Tours, Hamilton Cycles, and Their Applications

Characterizing Graphs (3) Characterizing Graphs (1) Characterizing Graphs (2) Characterizing Graphs (4)

Module 7. Independent sets, coverings. and matchings. Contents

Introduction to Graph Theory

Greedy algorithms Or Do the right thing

Examples of P vs NP: More Problems

Mathematical and Algorithmic Foundations Linear Programming and Matchings

Exercises Computational Complexity

Lecture 3: Graphs and flows

Graph Theory S 1 I 2 I 1 S 2 I 1 I 2

Transcription:

Chapter 8. NP-complete problems Search problems 1 / 64 2 / 64 E cient algorithms Exponential search space We have developed algorithms for finding shortest paths in graphs, minimum spanning trees in graphs, matchings in bipartite graphs, maximum increasing subsequences, maximum flows in networks,... All these algorithms are e cient, because in each case their time requirement grows as a polynomial function (such as n, n 2,orn 3 ) of the size of the input. n all these problems we are searching for a solution (path, tree, matching, etc.) from among an exponential population of possibilities. All these problems could in principle be solved in exponential time by checking through all candidate solutions, one by one. But an algorithm whose running time is 2 n, or worse, is all but useless in practice The quest for e cient algorithms is about finding clever ways to bypass this process of exhaustive search, using clues from the input in order to dramatically narrow down the search space. Now will see some other search problems in which again we are seeking a solution with particular properties among an exponential chaos of alternatives. The fastest algorithms we know for them are all exponential. 3 / 64 4 / 64

Satisfiability Satisfiability (cont d) The instances of Satisfiability or sat: (x _ y _ z)(x _ ȳ)(y _ z)(z _ x)( x _ ȳ _ z) That is, a Boolean formula in conjunctive normal form (CNF). t is a collection of clauses (the parentheses), each consisting of the disjunction (logical or, denoted _) of several literals, where a literal is either a Boolean variable (such as x) or the negation of one (such as x). A satisfying truth assignment is an assignment of false or true to each variable so that every clause contains a literal whose value is true. The sat problem is the following: given a Boolean formula in conjunctive normal form, either find a satisfying truth assignment or else report that none exists. sat is a typical search problem. We are given an instance (that is, some input data specifying the problem at hand, in this case a Boolean formula in conjunctive normal form), and we are asked to find a solution S (an object that meets a particular specification, in this case an assignment that satisfies each clause). f no such solution exists, we must say so. 5 / 64 6 / 64 Search problems The traveling salesman problem n the traveling salesman problem (tsp) we are given n vertices 1,...,n and all n(n 1)/2 distances between them, as well as a budget b. We are asked to find a tour, a cycle that passes through every vertex exactly once, of total cost b or less or to report that no such tour exists. A search problem is specified by an algorithm C that takes two inputs, an instance and a proposed solution S, and runs in time polynomial in. We say S is a solution to if and only if C(, S) =true. That is, we seek a permutation (1),..., (n) of the vertices such that when they are toured in this order, the total distance covered is at most b: d (1), (2) + d (2), (3) + + d (n), (1) apple b. We have defined the tsp as a search problem: given an instance, find a tour within the budget (or report that none exists). But why are we expressing the traveling salesman problem in this way, when in reality it is an optimization problem, in which the shortest possible tour is sought? 7 / 64 8 / 64

Search vs. optimization Then why search instead of optimization? Turning an optimization problem into a search problem does not change its di culty at all, because the two versions reduce to one another. Any algorithm that solves the optimization tsp also readily solves the search problem: nd the optimum tour and if it is within budget, return it; if not, there is no solution. Conversely, an algorithm for the search problem can also be used to solve the optimization problem: First suppose that we somehow knew the cost of the optimum tour; then we could find this tour by calling the algorithm for the search problem, using the optimum cost as the budget. We can find the optimum cost by binary search. sn t any optimization problem also a search problem in the sense that we are searching for a solution that has the property of being optimal? The solution to a search problem should be easy to recognize, or as we put it earlier, polynomial-time checkable. Given a potential solution to the tsp, it is easy to check the properties is a tour (just check that each vertex is visited exactly once) and has total length apple b. But how could one check the property is optimal? 9 / 64 10 / 64 Euler Path Rudrata Cycle Euler Path: Given a graph, find a path that contains each edge exactly once. The answer is yes if and only if (a) the graph is connected and (b) every vertex, with the possible exception of two vertices (the start and final vertices of the walk), has even degree. Using above, it is easy to see that there is a polynomial time algorithm for Euler Path. Rudrata Cycle: Given a graph, find a cycle that visits each vertex exactly once. n the literature this problem is known as the Hamilton cycle problem. 11 / 64 12 / 64

Minimum Cut Balanced Cut A cut is a set of edges whose removal leaves a graph disconnected. minimum cut: given a graph and a budget b, find a cut with at most b edges. This problem can be solved in polynomial time by n 1 max-flow computations: give each edge a capacity of 1, and find the maximum flow between some fixed node and every single other node. The smallest such flow will correspond (via the max-flow min-cut theorem) to the smallest cut. n many graphs, the smallest cut leaves just a singleton vertex on one side it consists of all edges adjacent to this vertex. Far more interesting are small cuts that partition the vertices of the graph into nearly equal-sized sets. balanced cut: Given a graph with n vertices and a budget b, partition the vertices into two sets S and T such that S, T n/3 and such that there are at most b edges between S and T. 13 / 64 14 / 64 nteger linear programming Three-dimensional matching integer linear programming (LP): We are given a set of linear inequalities Ax apple b, where A is an m n matrix and b is an m-vector; an objective function specified by an n-vector c; and finally, a goal g (the counterpart of a budget in maximization problems). We want to find a nonnegative integer n-vector x such that Ax apple b and c x g. But there is a redundancy here: the last constraint c x inequality and can be absorbed into Ax apple b. g is itself a linear So, we define LP to be following search problem: given A and b, find a nonnegative integer vector x satisfying the inequalities Ax apple b. 3D matching: There are n boys and n girls, but also n pets, and the compatibilities among them are specified by a set of triples, each containing a boy, a girl, and a pet. ntuitively, a triple (b, g, p) means that boy b, girl g, and pet p get along well together. We want to find n disjoint triples and thereby create n harmonious households. 15 / 64 16 / 64

ndependent set, vertex cover, and clique Longest path independent set: Given a graph and an integer g, find g vertices, no two of which have an edge between them. vertex cover: Given a graph and an integer b, find b vertices cover (touch) every edge. clique: Given a graph and an integer g, find g vertices such that all possible edges between them are present. longest path: Given a graph G with nonnegative edge weights and two distinguished vertices s and t, along with a goal g. We are asked to find a path from s to t with total weight at least g. To avoid trivial solutions we require that the path be simple, containing no repeated vertices. 17 / 64 18 / 64 Knapsack Subset sum knapsack: We are given integer weights w 1,...,w n and integer values v 1,...,v n for n items. We are also given a weight capacity W and a goal g We seek a set of items whose total weight is at most W and whose total value is at least g. The problem is solvable in time O(nW ) by dynamic programming. subset sum: Find a subset of a given set of integers that adds up to exactly W. 19 / 64 20 / 64

Hard problems, easy problems NP-complete problems Hard problems (NP-complete) Easy problems (in P) 3sat 2sat, Horn sat traveling salesman problem minimum spanning tree longest path shortest path 3Dmatching bipartite matching knapsack unary knapsack independent set independent set on trees integer linear programming linear programming Rudrata path Euler path balanced cut minimum cut 21 / 64 22 / 64 NP P Recall a search problem is defined by: There is an e cient checking algorithm C that takes as input the given instance,aswellastheproposedsolutions, andoutputstrue if and only if S really is a solution to instance. Moreover the running time of C(, S) isboundedbyapolynomialin, the length of the instance. We denote the class of all search problems by NP. We ve seen many examples of NP search problems that are solvable in polynomial time. n such cases, there is an algorithm that takes as input an instance and has a running time polynomial in. f has a solution, the algorithm returns such a solution; and if has no solution, the algorithm correctly reports so. The class of all search problems that can be solved in polynomial time is denoted P. 23 / 64 24 / 64

Why P and NP? P 6= NP? P: polynomial time NP: nondeterministic polynomial time nput: Amathematicalstatement' and n. Problem: Find a proof of ' of length apple if there is one. The task of finding a proof for a given mathematical assertion is a search problem and is therefore in NP, because A formal proof of a mathematical statement is written out in excruciating detail, it can be checked mechanically, line by line, by an e cient algorithm. So if P= NP, therewouldbeane cient method to prove any theorem, thus eliminating the need for mathematicians! 25 / 64 26 / 64 Reductions, again Reduction between search problems Even if we believe P 6= NP, what about the specific problems on the left side of the table? On the basis of what evidence do we believe that these particular problems have no e cient algorithm? Such evidence is provided by reductions, which translate one search problem into another. We will show that the problems on the left side of the table are all, in some sense, exactly the same problem, the hardest search problems in NP. f even one of them has a polynomial time algorithm, then every problem in NP has a polynomial time algorithm. A reduction from search problem A to search problem B is a polynomial time algorithm f that transforms any instance of A into an instance f ( )ofb, together with another polynomial time algorithm h that maps any solution S of f ( )backintoasolutionh(s) of. f f ( )hasnosolution,thenneitherdoes. These two translation procedures f and h imply that any algorithm for B can be converted into an algorithm for A by bracketing it between f and h. 27 / 64 28 / 64

NP-completeness The two ways to use reductions Assume there is a reduction from a problem A to a problem B. Definition AsearchproblemisNP-complete if all other search problems reduce to it. Remark t is not clear a priori that NP-complete problems exist at all. A! B. f we can solve B e ciently, then we can also solve A e ciently. f we know A is hard, then B must be hard too. Reductions also have the convenient property that they compose. f A! B and B! C, thena! C. 29 / 64 30 / 64 Factoring Rudrata (s, t)-path! Rudrata Cycle The di culty of factoring is of a di erent nature than that of the other hard search problems we have just seen. For example, nobody believes that factoring is NP-complete. One evidence is that a number can always be factored into primes. Another di erence: factoring succumbs to the power of quantum computation, whilesat, tspand the other NP-complete problems do not seem to. Recall the Rudrata Cycle problem: given a graph, is there a cycle that passes through each vertex exactly once? We can also formulate the closely related Rudrata (s, t)-path problem, in which two vertices s and t are specified, and we want a path starting at s and ending at t that goes through each vertex exactly once. s it possible that Rudrata Cycle is easier than Rudrata (s, t)-path? We will show by a reduction that the answer is no. The reduction maps an instance (G =(V, E), s, t) ofrudrata (s, t)-path into an instance G 0 =(V 0, E 0 )ofrudrata Cycle as follows: G 0 is simply G with an additional vertex x and two new edges {s, x} and {x, t}. 31 / 64 32 / 64

3Sat! ndependent Set Sat! 3Sat n 3Sat the input is a set of clauses, each with three or fewer literals, for example ( x _ y _ z)(x _ ȳ _ z)(x _ y _ z)( x _ y), and the aim is to find a satisfying truth assignment. n ndependent Set the input is a graph and a number g, andtheproblemis to find a set of g pairwise non-adjacent vertices. Given an instance of 3Sat, wecreateaninstance(g, g) ofndependent Set as follows. Graph G has a triangle for each clause (or just an edge, if the clause has two literals), with vertices labeled by the clause s literals, and has additional edges between any two vertices that represent opposite literals. The goal g is set to the number of clauses. This is an interesting and common kind of reduction, from a problem to a special case of itself. Given an instance of Sat, use exactly the same instance for 3Sat, except that any clause with more than three literals, (a 1 _ a 2 _ _ a k) (where the a i s are literals and k > 3), is replaced by a set of clauses, (a 1 _ a 2 _ y 1)(ȳ 1 _ a 3 _ y 2)(ȳ 2 _ a 4 _ y 3) (ȳ k 3 _ a k 1 _ a k), where the y i s are new variables. Call the resulting 3Sat instance 0. The conversion from to 0 is clearly polynomial time. 0 is equivalent to in terms of satisfiability, because for any assignment to the a i s, (a 1 _a 2 _ _a k ) is satisfied () there is a setting for the y i s for which (a 1 _a 2 _y 1 )(ȳ 1 _a 3 _y 2 )(ȳ 2 _a 4 _y 3 ) (ȳ k 3 _a k 1 _a k ) are all satisfied 33 / 64 34 / 64 Sat! 3Sat (cont d) ndependent Set! Vertex Cover n fact, 3Sat remains hard even under the further restriction that no variable appears in more than three clauses. Suppose that in the 3Sat instance, variable x appears in k > 3clauses.Then replace its first appearance by x 1,itssecondappearancebyx 2,andsoon, replacing each of its k appearances by a di erent new variable. Finally, add the clauses ( x 1 _ x 2)( x 2 _ x 3) ( x k _ x 1). n the new formula no variable appears more than three times (and in fact, no literal appears more than twice). To reduce ndependent Set to Vertex Cover we just need to notice that asetofnodess is a vertex cover of graph G =(V, E) (thatis,s touches every edge in E) ifandonlyiftheremainingnodes,v S, areanindependent set of G. Therefore, to solve an instance (G, g) ofndependent Set, simply look for a vertex cover of G with V g nodes. f such a vertex cover exists, then take all nodes not in it. f no such vertex cover exists, then G cannot possibly have an independent set of size g. 35 / 64 36 / 64

ndependent Set! Clique 3Sat! 3D Matching Define the complement of a graph G =(V, E) tobeḡ =(V, Ē), where Ē contains precisely those unordered pairs of vertices that are not in E. Then a set of nodes S is an independent set of G if and only if S is a clique of G. To paraphrase, these nodes have no edges between them in G if and only if they have all possible edges between them in Ḡ. Therefore, we can reduce ndependent Set to Clique by mapping an instance (G, g) ofndependent Set to the corresponding instance (Ḡ, g) of Clique; the solution to both is identical. Consider a set of four triples, each represented by a triangular node joining a boy, girl, and pet. Suppose that the two boys b 0 and b 1 and the two girls g 0 and g 1 are not involved in any other triples. (The four pets p 0,...,p 3 will of course belong to other triples as well; for otherwise the instance would trivially have no solution.) Then any matching must contain either the two triples (b 0, g 1, p 0), (b 1, g 0, p 2) or the two triples (b 0, g 0, p 1), (b 1, g 1, p 3), because these are the only ways in which these two boys and girls can find any match. Therefore, this gadget has two possible states: it behaves like a Boolean variable! To then transform an instance of 3Sat to one of 3D Matching, westartby creating a copy of the preceding gadget for each variable x. Call the resulting nodes p x1, b x0, g x1, andsoon.the intended interpretation is that boy b x0 is matched with girl g x1 if x = true, andwithgirlg x0 if x = false. 37 / 64 38 / 64 3Sat! 3D Matching (cont d) 3Sat! 3D Matching (cont d) Next we must create triples that somehow mimic clauses. For c =(x _ ȳ _ z), we introduce a new boy b c and a new girl g c. They will be involved in three triples, one for each literal in the clause. And the pets in these triples must reflect the three ways whereby the clause can be satisfied: 1. x = true, 2. y = false, 3. z = true. For (1), we have the triple (b c, g c, p x1), where p x1 is the pet p 1 in the gadget for x. f x = true, thenb x0 is matched with g x1 and b x1 with g x0, andsopets p x0 and p x2 are taken. n which case b c and g c can be matched with p x1. But if x = false, thenp x1 and p x3 are taken, and so g c and b c cannot be accommodated this way. We do the same thing for the other two literals of the clause, which yield triples involving b c and g c with either p y0 or p y2 (for the negated variable y) andwith either p z1 or p z3 (for variable z). We have to make sure that for every occurrence of a literal in a clause c there is a di erent pet to match with b c and g c. But this is easy: by an earlier reduction we can assume that no literal appears more than twice, and so each variable gadget has enough pets, two for negated occurrences and two for unnegated. The reduction now seems complete: From any matching we can recover a satisfying truth assignment by simply looking at each variable gadget and seeing with which girl b x0 was matched. And from any satisfying truth assignment we can match the gadget corresponding to each variable x so that triples (b x0, g x1, p x0) and(b x1, g x0, p x2) are chosen if x = true and triples (b x0, g x0, p x1) and(b x1, g x1, p x3) arechosenif x = false; and for each clause c match b c and g c with the pet that corresponds to one of its satisfying literals. 39 / 64 40 / 64

3Sat! 3D Matching (cont d) 3D Matching! ZOE But one last problem remains: n the matching defined so far, some pets may be left unmatched. n fact, if there are n variables and m clauses, then exactly 2n left unmatched. m pets will be But this is easy to fix: Add 2n m new boy-girl couples that are generic animal-lovers, and match them by triples with all the pets! n ZOE (Zero-One Equations) wearegivenanm n matrix A with 0 1 entries, and we must find a 0 1vectorx =(x 1,...,x n)suchthatthem equations Ax = 1, are satisfied. Here is how we express an instance of 3D Matching (m boys, m girls, m pets, and n boy-girl-pet triples) in the language of ZOE. We have 0 1variablesx 1,...,x n,onepertriple,wherex i =1meansthatthe ith triple is chosen for the matching, and x i =0meansthatitisnotchosen. Now all we have to do is write equations stating that the solution described by the x i s is a legitimate matching. For each boy (or girl, or pet), suppose that the triples containing him (or her, or it) are those numbered j 1, j 2,...,j k;theappropriateequationisthen x j1 + x j2 + + x jk =1. 41 / 64 42 / 64 ZOE! Subset Sum ZOE! Subset Sum (cont d) This is a reduction between two special cases of LP: one with many equations but only 0 1coe cients, and the other with a single equation but arbitrary integer coe cients. The reduction is based on: 0 1vectorscanencodenumbers! We are looking for a set of columns of A that, added together, make up the all-1 s vector. But if we think of the columns as binary integers (read from top to bottom), we are looking for a subset of the integers corresponding to the columns of A that add up to the binary integer 11...1. And this is an instance of Subset Sum. Thereductionseemscomplete! Except for one detail: carry. Because of carry, say 5-bit binary integers can add up to 11111 = 31, for example, 5 + 6 + 20 = 31 or, in binary, 00101 + 00110 + 10100 = 11111, even when the sum of the corresponding vectors is not (1, 1, 1, 1, 1). But this is easy to fix: Think of the column vectors not as integers in base 2, but as integers in base n +1,onemorethanthenumberofcolumns. This way, since at most n integers are added, and all their digits are 0 and 1, there can be no carry, and our reduction works. 43 / 64 44 / 64

Special cases ZOE! LP 3Sat is a special case of Sat, or,sat is a generalization of 3Sat. By special case we mean that the instances of 3Sat are a subset of the instances of Sat (in particular, the ones with no long clauses), and the definition of solution is the same in both problems (an assignment satisfying all clauses). Consequently, there is a reduction from 3Sat to Sat, in which the input undergoes no transformation, and the solution to the target instance is also kept unchanged. n other words, functions f and h from the reduction diagram are both the identity. t is a very useful and common way of establishing that a problem is NP-complete: Simply notice that it is a generalization of a known NP-complete problem. For example, the Set Cover problem is NP-complete because it is a generalization of Vertex Cover. n LP we are looking for an integer vector x that satisfies Ax apple b, for given matrix A and vector b. To write an instance of ZOE in this precise form, we need to rewrite each equation of the ZOE instance as two inequalities, and to add for each variable x i the inequalities x i apple 1and x i apple 0. 45 / 64 46 / 64 ZOE! Rudrata Cycle Rudrata Cycle with Paired Edges n Rudrata Cycle we seek a cycle in a graph that visits every vertex exactly once. We shall prove it NP-complete in two stages: 1. First we will reduce ZOE to a generalization of Rudrata Cycle, called Rudrata Cycle with Paired Edges. 2. Then we shall see how to get rid of the extra features of that problem and reduce it to the plain Rudrata Cycle. We are given a graph G =(V, E) andasetc E E of pairs of edges. We seek a cycle that 1. visits all vertices once, 2. for every pair of edges (e, e 0 )inc, traverseseitheredgee or edge e 0 exactly one of them. Notice that we allow two or more parallel edges between two nodes, since now the di erent copies of an edge can be paired with other copies of edges in ways that do make a di erence. 47 / 64 48 / 64

ZOE! Rudrata Cycle with Paired Edges ZOE! Rudrata Cycle with Paired Edges (cont d) Given an instance of ZOE, Ax = 1 (where A is an m n matrix with 0 1 entries, and thus describes m equations in n variables), the graph we construct has the very simple structure: Acyclethatconnectsm + n collections of parallel edges. For each variable x i we have two parallel edges (corresponding to x i =1 and x i =0). for each equation x j1 + + x jk =1involvingk variables we have k parallel edges, one for every variable appearing in the equation. Any Rudrata cycle must traverse the m + n collections of parallel edges one by one, choosing one edge from each collection. This way, the cycle chooses for each variable a value 0 or 1 and, for each equation, a variable appearing in it. The structure of the matrix A (and not just its dimensions) must be reflected somewhere, and there is one place left: the set C of pairs of edges such that exactly one edge in each pair is traversed. For every equation (recall there are m in total), and for every variable x i appearing in it, we add to C the pair (e, e 0 )wheree is the edge corresponding to the appearance of x i in that particular equation, and e 0 is the edge corresponding to the variable assignment x i =0. This completes the construction. 49 / 64 50 / 64 ZOE! Rudrata Cycle with Paired Edges (cont d) Getting rid of the edge pairs Take any solution of this instance of Rudrata Cycle with Paired Edges. t picks a value for each variable and a variable for every equation. We claim that the values thus chosen are a solution to the original instance of ZOE. f a variable x i has value 1, then the edge x i =0isnottraversed,andthusall edges associated with x i on the equation side must be traversed, since they are paired in C with the x i =0edge. So, in each equation exactly one of the variables appearing in it has value 1, i.e., all equations are satisfied. The other direction is straightforward as well: from a solution to the instance of ZOE one easily obtains an appropriate Rudrata cycle. Consider the graph shown in Figure 8.12, and suppose that it is a part of a larger graph G in such a way that only the four endpoints a, b, c, d touch the rest of the graph. We claim that this graph has the following important property: in any Rudrata cycle of G the subgraph shown must be traversed in one of the two ways shown in bold in Figure 8.12(b) and (c). This gadget behaves just like two edges {a, b} and {c, d} that are paired up in the Rudrate Cycle with Paired Edges. 51 / 64 52 / 64

S. Dasgupta, C.H. Papadimitriou, and U.V. Vazirani 273 Rudrata Cycle with Paired Edges! Rudrata Cycle Figure 8.12 A gadget for enforcing paired behavior. (a) a c f l m s g k n r h j p q b d We go through the pairs in C one by one. To get rid of each pair {a, b}, {c, d} we replace the two edges with the gadget in Figure 8.12(a). (b) a c b d For any other pair in C that involves {a, b}, wereplacetheedge{a, b} with the new edge {a, f }, wheref is from the gadget: the traversal of {a, f } is from now on an indication that edge {a, b} in the old graph would be traversed. (c) a b Similarly, {c, h} replaces {c, d}. (d) c d After C such replacements (performed in polynomial time, since each replacement adds only 12 vertices to the graph) we are done. a c b d C = {({a, b}, {c, d})} The Rudrata cycles in the resulting graph will be in one-to-one correspondence with the Rudrata cycles in the original graph that conform to the constraints in C. 53 / 64 54 / 64 Rudrata Cycle! TSP Rudrata Cycle! TSP (cont d) Given a graph G =(V, E), construct the following instance of the TSP: The set of cities is the same as V. The distance between cities u and v is 1 if {u, v} is an edge of G and 1+ otherwise, for some > 1tobedetermined. The budget of the TSP instance is equal to the number of nodes, V. f G has a Rudrata cycle, then the same cycle is also a tour within the budget of the TSP instance. Conversely, if G has no Rudrata cycle, then there is no solution: the cheapest possible TSP tour has cost at least n + (it must use at least one edge of length 1 +, andthetotallengthofalln 1othersisatleastn 1). Thus Rudrata Cycle reduces to TSP. f =1,thenalldistancesareeither1or2,and so this instance of the TSP satisfies the triangle inequality: if i, j, k are cities, then d ij + d jk This is a special case of the TSP which is of practical importance and which, as we shall see in Chapter 9, is in a certain sense easier, because it can be e ciently approximated. d ik. 55 / 64 56 / 64

Rudrata Cycle! TSP (cont d) any problem in NP! Sat f is large, then the resulting instance of the TSP may not satisfy the triangle inequality, but has another important property: either it has a solution of cost n or less, or all its solutions have cost at least n + (which now can be arbitrarily larger than n). As we shall see in Chapter 9, this important gap property implies that, unless P = NP, no approximation algorithm is possible. First, we shall show that all problems in NPcan be reduced to a generalization of Sat, i.e.,circuit Sat. n Circuit Sat we are given a (Boolean) circuit, a dag whose vertices are gates of five di erent types: 1. AND gates and OR gates have indegree 2. 2. NOT gates have indegree 1. 3. Known input gates have no incoming edges and are labeled false or true. 4. Unknown input gates have no incoming edges and are labeled?. One of the sinks of the dag is designated as the output gate. 57 / 64 58 / 64 Circuit Sat Circuit Sat (cont d) Given an assignment of values to the unknown inputs, we can evaluate the gates of the circuit in topological order, using the rules of Boolean logic, until we obtain the value at the output gate. This is the value of the circuit for the particular assignment to the inputs. Circuit SAT: Given a circuit, find a truth assignment for the unknown inputs such that the output gate evaluates to true, or report that no such assignment exists. Circuit Sat is a generalization of Sat. Sat asks for a satisfying truth assignment for a circuit that has asimple structure: AbunchofAND gates at the top join the clauses, and the result of this big AND is the output. Each clause is the OR of its literals. Each literal is either an unknown input gate or the NOT of one. There are no known input gates. 59 / 64 60 / 64

Circuit Sat! Sat any problem in NP! Circuit Sat (informal) For each gate g we create a variable g, andwemodelthee ect of the gate using a few clauses: g = true: (g). g = false: (ḡ). g = h 1 OR h 2:(g _ h 1)(g _ h 2)(ḡ _ h 1 _ h 2). g = h 1 AND h 2:(ḡ _ h 1)(ḡ _ h 2)(g _ h 1 _ h 2). g = NOT h: (g _ h)(ḡ _ h). Let A be an NP-problem. We must discover a reduction from A to Circuit Sat. This sounds very di cult, because we know almost nothing about A! Recall: there is an algorithm C that checks, given an instance and a proposed solution S, whetherornots is a solution of. Moreover, C runs time polynomial in the length of (we can assume that S is itself encoded as a binary string, and we know that the length of this string is polynomial in the length of ). 61 / 64 62 / 64 any problem in NP! Circuit Sat (cont d) any problem in NP! Circuit Sat (cont d) Recall now our argument in Section 7.7 that any polynomial algorithm can be rendered as a circuit, whose input gates encode the input to the algorithm. For any input length (number of input bits) the circuit will be scaled to the appropriate number of inputs, but the total number of gates of the circuit will be polynomial in the number of inputs. f the polynomial algorithm in question solves a problem that requires a yes or no answer, as is the situation with C: Does S encode a solution to the instance encoded by? then this answer is given at the output gate. We conclude that, given any instance of problem A, wecanconstructin polynomial time a circuit: the known inputs are the bits of, the unknown inputs are the bits of S, the output is true if and only if the unknown inputs spell a solution S of. n other words, the satisfying truth assignments to the unknown inputs of the circuit are in one-to-one correspondence with the solutions of instance of A. The reduction is complete. 63 / 64 64 / 64