CMPSCI611: The SUBSET-SUM Problem Lecture 18

Similar documents
Computability Theory

NP-Complete Reductions 2

Theorem 2.9: nearest addition algorithm

NP-Completeness. Algorithms

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

Chapter 8. NP-complete problems

8.1 Polynomial-Time Reductions

W4231: Analysis of Algorithms

Some Hardness Proofs

CSC 505, Fall 2000: Week 12

NP-complete Reductions

Prove, where is known to be NP-complete. The following problems are NP-Complete:

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

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

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

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

8 NP-complete problem Hard problems: demo

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

Chapter 9 Graph Algorithms

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

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

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

1 Definition of Reduction

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

NP and computational intractability. Kleinberg and Tardos, chapter 8

Chapter 9 Graph Algorithms

8.1 Polynomial-Time Reductions

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

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

PCP and Hardness of Approximation

Where Can We Draw The Line?

Module 6 NP-Complete Problems and Heuristics

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

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

Module 6 NP-Complete Problems and Heuristics

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

Chapter 9 Graph Algorithms

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

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

Notes for Lecture 24

P and NP (Millenium problem)

Vertex Cover Approximations

COMP260 Spring 2014 Notes: February 4th

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

Homework 4 Solutions

CS270 Combinatorial Algorithms & Data Structures Spring Lecture 19:

Module 6 NP-Complete Problems and Heuristics

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

Approximation Algorithms

Chapter 10 Part 1: Reduction

Lecture 21: Other Reductions Steven Skiena. Department of Computer Science State University of New York Stony Brook, NY

Lecture 7: Counting classes

Complexity Classes and Polynomial-time Reductions

arxiv: v2 [cs.cc] 29 Mar 2010

CS521 \ Notes for the Final Exam

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

APPROXIMATION ALGORITHMS FOR GEOMETRIC PROBLEMS

1 Introduction. 1. Prove the problem lies in the class NP. 2. Find an NP-complete problem that reduces to it.

Chapter 5 Graph Algorithms Algorithm Theory WS 2012/13 Fabian Kuhn

CS154, Lecture 18: PCPs, Hardness of Approximation, Approximation-Preserving Reductions, Interactive Proofs, Zero-Knowledge, Cold Fusion, Peace in

Solutions for the Exam 6 January 2014

15-451/651: Design & Analysis of Algorithms November 4, 2015 Lecture #18 last changed: November 22, 2015

Introduction to Graph Theory

Approximation Algorithms

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

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

Outline. CS38 Introduction to Algorithms. Approximation Algorithms. Optimization Problems. Set Cover. Set cover 5/29/2014. coping with intractibility

CMPSCI611: Approximating SET-COVER Lecture 21

V1.0: Seth Gilbert, V1.1: Steven Halim August 30, Abstract. d(e), and we assume that the distance function is non-negative (i.e., d(x, y) 0).

CPSC 536N: Randomized Algorithms Term 2. Lecture 10

Greedy Algorithms 1. For large values of d, brute force search is not feasible because there are 2 d

Chapter 8. NP-complete problems

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

Theory of Computing. Lecture 10 MAS 714 Hartmut Klauck

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

Graphs and trees come up everywhere. We can view the internet as a graph (in many ways) Web search views web pages as a graph

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

Graphs. Edges may be directed (from u to v) or undirected. Undirected edge eqvt to pair of directed edges

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

1 Better Approximation of the Traveling Salesman

6.2. Paths and Cycles

Matching 4/21/2016. Bipartite Matching. 3330: Algorithms. First Try. Maximum Matching. Key Questions. Existence of Perfect Matching

Questions... How does one show the first problem is NP-complete? What goes on in a reduction? How hard are NP-complete problems?

MITOCW watch?v=zm5mw5nkzjg

Introduction III. Graphs. Motivations I. Introduction IV

Recitation 4: Elimination algorithm, reconstituted graph, triangulation

Lecture 21: Other Reductions Steven Skiena

Math 776 Graph Theory Lecture Note 1 Basic concepts

CS 125 Section #10 Midterm 2 Review 11/5/14

(p 300) Theorem 7.27 SAT is in P iff P=NP

NP-Hard (A) (B) (C) (D) 3 n 2 n TSP-Min any Instance V, E Question: Hamiltonian Cycle TSP V, n 22 n E u, v V H

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

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

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

Introduction to Algorithms. Lecture 24. Prof. Patrick Jaillet

8 Matroid Intersection

PACKING DIGRAPHS WITH DIRECTED CLOSED TRAILS

1 Variations of the Traveling Salesman Problem

Lecture 8: The Traveling Salesman Problem

Transcription:

CMPSCI611: The SUBSET-SUM Problem Lecture 18 We begin today with the problem we didn t get to at the end of last lecture the SUBSET-SUM problem, which we also saw back in Lecture 8. The input to SUBSET- SUM is a set of numbers {a 1,..., a n } and a target number t, and we ask whether there is a subset of the numbers that add exactly to t. Using dynamic programming, we showed that we could decide this language in time that is polynomial in n and s, the sum of all the a i. Now we allow the numbers to get larger, so that they now might be n bits long. The problem is still in NP, because we can guess a subset by guessing a bitvector, add the numbers in the set, and verify that we get t. But it s no longer clear that we are in P, and in fact we will now see that the general problem is NP-complete. We reduce 3-SAT to SUBSET-SUM (with large numbers). We first assume that every clause in our input formula has exactly three literals we can just repeat literals in the same clause to make this true. Our numbers will be represented in decimal notation, with a column for each of the v variables and a column for each clause in the formula. 1

We ll create an item a i for each of the 2v literals. This item will have a 1 in the column for its variable, a 1 in the column of each clause where the literal appears, and zeroes everywhere else. We also have two items for each clause, each with a 1 in the column for that clause and zeroes everywhere else. The target number has a 1 for each variable column and a 3 for each clause column. We now have to prove that there is a subset summing to the target iff the formula is satisfiable. If there is a satisfying assignment, we choose the item for each literal in that assignment. This has one 1 in each variable column, and somewhere from one to three 1 s in each clause column. Using extra items as needed, we can reach the target. Conversely, if we reach the target we must have chosen one item with a 1 in each variable column, so we have picked v variables forming an assignment. Since we have three 1 s in each clause column and at most two came from the extra items, we must have at least one 1 in each clause column from our assignment, making it a satisfying assignment. 2

Given a problem with numerical parameters, we say that it is pseudopolynomial if it becomes polynomial when those parameters are given in unary. If it is NP-complete with parameters given in unary, we say that it is strongly NP-complete. The SUBSET-SUM problem is pseudopolynomial, but all our graph problems are strongly NP-complete. Recall that the KNAPSACK problem is similar to SUBSET- SUM but has a value for each item as well as its weight. We are asked to find whether a set of at least a given value exists with at most a given weight. Since SUBSET-SUM is an identifiable special case of KNAPSACK (where weight and value are both equal), we know that SUBSET-SUM p KNAPSACK. Since KNAPSACK (as a decision problem) is in NP, it is NP-complete. The associated optimization problem is thus NP-hard. 3

CMPSCI611: The MAX-CUT Problem Lecture 18 Earlier we looked at the problem of taking an undirected graph and finding the minimum cut in it a partition of the vertices into two sets such that the number of edges with one endpoint in each set was as small as possible. We solved this in polynomial time in two different ways using the network flow algorithm to find the minimum cut between one vertex s and each other vertex t, then taking the minimum over all t, and Karger s randomized algorithm. What about the problem of finding the maximum cut? For example, each edge might represent a difference between two objects, and we might want to divide the objects in two so as to maximize the number of differnences. Despite the obvious similarity to the min-cut problem, finding the maximum cut (as an optimization problem) is NP-hard. In particular, the language MAX-CUT, the set of all pairs (G, k) where G has a cut of size at least k, is NP-complete. 4

Once again it is clear that this decision problem is in NP. We can guess a partition (as a bitvector of length n), count the edges between the two sets, and accept if the number is at least k. To prove MAX-CUT is NPcomplete, we will reduce from NAE-3-SAT, one of the problems we proved to be NP-complete last lecture. Remember that NAE-3-SAT is the set of 3-CNF formulas ϕ for which there exists a setting of the variables giving each clause either one or two true literals, not either zero or four. (The initials stand for not all equal 3-SAT.) So given such a ϕ, we need to produce a graph G and a number k such that G has a cut of size k iff ϕ is NAEsatisfiable. 5

Before we begin, we make two modifications to ϕ if necessary: If any clause contains both a literal l and its negation l, we delete it it was guaranteed to be satisfied anyway. If any two clauses share two of there three literals, we replace them by four clauses, introducing two new variables, that don t have this property and are NAEsatisfiable iff the original two clauses were. In particular, if (a b c) and (a b d) are both clauses, we replace them by (a b c), (a x d), (b x y), and ( b x y). Whichever way y is set, NAE-satisfying the last two clauses forces x to be set the same way as b. 6

Now we can construct our graph. Say that ϕ, as modified, has v variables and m clauses. G will have 2v vertices, one for each literal. It will have v + 3m edges: An edge between l and l for each literal l (v edges), and A triangle of edges connecting the three literals of each clause. Our conditions on ϕ mean that no edge is added both ways, and no two of the triangles share an edge. Finally, we set k to be v + 2m. We must prove that ϕ is NAE-satisfiable iff G has a cut of size at least k. First assume that there is a setting that NAE-satisfies ϕ. We look at the cut that separates the true literals of this setting from the false literals. Every one of the v negation edges goes across this cut. Every triangle in G consists of either two true literals and one false one, or two false and one true. Thus exactly two of the three edges of the triangle cross the cut. So the number of edges crossing the cut is exactly v + 2m, or k. 7

Now assume that we have a partition of the 2v vertices into two sets such that there are k edges across the cut. We must prove that there is a setting of the variables that NAE-satisfies all the clauses. Look at the two categories of edges: The only way that all of the v negation edges cross the cut is if each pair of literals is divided between the two sets, so that each set has v literals from different variables and thus represents a setting of the variables. Each of the m triangles has either zero edges crossing the cut, if all three nodes are in the same set, or two edges crossing it, if the three nodes are split two and one. Thus the maximum possible number of edges crossing the cut is v+2m, and this is achieved only if the cut represents a setting, and this setting contains either one or two literals from each clause. This is exactly the definition of NAE-satisfying ϕ. (Note that if a setting NAE-satisfies ϕ, so does the setting obtained by negating all its literals.) We have completed the reduction and shown that NAE- 3-SAT p MAX-CUT and therefore that MAX-CUT is NP-complete. 8

On HW#4 you will consider the related MAX-BISECTION and MIN-BISECTION problems, which are similar to MAX-CUT and MIN-CUT except that in the bisection problems the cut is required to have an equal number of vertices in each set. 9

CMPSCI611: Three-Dimensional Matching Lecture 18 We now turn to an important NP-complete problem, THREE- DIMENSIONAL-MATCHING (3DM). This problem is useful as a base for reductions, is an identifiable special case of a number of other problems, and has an interesting NP-completeness proof. Let X, Y, and Z be disjoint sets of n elements each, and let T be a set of triples in X Y Z. The 3DM problem is the set of tuples (X, Y, Z, T ) such that there is a set of n triples in T that together include each item in X, Y, and Z exactly once. The 3DM problem generalizes the bipartite perfect matching problem, which we know to be in P. There we have two sets X and Y of size n and a set of edges that can be viewed as a subset of X Y, and we want a set of n edges that together include every vertex. Clearly 3DM is in NP. We will prove it to be NP-complete by reducing 3-SAT to it. 10

Let ϕ be a 3-CNF formula with m clauses and v variables. We ll set up a set S of 6mv elements and a bunch of three-element subsets of this set, such that we can make S the union of exactly 2mv 3-sets iff ϕ is satsifiable. This is actually an instance of the related EXACT- COVER-BY-3-SETS problem later we ll divide S into X, Y, and Z and make our 3-sets into triples. The elements of S are as follows: 4m elements for each variable, a core of 2mv elements and 2mv others called tips. As I ll show on the board, we ll think of the core as arranged in a circle, with the tips in another circle outside it. A pair of clause elements for each clause, 2m in all. m(v 1) pairs of cleanup elements, making 2m(v 1) in all. 11

Now to define the 3-sets in T : Two sets of m 3-sets for each variable. One set covers the core elements and the odd-numbered tips, the other the core elements and the even-numbered tips. There is no way to cover the whole core without taking either one set or the other. Covering the odds will correspond to setting that variable true, covering the evens to setting it false. For each clause C i = (l 1 l 2 l 3 ), we have three 3- set, each one covering the two clause elements and a tip corresponding to one of the l s. If l j is the variable x k, for example, the corresponding tip is the 2i th tip for variable x k. If l j is x k, the corresponding tip is the 2i + 1 st. For each cleanup clause and each tip, we have a 3-set containing those three elements. 12

We ll sketch the proof that a successful cover of all the elements by 3-sets in T corresponds to an assignment that satisfies ϕ. Suppose we have the asignment. We choose sets to cover the core elements for each variable as described above, leaving either all the odd tips or all the even tips uncovered. For each clause, we pick a literal that is assigned to be true and choose the 3-set that covers the two clause elements and the corresponding tip (which is uncovered because of the assignment). Then we cover the other tips and the cleanup elements with the 3-sets that include the cleanup elements. Conversely, suppose we have a successful covering. To cover all the core elements, we must in effect pick an assignment to the variables. To cover the clause elements, we must also cover n tips, in such a way that the tips chosen correspond to literals that are set to true. This gives us a satisfying assignment. The clause and core elements can be covered in no other way, so the assignment must exist if the covering does. Finally, we split S into X, Y, and Z to make these 3- sets into triples. Z is exactly the set of tips. The clause element and cleanup element pairs each have one element of X and one of Y. The core elements are alternatively from X and from Y, as I ll show on the board. 13

Here are some of the related problems that can be shown to be NP-complete by reduction from 3DM: SET-COVER: Given S and a collection of subsets of S, and a number k, is there a collection of k of the subsets that union together to give S? SET-PACKING: Given S, a collection of subsets, and k, is there a pairwise disjoint collection of k of the subsets? EXACT-COVER-BY-3-SETS: As above. PARTITION-INTO-TRIANGLES: Given an undirected graph with 3n vertices, is there a set of n disjoint triangles in the graph that include all the vertices? PARTITION-INTO-2-PATHS: Given an undirected graph with 3n vertices, are there n vertex disjoint paths of length 2 that together include all the vertices? STEINER-TREE: Given a weighted graph, a division of the vertices into required and optional, and a target cost, is there a tree that includes all the required vertices and has total cost less than the target? 14

Clearly all these problems are in NP. For many of them problems, 3DM is an identifiable special case and so the reduction just uses the identity map. In the other cases, except for STEINER-TREE, the reduction is simple. STEINER-TREE is an extension of MST MST is the identifiable special case where there are no optional vertices. The Steiner tree problem is extensively studied as a geometric problem, where the edge weights are distances in the plane. It is also NP-complete in the geometric version, with either Euclidean or Manhattan distances. 15

CMPSCI611: More NP-Complete Problems Lecture 18 We can arrange known NP-complete functions in a tree, based on the reductions used to prove them NP-complete. At the end of Chapter 7, the Adler notes have such a tree (unreadable in the original version of the notes). We ll repeat it here and discuss some of the problems: 3-SAT p NAE-3-SAT p MAX-CUT p MIN-BISECTION p MAX-BISECTION 3-SAT p CLIQUE p IND-SET p VERTEX-COVER p HAM-CYCLE p LONGEST-PATH HAM-CYCLE p TSP 3-SAT p SUBSET-SUM p KNAPSACK 3-SAT p 3DM p STEINER-TREE Of course there exists a reduction from any NP-complete problem to any other, so a tree like this only represents a choice as to which reductions are easier. In the rest of this lecture, we ll look at some of the problems on this list. In many cases, we have pairs of similar problems, one of which is in P and the other of which is NP-complete. 16

We ve mentioned MAX-CUT (NP-complete) and MIN- CUT (in P). The HAM-CYCLE problem asks whether there is a cycle that contains all the vertices. This contrasts with EULER- CYCLE, where the cycle (in a multigraph) must contain all edges. The latter is in P. The problem of finding a LONGEST-PATH from s to t in an undirected graph is easily proved to be NP-complete by reduction from HAM-CYCLE. By contrast, we can find a SHORTEST-PATH in P by breadth-first or matrix powering. The famous TRAVELING-SALESPERSON (TSP) problem is easily proved NP-complete (or NP-hard as an optimization problem) by reduction from HAM-CYCLE. Sometimes the parameter of a problem is very important. While 3-SAT and 3DM are NP-complete, we have seen that 2DM is in P and 2-SAT is easily proved so. EDGE-COVER, where we ask for a minimum-sized set of edges to cover every vertex, is in P, in contrast with VERTEX-COVER. Finally, MST generalizes to the NPcomplete STEINER-TREE problem. 17