CS Fall 2011 P and NP Carola Wenk

Similar documents
NP-Complete Problems. More reductions

NP-Complete Reductions 1

Correctness of Dijkstra s algorithm

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

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

NP and Computational Intractability

NP-Complete Reductions 2

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

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

Essential facts about NP-completeness:

NP Complete Problems. COMP 215 Lecture 20

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

1. Introduction Recap

Design and Analysis of Algorithms

NP Completeness and Approximation Algorithms

NP-Complete problems

Chapter 34: NP-Completeness

Polynomial-Time Reductions

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

More on NP and Reductions

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

Algorithms and Theory of Computation. Lecture 19: Class P and NP, Reduction

NP-completeness. Chapter 34. Sergey Bereg

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

CS 583: Algorithms. NP Completeness Ch 34. Intractability

NP-Hardness reductions

Lecture 4: NP and computational intractability

P is the class of problems for which there are algorithms that solve the problem in time O(n k ) for some constant k.

VIII. NP-completeness

Computational Intractability 2010/4/15. Lecture 2

Admin NP-COMPLETE PROBLEMS. Run-time analysis. Tractable vs. intractable problems 5/2/13. What is a tractable problem?

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

8.5 Sequencing Problems

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

NP-Completeness. Dr. B. S. Panda Professor, Department of Mathematics IIT Delhi, Hauz Khas, ND-16

SAT, NP, NP-Completeness

NP-Complete Problems. Complexity Class P. .. Cal Poly CSC 349: Design and Analyis of Algorithms Alexander Dekhtyar..

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

NP and Computational Intractability

There are two types of problems:

P, NP, NP-Complete, and NPhard

NP-COMPLETE PROBLEMS. 1. Characterizing NP. Proof

Algorithm Design and Analysis

P,NP, NP-Hard and NP-Complete

NP-Completeness. NP-Completeness 1

Lecture 19: NP-Completeness 1

CS21 Decidability and Tractability

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

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

CSE 3500 Algorithms and Complexity Fall 2016 Lecture 25: November 29, 2016

CSL 356: Analysis and Design of Algorithms. Ragesh Jaiswal CSE, IIT Delhi

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

Instructor N.Sadagopan Scribe: P.Renjith. Lecture- Complexity Class- P and NP

Complexity, P and NP

Algorithms and Complexity Theory. Chapter 8: Introduction to Complexity. Computer Science - Durban - September 2005

Algorithms Design & Analysis. Approximation Algorithm

5. Complexity Theory

More NP-Complete Problems

Algorithms, Lecture 3 on NP : Nondeterminis7c Polynomial Time

CS/COE

Polynomial-time reductions. We have seen several reductions:

NP Completeness and Approximation Algorithms

COP 4531 Complexity & Analysis of Data Structures & Algorithms

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

Chapter 3: Proving NP-completeness Results

ECS122A Handout on NP-Completeness March 12, 2018

Lecture 18: More NP-Complete Problems

NP-Completeness. Algorithmique Fall semester 2011/12

NP and NP Completeness

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

Intro to Theory of Computation

NP-Completeness. Subhash Suri. May 15, 2018

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

BBM402-Lecture 11: The Class NP

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

Introduction to Computational Complexity

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

Design and Analysis of Algorithms

Algorithms: COMP3121/3821/9101/9801

Chapter 8. NP and Computational Intractability

Computability and Complexity Theory: An Introduction

The Complexity Classes P and NP. Andreas Klappenecker [partially based on slides by Professor Welch]

6.045: Automata, Computability, and Complexity (GITCS) Class 15 Nancy Lynch

NP-Completeness Theory

CSE 421 NP-Completeness

NP-Completeness Review

Instructor N.Sadagopan Scribe: P.Renjith

Today: NP-Completeness (con t.)

Polynomial-time Reductions

Undecidable Problems. Z. Sawa (TU Ostrava) Introd. to Theoretical Computer Science May 12, / 65

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

Spring Lecture 21 NP-Complete Problems

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

Introduction. Pvs.NPExample

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

Algorithm Design and Analysis

Lecture #14: NP-Completeness (Chapter 34 Old Edition Chapter 36) Discussion here is from the old edition.

Transcription:

CS3343 -- Fall 2011 P and NP Carola Wenk Slides courtesy of Piotr Indyk with small changes by Carola Wenk 11/29/11 CS 3343 Analysis of Algorithms 1

We have seen so far Algorithms for various problems Running times O(nm 2 ),O(n 2 ),O(n log n), O(n), etc. I.e., polynomial in the input size Can we solve all (or most of) interesting problems in polynomial time? Not really 11/29/11 CS 3343 Analysis of Algorithms 2

Example difficult problem Traveling Salesperson 2 Problem (TSP; 4 5 optimization variant) 10 8 Input: Undirected graph 6 with lengths on edges 9 Output: Shortest tour that visits each vertex exactly once Best known algorithm: O(n 2 n ) time. 9 11 5 7 3 11/29/11 CS 3343 Analysis of Algorithms 3

Another difficult problem Clique (optimization variant): Input: Undirected graph G=(V,E) Output: Largest subset C of V such that every pair of vertices in C has an edge between them (C is called a clique) Best known algorithm: O(n 2 n ) time 11/29/11 CS 3343 Analysis of Algorithms 4

What can we do? Spend more time designing algorithms for those problems People tried for a few decades, no luck Prove there is no polynomial time algorithm for those problems Would ldbe great Seems really difficult Best lower bounds for natural problems: Ω(n 2 ) for restricted computational models 4.5nfor unrestricted computational models 11/29/11 CS 3343 Analysis of Algorithms 5

What else can we do? Show that those hard problems are essentially equivalent. I.e., if we can solve one of them in polynomial time, then all others can be solved in polynomial time as well. Works for at least 10 000 hard problems 11/29/11 CS 3343 Analysis of Algorithms 6

The benefits of equivalence Combines research efforts If one problem has a polynomial ltime P1 solution, then all of them do More realistically: Once an exponential lower bound is shown for one problem, it holds for all of them P3 P2 11/29/11 CS 3343 Analysis of Algorithms 7

Summing up If we show that a problem is equivalent to ten thousand other well studied problems without efficient algorithms, then we get a very strong evidence that is hard. We need to: Identify the class of problems of interest Dfi Define the notion of equivalence Prove the equivalence(s) 11/29/11 CS 3343 Analysis of Algorithms 8

Decision Problem Decision problems: answer YES or NO. Example: Search hproblem Π Search Given an unsorted set S of n numbers and a number key, is key contained in A? Input is x=(s,key) Possible algorithms that solve Π Search (x) : A 1 (x): Linear search algorithm. O(n) time A 2 2( (x): Sort the array and then perform binar search. O(n log n) time A 3 (x): Compute all possible subsets of S (2 n many) and check each subset if it contains key. O(n2 n ) time. 11/29/11 CS 3343 Analysis of Algorithms 9

Decision problem vs. optimization problem 3 variants of Clique: 1. Input: Undirected dgraph hg G=(V,E), and an integer k 0. Output: Does G contain a clique C such that C k? 2. Input: Undirected graph G=(V,E) Output: Largest integer k such that G contains a clique C with C =k. 3. Input: Undirected graph G=(V (V,E) Output: Largest clique C of V. 3. is harder than 2. is harder than 1. So, if we reason about the decision problem (1.), and can show that it is hard, then the others are hard as well. Also, every algorithm for 3. can solve 2. and 1. as well. 11/29/11 CS 3343 Analysis of Algorithms 10

Decision problem vs. optimization problem (cont.) Theorem: a) If 1. can be solved in polynomial time, then 2. can be solved in polynomial time. b) If 2. can be solved in polynomial time, then 3. can be solved in polynomial time. Proof: a) Run 1. for values k = 1... n. Instead of linear search one could also do binary search. b) Run 2. to find the size k opt of a largest clique in G. Now check one edge after the other. Remove one edge from G, compute the new size of the largest clique in this new graph. If it is still k opt then this edge is not necessary for a clique. If it is less than k opt then it is part of the clique. 11/29/11 CS 3343 Analysis of Algorithms 11

Class of problems: NP Decision problems: answer YES or NO. E.g., is there a tour of length K? Solvable in non-deterministic polynomial time: Intuitively: the solution can be verified in polynomial ltime E.g., if someone gives us a tour T, we can verify in polynomial time if T is a tour of length K. Therefore, the decision variant of TSP is in NP. 11/29/11 CS 3343 Analysis of Algorithms 12

Formal definitions of P and NP A decision problem is solvable in polynomial time (or P), if there is a polynomial time algorithm A(.) such that for any input x: (x)=yes iff A(x)=YES A decision problem is solvable in nondt deterministic iiti polynomial lti time (or NP), ifth there is a polynomial time algorithm A(.,.) such that for any input x: (x)=yes iff there exists a certificate y of size poly( x ) such that A(x,y)=YES 11/29/11 CS 3343 Analysis of Algorithms 13

Examples of problems in NP Is Does there exist a clique in G of size K in NP? Yes: A(x,y) ) interprets x as a graph G, y as a set C, and checks if all vertices in C are adjacent and if C K Is Sorting in NP? No, not a decision problem. Is Sortedness in NP? Yes: ignore y, and check if the input x is sorted. 11/29/11 CS 3343 Analysis of Algorithms 14

Reductions: to x A for YES NO x A for YES NO 11/29/11 CS 3343 Analysis of Algorithms 15

Reductions: to f f(x )= x A for YES NO x A for YES NO 11/29/11 CS 3343 Analysis of Algorithms 16

Reductions is polynomial time reducible to ( ) iff 1. there is a polynomial time function f that maps inputs x for into inputs x for, 2. such that for any x : : (x )= (f(x )) (or in other words (x )=YES iff (f(x )=YES) Fact 1: if P and then P Fact t2: if NP and then NP Fact 3 (transitivity): if and then 11/29/11 CS 3343 Analysis of Algorithms 17

Independent set (IS) Input: Undirected graph G=(V,E), K Output: Is there a subset S of V, S K such that no pair of vertices in S has an edge between them? (S is called an independent set) 11/29/11 CS 3343 Analysis of Algorithms 18

Clique IS x Given an input G=(V,E), K to Clique, need to construct an input G =(V,E E ) ), K to IS, f(x )=x such that G has clique of size K iff G has IS of size K. Construction: K =K,V =V,E =E Reason: C is a clique in G iff it is an ISin G s complement. 11/29/11 CS 3343 Analysis of Algorithms 19

Recap We defined a large class of interesting problems, namely NP We have a way of saying that one problem is not harder than another ( ) Our goal: show equivalence between hard problems 11/29/11 CS 3343 Analysis of Algorithms 20

Showing equivalence between difficult problems Options: Show reductions between all pairs of problems Reduce the number of reductions using transitivity of TSP P3 Clique P4 P5 11/29/11 CS 3343 Analysis of Algorithms 21

Showing equivalence between difficult problems Options: Show reductions between all pairs of problems Reduce the number of reductions using transitivity of Show that all problems in NP are reducible to a fixed. TSP P3 To show that some problem NP is equivalent to all difficult problems, we only show. Clique P4 P5 11/29/11 CS 3343 Analysis of Algorithms 22

The first problem Satisfiability problem (SAT): Given: a formula φ with m clauses over n variables, e.g., x 1 v x 2 v x 5, x 3 v x 5 Check if there exists TRUE/FALSE assignments to the variables that makes the formula satisfiable 11/29/11 CS 3343 Analysis of Algorithms 23

SAT is NP-complete Fact: SAT NP Theorem [Cook 71]: For any NP, we have SAT. Definition: A problem such that for any NP we have, is called NP-hard Definition: An NP-hard problem that bl belongs to NPis called lldnp-complete lt Corollary: SAT is NP-complete. 11/29/11 CS 3343 Analysis of Algorithms 24

Plan of attack: SAT Clique Independent set Vertex cover (thanks, Steve ) Follow from Cook s Theorem Conclusion: all of the above problems are NPcomplete 11/29/11 CS 3343 Analysis of Algorithms 25

Clique again Clique (decision variant): Input: Undirected graph G=(V,E), and an integer K 0 Output: Is there a clique C, i.e., a subset C of V such that every pair of vertices in C has an edge between them, such that C K? 11/29/11 CS 3343 Analysis of Algorithms 26

SAT Clique Given a SAT formula φ=c 1,,C m over x 1,,x n, we need to produce G=(V,E) and K, f(x )=x such that φ satisfiable iff G has a clique of size K. Notation: a literal is either x i or x i x 11/29/11 CS 3343 Analysis of Algorithms 27

SAT Clique reduction For each literal t occurring in φ, create a vertex v t Create an edge v t v t iff: t and t are not in the same clause, and t is not the negation of t 11/29/11 CS 3343 Analysis of Algorithms 28

SAT Clique example Edge v t v t t and t are not in the same clause, and t is not the negation of t Formula: x 1 v x 2 v x 3, x 2 v x 3, x 1 v x 2 Graph: x 1 x 2 x 3 x 2 x 3 x 2 x 1 Claim: φ satisfiable iff G has a clique of size m 11/29/11 CS 3343 Analysis of Algorithms 29

Proof Edge v t v t part: t and t are not in the same clause, and t is not the negation of t x 2 x Take any assignment that 1 x 3 x satisfies φ. 2 Eg E.g., x 1 =F, x 2 =T, x 3 =F Let the set C contain one satisfied literal per clause C is a clique x 3 x 1 x 2 11/29/11 CS 3343 Analysis of Algorithms 30

Proof Edge v t v t part: t and t are not in the same clause, and t is not the negation of t x 2 Take any clique C of size m x 1 x 3 (i.e., = m) x 2 Create a set of equations that satisfies selected literals. l E.g., x 3 =T, x 2 =F, x 1 =F The set of equations is consistent and the solution satisfies φ x 3 x 2 x 1 11/29/11 CS 3343 Analysis of Algorithms 31

Altogether We constructed a reduction that maps: YES inputs to SAT to YES inputs to Clique NO inputs to SAT to NO inputs to Clique The reduction works in polynomial time Therefore, SAT Clique Clique NP-hard Clique is in NP Clique is NP-complete 11/29/11 CS 3343 Analysis of Algorithms 32

Independent set (IS) Input: Undirected graph G=(V,E), K Output: Is there a subset S of V, S K such that no pair of vertices in S has an edge between them? (S is called an independent set) 11/29/11 CS 3343 Analysis of Algorithms 33

Clique IS x Given an input G=(V,E), K to Clique, need to construct an input G =(V,E E ) ), K to IS, f(x )=x such that G has clique of size K iff G has IS of size K. Construction: K =K,V =V,E =E Reason: C is a clique in G iff it is an ISin G s complement. 11/29/11 CS 3343 Analysis of Algorithms 34

Vertex cover (VC) Input: undirected graph G=(V,E), and K 0 Output: is there a subset C of V, C K, such that each edge in E is incident to at least one vertex in C. 11/29/11 CS 3343 Analysis of Algorithms 35

IS VC x Given an input G=(V,E), K to IS, need to construct an input G =(V,E ), K to VC, such that f(x )=x G has an IS of size K iff G has VC of size K. Construction: V =V, E =E, K = V -K Reason: S is an IS in G iff V-S is a VC in G. 11/29/11 CS 3343 Analysis of Algorithms 36