ECS122A Handout on NP-Completeness March 12, 2018

Similar documents
VIII. NP-completeness

1. Introduction Recap

4. How to prove a problem is NPC

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

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

NP-Complete Problems and Approximation Algorithms

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

INTRO TO COMPUTATIONAL COMPLEXITY

Algorithms Design & Analysis. Approximation Algorithm

CS 583: Algorithms. NP Completeness Ch 34. Intractability

1.1 P, NP, and NP-complete

Tractable & Intractable Problems

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

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

Computer Science 385 Analysis of Algorithms Siena College Spring Topic Notes: Limitations of Algorithms

NP-Completeness. CptS 223 Advanced Data Structures. Larry Holder School of Electrical Engineering and Computer Science Washington State University

Data Structures in Java

Computational Complexity and Intractability: An Introduction to the Theory of NP. Chapter 9

NP Completeness and Approximation Algorithms

CS/COE

Limitations of Algorithm Power

NP Complete Problems. COMP 215 Lecture 20

Polynomial-time Reductions

Notes for Lecture 21

NP-Complete problems

NP-Completeness. NP-Completeness 1

CMSC 441: Algorithms. NP Completeness

NP and Computational Intractability

DESIGN AND ANALYSIS OF ALGORITHMS. Unit 6 Chapter 17 TRACTABLE AND NON-TRACTABLE PROBLEMS

Unit 6 Chapter 17 TRACTABLE AND NON-TRACTABLE PROBLEMS

Lecture 24: How to become Famous with P and NP

NP-completeness. Chapter 34. Sergey Bereg

CSC 1700 Analysis of Algorithms: P and NP Problems

Lecture 18: P & NP. Revised, May 1, CLRS, pp

NP-Completeness. Until now we have been designing algorithms for specific problems

Computational Intractability 2010/4/15. Lecture 2

COP 4531 Complexity & Analysis of Data Structures & Algorithms

Unit 1A: Computational Complexity

NP and Computational Intractability

Data Structures and Algorithms (CSCI 340)

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

Analysis of Algorithms. Unit 5 - Intractable Problems

NP-Completeness. Subhash Suri. May 15, 2018

Lecture 4: NP and computational intractability

In complexity theory, algorithms and problems are classified by the growth order of computation time as a function of instance size.

Computational Complexity. IE 496 Lecture 6. Dr. Ted Ralphs

8.5 Sequencing Problems

Algorithms: COMP3121/3821/9101/9801

Polynomial-Time Reductions

Correctness of Dijkstra s algorithm

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

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

Chapter 34: NP-Completeness

P and NP. Warm Up: Super Hard Problems. Overview. Problem Classification. Tools for classifying problems according to relative hardness.

Introduction. Pvs.NPExample

Design and Analysis of Algorithms

Announcements. Friday Four Square! Problem Set 8 due right now. Problem Set 9 out, due next Friday at 2:15PM. Did you lose a phone in my office?

SAT, Coloring, Hamiltonian Cycle, TSP

NP-Complete Problems. More reductions

Recap from Last Time

Lecture 15 - NP Completeness 1

P vs. NP. Data Structures and Algorithms CSE AU 1

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

July 18, Approximation Algorithms (Travelling Salesman Problem)

Computational Complexity

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

NP-complete problems. CSE 101: Design and Analysis of Algorithms Lecture 20

P,NP, NP-Hard and NP-Complete

NP-Complete Reductions 2

Spring Lecture 21 NP-Complete Problems

Computational Complexity

NP Completeness and Approximation Algorithms

Polynomial-time reductions. We have seen several reductions:

Computational Complexity

CSC 8301 Design & Analysis of Algorithms: Lower Bounds

Problem Complexity Classes

NP-Completeness. f(n) \ n n sec sec sec. n sec 24.3 sec 5.2 mins. 2 n sec 17.9 mins 35.

NP-Complete Reductions 1

Algorithm Design and Analysis

FINAL EXAM PRACTICE PROBLEMS CMSC 451 (Spring 2016)

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

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

P, NP, NP-Complete, and NPhard

COMP/MATH 300 Topics for Spring 2017 June 5, Review and Regular Languages

Tractability. Some problems are intractable: as they grow large, we are unable to solve them in reasonable time What constitutes reasonable time?

Graph Theory and Optimization Computational Complexity (in brief)

Introduction to Complexity Theory

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

Chapter 8. NP and Computational Intractability

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

NP-problems continued

P and NP. Inge Li Gørtz. Thank you to Kevin Wayne, Philip Bille and Paul Fischer for inspiration to slides

Lecture 14 - P v.s. NP 1

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

Outline. 1 NP-Completeness Theory. 2 Limitation of Computation. 3 Examples. 4 Decision Problems. 5 Verification Algorithm

Algorithm Design Strategies V

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

Chapter 3: Proving NP-completeness Results

Formal definition of P

Transcription:

ECS122A Handout on NP-Completeness March 12, 2018 Contents: I. Introduction II. P and NP III. NP-complete IV. How to prove a problem is NP-complete V. How to solve a NP-complete problem: approximate algorithms I. Introduction 1. Tractable (easy, not-so-hard ) and intractable ( hard ) problems Generally, we think of problems that are solvable by polynomial-time algorithms are being tractable, and problems that require superpolynomial time as being intractable. Almost all the algorithms we have studied thus far have been polynomial-time algorithms: on inputs of size n, their worst-case running time is O(n k ) for some constant k. 2. We now turn to a class of problems, called the NP-complete problems, which is a class of very diverse problems, that share the following properties: we only know how to solve those problems in time much larger than polynomial, namely exponential time, and if we could solve one NP-complete problem in polynomial time, then there is a way to solve every NP-complete porblem in polynomial time. 3. Two reasons to study NP-complete porblems: (a) The practical one is that if you recognize that a problem is NP-complete, then you have three choices: you can use a known algorithm for it, and accept that it will take a long long time to solve; you can settle for approximating the solution, e.g., finding a nearly best solution rather than the optimum; or you can change your problem formulation so that it is solvable in polynomial time. (b) One of the most famous open problem in computer science concerns the NP-complete problem. We stated above that we only know how to solve those problems in time much larger than polynomial, not that we have proven that NP-complete problems require exponential time. Indeed, this is a million-dollar question 1, one of the most famous problem in computer science, the question is whether P = NP?, or whether the class of NP-complete problems have polynomial solutions (first posed in 1971). 1 http://www.claymath.org/millennium-problems 1

4. A particular tantalizing aspect of the NP-complete problems is that several of them seem on the surface to be similar problems that have polynomial-time algorithms. In each of the following pairs of problems, one is solvable in polynomial time, and the other is NP-complete, but the difference between problems appears to be slight: Shortest vs. Longest simple paths: Shortest path: finding the shortest path from a single source in a directed graph. Longest path: finding the longest simple path between two vertices in a directed graph. Euler cycle vs Hamiltonian cycle Euler cycle: given a connected, directed graph G, is there a cycle that visits each edge exactly once (although it is allowed to visit each vertex more than once)? Hamiltonian cycle: given a directed graph G, is there a simple cycle that visits each vertex exactly once? Minimum Spanning Tree (MST) vs. Traveling Salesperson Problem (TSP) MST: given a weighted graph and an integer k, is there a spanning tree whose total weight is k or less? TSP: given a weighted graph and an integer k, is there a cycle that visits all vertices exactly once of the graph whose total weight is k or less? Circuit value vs Circuit satisfiability Circuit value: given a Boolean formula and its input, is the output True? Circuit satisfiability: given a Boolean formula, is there a way to set the inputs so that the output is True? 5. Optimization problems vs. Decision problems Most of problems occur naturally as optimization problems, but they can also be formulated as decision problems, that is, problems for which the output is a simple Yes or No answer for each input. Examples: Graph coloring: a coloring of a graph G = (V, E) is a mapping C : V S, where S is a finite set of colors, such that if (u, v) E, then C(u) C(v). Optimization problem: given G, determine the smallest number of colors needed. Decision problem: given G and a positive integer k, is there a coloring of G using at most k colors? If so, G is said to be k-colorable. Hamiltonian cycle: Decision problem: Does a given graph have a Hamiltonian cycle? Optimization problem: Give a list of vertices of a Hamiltonian cycle. TSP (Traveling Salesperson Problem): Optimization problem: given a weighted graph, find a minimum Hamiltonian cycle. 2

Decision problem: given a weighted graph and an integer k, is there a Hamiltonian cycle with total weight at most k? To simplify the discussion, we can consider only the decision problems with Yes-No answers, rather than the optimization problems. The optimization problems are at least as hard to solve as the related decision problems, we have not lost anything essential by doing so. II. P and NP 1. P is the class of decision problems that can be solved in polynomial time, i.e., they are polynomial bounded. An algorithm is said to polynomial bounded if its worst-case complexity is bounded by a polynomial function of the input size, i.e. T (n) = O(n k ). Examples: Shortest path, MST, Euler tour, Circuit value. 2. NP is the class of decision problems that are verifiable in polynomial time. What we mean here is that if we were somehow given a certificate (= a solution), then we could verify that the certificate is correct in time polynomial in the size of input to the problem. NP stands for Nondeterministic Polynomial time Examples: Longest path, TSP, Hamiltonian cycle, Circuit satisfiability, graph coloring. 3. P NP, since if a problem is in P then we can solve it in polynomial time without even being given a certificate. 4. Open question: Does P = NP or P NP? 5. The size of the input can also change the classification of P or NP. Knowing the effect on complexity of restricting the set of inputs for a problem is important. Examples: Prime-testing problem Knapsack problem Remark: Unfortunately, even with quite strong restrictions on the inputs, many NPcomplete problems are still NP-complete. For example, 3-Conjuntive Normal Form (3- CNF) satisfiability problem. III. NP-complete 1. NP-complete is the term used to describe decision problems that are the hardest ones in NP in the sense that, if there were a polynomial-bounded algorithm for an NP-complete problem, then there would be a polynomial-bounded time for each problem in NP. 2. Polynomial reduction Let A and B be two decision problems, we say that A is polynomially reducible to B, denoted as A T B, if there is a poly-time computable function T such that Yes-instance of A Yes-instance of B 3

3. Formal definition of NP-complete A decision problem A is NP-complete (NPC) if (1) A NP and (2) every (other) problems A in NP is reducible to A. 4. A first NP-complete problem: The circuit satisfiability (circuit-sat) problem is NPcomplete This is the famous Cook s theorem (1971), which is the first major theorem deomonstrating that a specific problem is NP-complete. 5. Theorem: Graph coloring, Hamiltonian cycle, TSP,... are all NP-complete. 6. How most theoretical computer scientists view the relationships among P, NP and NPC. Both P and NPC are wholely contained within NP, and P NPC =. 7. If a problem satisfies the property (2), but not necessarily the property (1), we say the problem is NP-hard It is important to realize that NP-hard does not mean in NP and hard. It means at least as hard as any problem in NP. Thus a problem can be NP-hard and not be in NP. IV. How to prove a problem is NP-complete? 1. Since the reducibility relation is transitive, to prove that a problem A in NP is NPcomplete, it suffices to prove that some other NP-complete problem B is polynomially reducible to it. Specifically, choose some known NP-complete problem B, and reduce B to A (note: not the other way around!), i.e., show that The logic is as follows: B T A Since B is NP-complete, all problems in NP is reducible to B. Show B is reducible to A. Then all problems in NP is reducible to A. Therefore, A is NP-complete 2. Example 1. The directed Hamiltonian cycle (HC) problem is known to be NP-complete. In the following, we show that the directed HC problem is reducible to the undirected HC problem. Therefore, we conclude that the undirected HC problem is also NP-complete. 4

Proof: Let G = (V, E) be a directed graph with n vertices. G is transformed into the undirected graph G = (V, E ) by the transform function T defined as the following: and v V v 1, v 2, v 3 V and (v 1, v 2 ), (v 2, v 3 ) E. Clearly, T is polynomial-time computable. We now show that (u, v) E (u 3, v 1 ) E. G has a HC G has a HC. = : Suppose that G has a directed HC, v 1, v 2,..., v n, v 1. Then is an undirected HC for G. v 1 1, v 2 1, v 3 1, v 1 2, v 2 2, v 3 2,..., v 1 n, v 2 n, v 3 n, v 1 1 = : Suppose that G has an undirected HC, the three vertices, say v 1, v 2, v 3 that correspond to one vertex from G must be traversed consecutively in the order v 1, v 2, v 3 or v 3, v 2, v 1, since v 2 cannot be reached from any other vertex in G. Since the other edges in G connect vertices with superscripts 1 or 3, if for any one triple the order of the superscripts is 1, 2, 3, then the order is 1, 2, 3 for all triples. Otherwise, it is 3, 2, 1 for all triples. Since G is undirected, we may assume that its HC is v 1 i 1, v 2 i 1, v 3 i 1, v 1 i 2, v 2 i 2, v 3 i 2,..., v 1 i n, v 2 i n, v 3 i n, v 1 i 1. Then v i1, v i2,..., v in, v i1 is a directed HC for G. 3. Example 2: The subset sum problem is known to be NP-complete, In the following, we show that the subset sum problem is reducible to the job scheduling (with penalties) problem. Therefore, we conclude that the problem of job scheduling with penalties is also NP-complete. Subset sum decision problem: Given a positive integer C, and the set S = {s 1, s 2,..., s n } of positive integers s i for i = 1, 2,..., n. Assume that n s i C. Is there a J {1, 2,..., n} such that i J s i = C? Job-Scheduling decision problem: Suppose there are n jobs J 1, J 2,..., J n to be executed one at a time, each takes t i time, deadline d i and penalties p i for missing the deadline. A schedule for the jobs is to find a permutation π of {1, 2,..., n}, such that the jobs are executed in the order J π(1), J π(2),..., J π(n). The corresponding total penalty is P π = where P π(j) = P π(j) j=1 { pπ(j) if t π(1) + + t π(j) > d π(j) 0 otherwise The decision problem: given k, is there a schedule such that P π(j) k? 5

We show that the subset sum problem is reducible to the job scheduling problem. Proof: Let s 1, s 2,..., s n and C be an input for the subset sum problem. Let the input be transformed into the following input for the job scheduling problem t i = p i = s i for 1 i n, d i = C for 1 i n, k = s i C. Clearly the transformation takes polynomial time. Now we shows that Yes-instance of the subset sum Yes-instance of the job scheduling. = : suppose that the subset sum input produces a YES answer; i.e., there is a subset J of N = {1, 2,..., n} such that i J s i = C. Then let π be any permutation of N that causes all jobs with indices in J to be done before any job with indices in N J. The first J jobs are completed by their deadline since i J t i = i J s i = C and C is the deadline for all jobs. Then the total penalty J P π = p π(j) + j=1 p π(j) = 0 + p π(j) = s π(j) = s j C = k. j= J +1 j= J +1 j= J +1 j=1 Thus the jobs can be done with total penalty k. = Let π be any schedule for the jobs with total penalty k. Let m be largest such that m t π(i) C; (1) i.e., m is the number of jobs completed by the deadline C. The penalty, then, is p π(i) k = s i C. (2) i=m+1 Since t i = p i = s i for all 1 i n, we must have m t π(i) + m p π(i) = s π(i) + s π(i) = s i, i=m+1 i=m+1 and this can happen only if the inequalities in (1) and (2) are equalities. Thus m t π(i) = C, so the objects with indices π(1), π(2),..., π(m) are a solution to the subset sum problem. 6

V. Approximation Algorithms 1. What can we do when we encounters an NP-complete problem? We have three choices: (a) You can use a known algorithm for it, and accept that it will take a long time to solve if n is large. (b) You can settle for approximating the solution, e.g., finding a nearly best solution rather than the optimum. (c) You can change your problem formulation so that it is in P, rather than being NPcomplete, for example, by restricting it to work only on a subset of simpler input problems. We will show how to get near-optimal solutions in polynomial time. In practice, nearoptimality is often good enough. 2. Apprixmate algorithms for Bin Packing Problem Problem statement: suppose we have an unlimited number of bins, each of capacity 1, and n objects with sizes s 1, s 2,..., s n, where 0 < s i 1. Decision problem: Do the objects fit in k bins? Optimization problem: Determine the smallest number of bins into which the objects can be packed and find an optimal packing. Theorem: The bin-packing problem is NP-complete. Approximate algorithm: First-fit strategy (greedy): places an object in the first bin into which it fits. Example: Objects = {0.8, 0.5, 0.4, 0.4, 0.3,,, } Approximate Algorithm solution: B 1 0.8 B 2 0.4 0.5 B 3 0.3 0.4 B 4 Optimal packing: B 1 0.8 B 2 0.3 0.5 B 3 0.4 0.4 Theorem: Let S = s i. (a) The optimal number of bins required is at least S (b) The number of bins used by the first-fit strategy is never more than 2S. 7

3. Apprixmate algorithms for Vertex-Cover Problem Problem statement: a vertex-cover of an undirected graph G = (V, E) is a subset of V V such that if the edge (u, v) E, then u V or v V (or both). In other words, a vertex cover for G is a set of vertices that covers all edges in E. The size of a vertex cover is the number of vertices in it. Optimization problem: find a vertex cover of minimum size. Decision problem: determine whether a graph has a vertex cover of a given size k. Theorem: The vertex-cover problem is NP-complete. Approximate algorithm C = E = E while E let (u, v) be an arbitrary edge of E C = C {u, v} remove from E every edge incident on either u or v. endwhile return C Theorem. The size of the vertex-cover is no more than twice the size of an optimal vertex cover. 8