COP 4531 Complexity & Analysis of Data Structures & Algorithms

Similar documents
NP and Computational Intractability

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

Algorithm Design and Analysis

Algorithms Design & Analysis. Approximation Algorithm

Announcements. Analysis of Algorithms

Algorithm Design and Analysis

Intro to Theory of Computation

Polynomial-Time Reductions

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

Algorithm Design and Analysis

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

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

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

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

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

Intro to Theory of Computation

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

Computational Intractability 2010/4/15. Lecture 2

CS 583: Algorithms. NP Completeness Ch 34. Intractability

NP and Computational Intractability

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

Approximation and Randomized Algorithms (ARA) Lecture 2, September 1, 2010

CS 580: Algorithm Design and Analysis

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

NP completeness and computational tractability Part II

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

SAT, NP, NP-Completeness

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

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

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

Chapter 2. Reductions and NP. 2.1 Reductions Continued The Satisfiability Problem (SAT) SAT 3SAT. CS 573: Algorithms, Fall 2013 August 29, 2013

SAT, Coloring, Hamiltonian Cycle, TSP

Lecture 4: NP and computational intractability

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

1. Introduction Recap

More NP-Complete Problems

8.5 Sequencing Problems

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

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

NP and NP Completeness

7.8: Intractability. Overview. Exponential Growth. Properties of Algorithms. What is an algorithm? Turing machine.

10.3: Intractability. Overview. Exponential Growth. Properties of Algorithms. What is an algorithm? Turing machine.

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

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?

Design and Analysis of Algorithms

1.1 P, NP, and NP-complete

CSC 373: Algorithm Design and Analysis Lecture 15

NP Completeness and Approximation Algorithms

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

Chapter 8. NP and Computational Intractability

NP Complete Problems. COMP 215 Lecture 20

Algorithms 6.5 REDUCTIONS. designing algorithms establishing lower bounds classifying problems intractability

A difficult problem. ! Given: A set of N cities and $M for gas. Problem: Does a traveling salesperson have enough $ for gas to visit all the cities?

P, NP, NP-Complete, and NPhard

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

CSE 421 NP-Completeness

COMP Analysis of Algorithms & Data Structures

Computability and Complexity Theory: An Introduction

NP-Completeness. Subhash Suri. May 15, 2018

Intractability. A difficult problem. Exponential Growth. A Reasonable Question about Algorithms !!!!!!!!!! Traveling salesperson problem (TSP)

Harvard CS 121 and CSCI E-121 Lecture 22: The P vs. NP Question and NP-completeness

NP-Complete Reductions 1

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

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

Polynomial-time Reductions

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

NP and NP-Completeness

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

NP-Complete problems

CS 580: Algorithm Design and Analysis

COMP 382. Unit 10: NP-Completeness

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

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

NP-Complete Problems. More reductions

Limitations of Algorithm Power

ECS122A Handout on NP-Completeness March 12, 2018

Essential facts about NP-completeness:

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

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

Computability and Complexity

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

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

Theory of Computation Chapter 9

Automata Theory CS Complexity Theory I: Polynomial Time

NP-completeness. Chapter 34. Sergey Bereg

Show that the following problems are NP-complete

NP-Complete Reductions 2

Lecture 19: Finish NP-Completeness, conp and Friends

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

CS154, Lecture 13: P vs NP

Polynomial-time reductions. We have seen several reductions:

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

CSC 1700 Analysis of Algorithms: P and NP Problems

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

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

1 Primals and Duals: Zero Sum Games

CSE 135: Introduction to Theory of Computation NP-completeness

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

Complexity, P and NP

Transcription:

COP 4531 Complexity & Analysis of Data Structures & Algorithms Lecture 18 Reductions and NP-completeness Thanks to Kevin Wayne and the text authors who contributed to these slides

Classify Problems According to Computational Requirements Q. Which problems will we be able to solve in practice? A working definition: those with polynomial-time algorithms. Yes Shortest path Matching Min cut 2-SAT Planar 4-color Bipartite vertex cover Primality testing Probably no Longest path 3D-matching Max cut 3-SAT Planar 3-color Vertex cover Factoring 2

Classify Problems Classify problems according to those that can be solved in polynomial-time and those that cannot. Provably requires exponential-time. Given a Turing machine, does it halt in at most k steps? Given a board position in an n-by-n generalization of chess, can black guarantee a win? Cannot be solved at all: Given an arbitrary Turing machine T and an input x, Does T halt on x. Frustrating news. Huge number of fundamental problems have defied classification for decades. But, we can show that many of these fundamental problems are "computationally equivalent" and appear to be different manifestations of one really hard problem. 3

Polynomial-Time Reduction Suppose we could solve B in polynomial-time. What else could we solve in polynomial time? Reduction. Problem A polynomial reduces to problem B if arbitrary instances of problem A can be solved using: Polynomial transform an instance α of A to a problem β of B The answers are the same. The answer for α is yes if and only if the answer for β is yes Notation. A P B. yes Instance α of A Polynomial Time Reduction Instance β of B Polynomial Time to decide β no 4

Polynomial-Time Reduction Purpose. Classify problems according to relative difficulty. Design algorithms. If A P B and B can be solved in polynomial-time, then A can also be solved in polynomial time. Establish intractability. If A P B and A cannot be solved in polynomialtime, then B cannot be solved in polynomial time. Establish equivalence. If A P B and B P A, we use notation A P B. up to cost of reduction 5

Reduction By Simple Equivalence Basic reduction strategies. Reduction by simple equivalence. Reduction from special case to general case. Reduction by encoding with gadgets.

Independent Set INDEPENDENT SET: Given a graph G = (V, E) and an integer k, is there a subset of vertices S V such that S k, and for each edge at most one of its endpoints is in S? Ex. Is there an independent set of size 6? Yes. Ex. Is there an independent set of size 7? No. independent set 7

Vertex Cover VERTEX COVER: Given a graph G = (V, E) and an integer k, is there a subset of vertices S V such that S k, and for each edge, at least one of its endpoints is in S? Ex. Is there a vertex cover of size 4? Yes. Ex. Is there a vertex cover of size 3? No. vertex cover 8

Vertex Cover and Independent Set Claim. VERTEX-COVER P INDEPENDENT-SET. Pf. We show S is an independent set iff V S is a vertex cover. independent set vertex cover 9

Vertex Cover and Independent Set Claim. INDEPENDENT-SET P VERTEX-COVER Pf. We show S is an independent set iff V S is a vertex cover. Let S be any independent set. Consider an arbitrary edge (u, v). S independent u S or v S u V S or v V S. Thus, V S covers (u, v). Let V S be any vertex cover. Consider two nodes u S and v S. Observe that (u, v) E since V S is a vertex cover. Thus, no two nodes in S are joined by an edge S independent set. 10

Reduction from Special Case to General Case Basic reduction strategies. Reduction by simple equivalence. Reduction from special case to general case. Reduction by encoding with gadgets.

Set Cover SET COVER: Given a set U of elements, a collection S 1, S 2,..., S m of subsets of U, and an integer k, does there exist a collection of k of these sets whose union is equal to U? Sample application. Ex: m available pieces of software. Set U of n capabilities that we would like our system to have. The ith piece of software provides the set S i U of capabilities. Goal: achieve all n capabilities using fewest pieces of software. U = { 1, 2, 3, 4, 5, 6, 7 } k = 2 S 1 = {3, 7} S 4 = {2, 4} S 2 = {3, 4, 5, 6} S 5 = {5} S 3 = {1} S 6 = {1, 2, 6, 7} 12

Vertex Cover Reduces to Set Cover Claim. VERTEX-COVER P SET-COVER. Pf. Given a VERTEX-COVER instance G = (V, E), k, we construct a set cover instance whose size equals the size of the vertex cover instance. Construction. Create SET-COVER instance: k = k, U = E, S v = {e E : e incident to v } Set-cover of size k iff vertex cover of size k. VERTEX COVER e 7 a b e 2 e 3 e 4 SET COVER U = { 1, 2, 3, 4, 5, 6, 7 } k = 2 f e 6 c S a = {3, 7} S b = {2, 4} e 1 e 5 S c = {3, 4, 5, 6} S d = {5} k = 2 e d S e = {1} S f = {1, 2, 6, 7} 13

Reductions via "Gadgets" Basic reduction strategies. Reduction by simple equivalence. Reduction from special case to general case. Reduction via "gadgets."

Satisfiability Literal: A Boolean variable or its negation. Clause: A disjunction of literals. Conjunctive normal form: A propositional formula Φ that is the conjunction of clauses. SAT: Given CNF formula Φ, does it have a satisfying truth assignment? 3-SAT: SAT where each clause contains exactly 3 literals. x i or x i C j = x 1 x 2 x 3 Φ = C 1 C 2 C 3 C 4 each corresponds to a different variable Ex: ( ) ( ( x 1 x 2 ) x 3 ) ( x 2 ( x 1 x 3 ) x 2 ( x 1 4 ) x 2 ( x 1 x 3 ) x 3 x 4 ) ( x x 1 1 x x 2 2 x x 3 ) 3 x 1 x 2 x 3 Yes: x 1 = true, x 2 = true x 3 = false. 15

3 Satisfiability Reduces to Independent Set Claim. 3-SAT P INDEPENDENT-SET. Pf. Given an instance Φ of 3-SAT, we construct an instance (G, k) of INDEPENDENT-SET that has an independent set of size k iff Φ is satisfiable. Construction. G contains 3 vertices for each clause, one for each literal. Connect 3 literals in a clause in a triangle. Connect literal to each of its negations. x 1 x 2 x 1 G x 2 x 3 x x 1 x 2 x 3 4 k = 3 Φ = ( x 1 x 2 x 3 ) ( x 1 x 2 x 3 ) ( x 1 x 2 x 4 ) 16

3 Satisfiability Reduces to Independent Set Claim. G contains independent set of size k = Φ iff Φ is satisfiable. Pf. Let S be independent set of size k. S must contain exactly one vertex in each triangle. Set these literals to true. and any other variables in a consistent way Truth assignment is consistent and all clauses are satisfied. Pf Given satisfying assignment, select one true literal from each triangle. This is an independent set of size k. x 1 x 2 x 1 G x 2 x 3 x x 1 x 2 x 3 4 k = 3 Φ = ( x 1 x 2 x 3 ) ( x 1 x 2 x 3 ) ( x 1 x 2 x 4 ) 17

Review Basic reduction strategies. Simple equivalence: INDEPENDENT-SET P VERTEX-COVER. Special case to general case: VERTEX-COVER P SET-COVER. Encoding with gadgets: 3-SAT P INDEPENDENT-SET. Transitivity. If X P Y and Y P Z, then X P Z. Pf idea. Compose the two algorithms. Ex: 3-SAT P INDEPENDENT-SET P VERTEX-COVER P SET-COVER. 18

Decision Problems vs. Optimization Problems Decision problem. Does there exist a vertex cover of size k? Optimization problem. Find vertex cover of minimum cardinality. It is easy to see that decision problem P optimization version. Solve optimization problem; compare solution with k. Since we will generally be interested in proving that a problem is hard, if we can show the decision problem is hard, then we know the corresponding optimization problem is also hard Self-reducibility. Optimization problem P decision version. Applies to all (NP-complete) problems we consider. Further justifies our focus on decision problems. 19

20

Decision Problems Decision problem. X is a set of strings. Instance: string s. Algorithm A solves problem X: A(s) = yes iff s X. Polynomial time. Algorithm A runs in poly-time if for every string s, A(s) terminates in at most p( s ) "steps", where p( ) is some polynomial. length of s PRIMES: X = { 2, 3, 5, 7, 11, 13, 17, 23, 29, 31, 37,. } Algorithm. [2002] p( s ) = s 8. 21

Definition of P P. Decision problems for which there is a poly-time algorithm. Problem Description Algorithm Yes No MULTIPLE Is x a multiple of y? Grade school division 51, 17 51, 16 RELPRIME Are x and y relatively prime? Euclid (300 BCE) 34, 39 34, 51 PRIMES Is x prime? AKS (2002) 53 51 EDIT- DISTANCE Is the edit distance between x and y less than 5? Dynamic programming niether neither acgggt ttttta LSOLVE Is there a vector x that satisfies Ax = b? Gauss-Edmonds elimination # 0 1 1& % ( % 2 4 2 (, $ % 0 3 15' ( # 4& % ( % 2 ( $ % 36' ( " 1 0 0% $ ' $ 1 1 22 1 ' # $ 0 1 1& ', " 1% $ ' $ 1 ' # $ 1& '

NP Certification algorithm intuition. Certifier views things from "managerial" viewpoint. Certifier doesn't determine whether s X on its own; rather, it checks a proposed proof t that s X. Def. Algorithm C(s, t) is a certifier for problem X if for every string s, s X iff there exists a string t such that C(s, t) = yes. NP. Decision problems for which there exists a poly-time certifier. "certificate" or "witness" Remark. NP stands for nondeterministic polynomial-time. C(s, t) is a poly-time algorithm and t p( s ) for some polynomial p( ). 23

Certifiers and Certificates: Composite COMPOSITES. Given an integer s, is s composite? Certificate. A nontrivial factor t of s. Note that such a certificate exists iff s is composite. Moreover t s. Certifier. Instance. s = 437,669. Certificate. t = 541 or 809. Conclusion. COMPOSITES is in NP. boolean C(s, t) { if (t 1 or t s) return false else if (s is a multiple of t) return true else return false } 437,669 = 541 809 24

Certifiers and Certificates: 3- Satisfiability SAT. Given a CNF formula Φ, is there a satisfying assignment? Certificate. An assignment of truth values to the n boolean variables. Certifier. Check that each clause in Φ has at least one true literal. Ex. ( x 1 x 2 x 3 ) ( x 1 x 2 x 3 ) x 1 x 2 x 4 instance s x 1 =1, x 2 =1, x 3 = 0, x 4 =1 Conclusion. SAT is in NP. certificate t ( ) ( ) x 1 x 3 x 4 25

Certifiers and Certificates: Hamiltonian Cycle HAM-CYCLE. Given an undirected graph G = (V, E), does there exist a simple cycle C that visits every node? Certificate. A permutation of the n nodes. Certifier. Check that the permutation contains each node in V exactly once, and that there is an edge between each pair of adjacent nodes in the permutation. Conclusion. HAM-CYCLE is in NP. instance s certificate t 26

P, NP, EXP P. Decision problems for which there is a poly-time algorithm. EXP. Decision problems for which there is an exponential-time algorithm. NP. Decision problems for which there is a poly-time certifier. Claim. P NP. Pf. Consider any problem X in P. By definition, there exists a poly-time algorithm A(s) that solves X. Certificate: separate t not needed, certifier C(s, t) = A(s). Claim. NP EXP. Pf. Consider any problem X in NP. By definition, there exists a poly-time certifier C(s, t) for X. To solve input s, run C(s, t) on all strings t with t p( s ). Return yes, if C(s, t) returns yes for any of these. 27

The Main Question: P Versus NP Does P = NP? [Cook 1971, Edmonds, Levin, Yablonski, Gödel] Is the decision problem as easy as the certification problem? Clay $1 million prize. EXP P If yes: Efficient algorithms for 3-COLOR, TSP, FACTOR, SAT, If no: No efficient algorithms possible for 3-COLOR, TSP, SAT, Consensus opinion on P = NP? Probably no. NP If P NP EXP P = NP If P = NP would break RSA cryptography (and potentially collapse economy) 28

NP-Complete NP-complete. A problem Y in NP with the property that for every problem X in NP, X p Y. (Hardest problems in NP) Theorem. Suppose Y is an NP-complete problem. Then Y is solvable in poly-time iff P = NP. Pf. If P = NP then Y can be solved in poly-time since Y is in NP. Pf. Suppose Y can be solved in poly-time. Let X be any problem in NP. Since X p Y, we can solve X in poly-time. This implies NP P. We already know P NP. Thus P = NP. 29

Circuit Satisfiability CIRCUIT-SAT. Given a combinational circuit built out of AND, OR, and NOT gates, is there a way to set the circuit inputs so that the output is 1? output yes: 1 0 1 1 0??? hard-coded inputs inputs 30

The "First" NP-Complete Problem Theorem. CIRCUIT-SAT is NP-complete. Pf. (sketch) Any algorithm that takes a fixed number of bits n as input and produces a yes/no answer can be represented by such a circuit. Moreover, if algorithm takes poly-time, then circuit is of poly-size. sketchy part of proof; fixing the number of bits is important, and reflects basic distinction between algorithms and circuits Consider some problem X in NP. It has a poly-time certifier C(s, t). To determine whether s is in X, need to know if there exists a certificate t of length p( s ) such that C(s, t) = yes. View C(s, t) as an algorithm on s + p( s ) bits (input s, certificate t) and convert it into a poly-size circuit K. first s bits are hard-coded with s remaining p( s ) bits represent bits of t Circuit K is satisfiable iff C(s, t) = yes. 31

Example Ex. Construction below creates a circuit K whose inputs can be set so that K outputs true iff graph G has an independent set of size 2. independent set of size 2? independent set? both endpoints of some edge have been chosen? set of size 2? u v w G = (V, E), n = 3 u-v u-w v-w u v w " n % $ ' # 2 & 1 0 1 hard-coded inputs (graph description)??? 32 n inputs (nodes in independent set)

Establishing NP-Completeness Remark. Once we establish first "natural" NP-complete problem, others fall like dominoes. Recipe to establish NP-completeness of problem Y. Step 1. Show that Y is in NP. Step 2. Choose an NP-complete problem X. Step 3. Prove that X p Y. Justification. If X is an NP-complete problem, and Y is a problem in NP with the property that X P Y then Y is NP-complete. Pf. Let W be any problem in NP. Then W P X P Y. By transitivity, W P Y. Hence Y is NP-complete. 33

3-SAT is NP-Complete Theorem. 3-SAT is NP-complete. Pf. Suffices to show that CIRCUIT-SAT P SAT is in NP. Hence we now have 3-SAT since 3-3-SAT p Independent Set p Vertex Cover p Set Cover In our NP-Complete Bank 34

X problems? X = Hard? Tough? Herculean? Formidable? Arduous? NPC? X = Impractical? Bad? Heavy? Tricky? Intricate? Prodigious? Difficult? Intractable? Costly? Obdurate? Obstinate? Exorbitant? Interminable? Couldn t find a poly-time solution bosss? 35

X problems? X = Hard? Tough? Herculean? Formidable? Arduous? X = Impractical? Bad? Heavy? Tricky? Intricate? Prodigious? Difficult? Intractable? Costly? Obdurate? Obstinate? Exorbitant? Interminable? Proof? Couldn t find a poly-time solution boss because none exists. 36

X problems? X = Hard? Tough? Herculean? Formidable? Arduous? X = Impractical? Bad? Heavy? Tricky? Intricate? Prodigious? Difficult? Intractable? Costly? Obdurate? Obstinate? Exorbitant? Interminable? Couldn t find a poly-time solution boss but neither could all these smart people 37

NP-Completeness Observation. All problems below are NP-complete and polynomial reduce to one another CIRCUIT-SAT by definition of NP-completeness 3-SAT 3-SAT reduces to INDEPENDENT SET INDEPENDENT SET DIR-HAM-CYCLE GRAPH 3-COLOR SUBSET-SUM VERTEX COVER HAM-CYCLE PLANAR 3-COLOR SCHEDULING SET COVER TSP 38

Some NP-Complete Problems Six basic genres of NP-complete problems and paradigmatic examples. Packing problems: SET-PACKING, INDEPENDENT SET. Covering problems: SET-COVER, VERTEX-COVER. Constraint satisfaction problems: SAT, 3-SAT. Sequencing problems: HAMILTONIAN-CYCLE, TSP. Partitioning problems: 3D-MATCHING 3-COLOR. Numerical problems: SUBSET-SUM, KNAPSACK. Practice. Most NP problems are either known to be in P or NP-complete. Notable exceptions. Factoring, graph isomorphism, Nash equilibrium. 39