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

Similar documents
BBM402-Lecture 11: The Class NP

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

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

Essential facts about NP-completeness:

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

Design and Analysis of Algorithms

CS5371 Theory of Computation. Lecture 19: Complexity IV (More on NP, NP-Complete)

Chapter 34: NP-Completeness

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

CS154, Lecture 17: conp, Oracles again, Space Complexity

CMPT307: Complexity Classes: P and N P Week 13-1

NP-Completeness. ch34 Hewett. Problem. Tractable Intractable Non-computable computationally infeasible super poly-time alg. sol. E.g.

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

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

NP Complete Problems. COMP 215 Lecture 20

NP-Complete Problems. More reductions

CSE 105 THEORY OF COMPUTATION

Polynomial-time reductions. We have seen several reductions:

Introduction to Complexity Theory

Lecture 20: conp and Friends, Oracles in Complexity Theory

} } } Lecture 23: Computational Complexity. Lecture Overview. Definitions: EXP R. uncomputable/ undecidable P C EXP C R = = Examples

CS154, Lecture 13: P vs NP

Intro to Theory of Computation

Correctness of Dijkstra s algorithm

CS154, Lecture 13: P vs NP

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

NP-Complete Reductions 2

Reductions. Example 1

Intro to Theory of Computation

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

15-451/651: Design & Analysis of Algorithms October 31, 2013 Lecture #20 last changed: October 31, 2013

Topics in Complexity Theory

Polynomial-time Reductions

SAT, NP, NP-Completeness

CS Fall 2011 P and NP Carola Wenk

NP-Complete Reductions 1

1 Computational Problems

Data Structures in Java

Introduction. Pvs.NPExample

Lecture 19: Finish NP-Completeness, conp and Friends

Lecture Notes 4. Issued 8 March 2018

Notes for Lecture Notes 2

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

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

Computational complexity

CMSC 441: Algorithms. NP Completeness

Computability Theory

1 Reductions and Expressiveness

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

CS154, Lecture 15: Cook-Levin Theorem SAT, 3SAT

NP-completeness. Chapter 34. Sergey Bereg

Complexity Theory VU , SS The Polynomial Hierarchy. Reinhard Pichler

ITCS:CCT09 : Computational Complexity Theory Apr 8, Lecture 7

Outline. Complexity Theory EXACT TSP. The Class DP. Definition. Problem EXACT TSP. Complexity of EXACT TSP. Proposition VU 181.

Complexity Theory Part II

CSE 105 THEORY OF COMPUTATION

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.

CSCI3390-Lecture 14: The class NP

1. Introduction Recap

ECS 120 Lesson 24 The Class N P, N P-complete Problems

conp, Oracles, Space Complexity

NP and NP Completeness

NP-Completeness I. Lecture Overview Introduction: Reduction and Expressiveness

CSCI3390-Lecture 18: Why is the P =?NP Problem Such a Big Deal?

Chapter 2 : Time complexity

Announcements. Problem Set 7 graded; will be returned at end of lecture. Unclaimed problem sets and midterms moved!

Data Structures and Algorithms (CSCI 340)

Spring Lecture 21 NP-Complete Problems

Definition: conp = { L L NP } What does a conp computation look like?

CS 583: Algorithms. NP Completeness Ch 34. Intractability

NP-Complete problems

Lecture 18: PCP Theorem and Hardness of Approximation I

Lecture 16: Time Complexity and P vs NP

Chapter 7: Time Complexity

Lecture 6: Oracle TMs, Diagonalization Limits, Space Complexity

Computational Complexity

Turing Machines and Time Complexity

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

Lecture 15 - NP Completeness 1

CS5371 Theory of Computation. Lecture 18: Complexity III (Two Classes: P and NP)

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

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

CSE 105 THEORY OF COMPUTATION

3130CIT Theory of Computation

Tractable & Intractable Problems

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

NP-COMPLETE PROBLEMS. 1. Characterizing NP. Proof

CSE 105 Theory of Computation

Comparison of several polynomial and exponential time complexity functions. Size n

CSCI3390-Lecture 17: A sampler of NP-complete problems

Limits to Approximability: When Algorithms Won't Help You. Note: Contents of today s lecture won t be on the exam

Lecture 4 : Quest for Structure in Counting Problems

Algorithms, Lecture 3 on NP : Nondeterminis7c Polynomial Time

Finish K-Complexity, Start Time Complexity

NP and Computational Intractability

P and NP. Or, how to make $1,000,000.

Computational Models Lecture 11, Spring 2009

Problems, and How Computer Scientists Solve Them Manas Thakur

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

Transcription:

Algorithms and Theory of Computation Lecture 19: Class P and NP, Reduction Xiaohui Bei MAS 714 October 29, 2018 Nanyang Technological University MAS 714 October 29, 2018 1 / 26

Decision Problems Revisited Many optimization problems can be reposed as decision problems. Nanyang Technological University MAS 714 October 29, 2018 2 / 26

Decision Problems Revisited Many optimization problems can be reposed as decision problems. Travelling Salesman Problem TSP: Given a complete undirected graph with edge weights, find a tour (cycle visiting each vertex once and exactly once) of minimum total weight. Nanyang Technological University MAS 714 October 29, 2018 2 / 26

Decision Problems Revisited Many optimization problems can be reposed as decision problems. Travelling Salesman Problem TSP: Given a complete undirected graph with edge weights, find a tour (cycle visiting each vertex once and exactly once) of minimum total weight. TSP dec : { G, k G is a complete undirected graph with edge weights and there exists a tour of total weight k}. Nanyang Technological University MAS 714 October 29, 2018 2 / 26

TSP in NP Given G, k, what is a nondeterministic polynomial time algorithm to decide whether or not G has a tour of cost at most k? Nanyang Technological University MAS 714 October 29, 2018 3 / 26

TSP in NP Given G, k, what is a nondeterministic polynomial time algorithm to decide whether or not G has a tour of cost at most k? Guess a tour t, and accept if cost(t) k runs in polynomial time (linear in fact) if there is a tour of cost at most k, then there is an accepting computation if there is no tour of cost at most k, then all computations reject. Nanyang Technological University MAS 714 October 29, 2018 3 / 26

Certifier/Proof Interpretation of NP L NP implies that there is a nondeterministic poly-time algorithm/tm M that accepts L. Claim L NP if and only if there is a poly-time TM M that accepts L with the following properties: On input w, M first non-deterministically guesses a string y where y p( w ) for some fixed polynomial p(). M then runs a deterministic poly-time TM M on the string w#y and accepts w if M accepts w#y and rejects w if M rejects w#y. Nanyang Technological University MAS 714 October 29, 2018 4 / 26

Certifier/Proof Interpretation of NP L NP implies that there is a nondeterministic poly-time algorithm/tm M that accepts L. Claim L NP if and only if there is a poly-time TM M that accepts L with the following properties: On input w, M first non-deterministically guesses a string y where y p( w ) for some fixed polynomial p(). M then runs a deterministic poly-time TM M on the string w#y and accepts w if M accepts w#y and rejects w if M rejects w#y. Non-determinism is used to guess a proof/solution y for w. Verifier/Certifier M is a deterministic algorithm that checks if y is a valid solution for w. Nanyang Technological University MAS 714 October 29, 2018 4 / 26

Certifier/Proof Interpretation of NP L NP implies that there is a nondeterministic poly-time algorithm/tm M that accepts L. Alternate definition of NP L NP if and only if there is a deterministic TM/algorithm M and two polynomials p() and q() such that M runs in time p( x ) where x is its input (hence efficient) if w L then there is a string y with y q( w ) such that M accepts w#y if w / L then for every y with y q( w ), M on input w#y rejects Nanyang Technological University MAS 714 October 29, 2018 5 / 26

Certifier/Proof Interpretation of NP L NP implies that there is a nondeterministic poly-time algorithm/tm M that accepts L. Alternate definition of NP L NP if and only if there is a deterministic TM/algorithm M and two polynomials p() and q() such that M runs in time p( x ) where x is its input (hence efficient) if w L then there is a string y with y q( w ) such that M accepts w#y if w / L then for every y with y q( w ), M on input w#y rejects NP is natural because there are plenty of problems where verification of solutions is easy. Hundreds of well-studied problems are in NP. Nanyang Technological University MAS 714 October 29, 2018 5 / 26

Maximum Independent Set Given undirected graph G = (V, E), a subset of vertices S V is an independent set if there are no edges between vertices in S. That is, if u, v S then (u, v) / E. A B C F E D Some independent sets in graph above: {D}, {A, C}, {B, E, F} Nanyang Technological University MAS 714 October 29, 2018 6 / 26

Maximum Independent Set Given undirected graph G = (V, E), a subset of vertices S V is an independent set if there are no edges between vertices in S. That is, if u, v S then (u, v) / E. A B C F E D Some independent sets in graph above: {D}, {A, C}, {B, E, F} Maximum Independent Set Problem(MIS) Input: Graph G = (V, E) Goal: Find maximum sized independent set in G. Nanyang Technological University MAS 714 October 29, 2018 6 / 26

Maximum Independent Set Decision Version of MIS Input: Graph G = (V, E) and integer k written as G, k Question: Is there an independent set in G of size at least k? Nanyang Technological University MAS 714 October 29, 2018 7 / 26

Maximum Independent Set Decision Version of MIS Input: Graph G = (V, E) and integer k written as G, k Question: Is there an independent set in G of size at least k? The answer to G, k is YES if G has an independent set of size at least k. Otherwise the answer is NO. Sometimes we say G, k is a YES instance or a NO instance. The language associated with this decision problem is L MIS = { G, k G has an independent set of size k} Nanyang Technological University MAS 714 October 29, 2018 7 / 26

L MIS is in NP A non-deterministic polynomial-time algorithm for L MIS. Nanyang Technological University MAS 714 October 29, 2018 8 / 26

L MIS is in NP A non-deterministic polynomial-time algorithm for L MIS. Input: a string G, k encoding graph G = (V, E) and integer k 1 Non-deterministically guess a subset S V of vertices. 2 Verify (deterministically) that S forms an independent set in G by checking that there is no edge in E between any pair of vertices in S S k 3 If S passes the above two tests output YES else NO Nanyang Technological University MAS 714 October 29, 2018 8 / 26

L MIS is in NP A non-deterministic polynomial-time algorithm for L MIS. Input: a string G, k encoding graph G = (V, E) and integer k 1 Non-deterministically guess a subset S V of vertices. 2 Verify (deterministically) that S forms an independent set in G by checking that there is no edge in E between any pair of vertices in S S k 3 If S passes the above two tests output YES else NO Key Points: 1 string encoding S, S has length polynomial in length of input G, k 2 verification of guess is easily seen to be polynomial in length of S and G, k Nanyang Technological University MAS 714 October 29, 2018 8 / 26

Sudoku Given a n n sudoku puzzle, does it have a solution? Nanyang Technological University MAS 714 October 29, 2018 9 / 26

Recap P: set of decision problems that have polynomial time algorithms. NP: set of decision problems that have polynomial time nondeterministic algorithms. Big Question Does every problem in NP have an efficient algorithm? Nanyang Technological University MAS 714 October 29, 2018 10 / 26

Recap P: set of decision problems that have polynomial time algorithms. NP: set of decision problems that have polynomial time nondeterministic algorithms. Big Question Does every problem in NP have an efficient algorithm? Same as asking whether P = NP. We dont know the answer and many people believe that P NP. Nanyang Technological University MAS 714 October 29, 2018 10 / 26

Reductions A reduction from Problem X to Problem Y means (informally) that if we have an algorithm for Problem Y, we can use it to find an algorithm for Problem X. Nanyang Technological University MAS 714 October 29, 2018 11 / 26

Reductions A reduction from Problem X to Problem Y means (informally) that if we have an algorithm for Problem Y, we can use it to find an algorithm for Problem X. We use reductions to find algorithms to solve problems. show that we can t find algorithms for some problems. (We say that these problems are hard.) Nanyang Technological University MAS 714 October 29, 2018 11 / 26

Reductions for Decision Problems/Languages Reductions for Languages For languages L X, L Y, a reduction from L X to L Y is an algorithm with input w Σ output w Σ such that w L Y w L X (Actually, this is only one type of reduction, but this is the one well use most often.) There are other kinds of reductions. Nanyang Technological University MAS 714 October 29, 2018 12 / 26

Reductions for Decision Problems/Languages Reductions for Decision Problems For decision problems X, Y, a reduction from X to Y is an algorithm with such that input: I X, an instance of X output: I Y. an instance of Y I Y is YES instance of Y I X is YES instance of X Nanyang Technological University MAS 714 October 29, 2018 13 / 26

Using Reductions to Solve Problems R: Reduction X Y A Y : algorithm for Y Nanyang Technological University MAS 714 October 29, 2018 14 / 26

Using Reductions to Solve Problems R: Reduction X Y A Y : algorithm for Y New algorithm for X: Algorithm: A X (I X ): I Y = R(I X ); return A Y (I Y ) Nanyang Technological University MAS 714 October 29, 2018 14 / 26

Using Reductions to Solve Problems R: Reduction X Y A Y : algorithm for Y New algorithm for X: Algorithm: A X (I X ): I Y = R(I X ); return A Y (I Y ) If R and A Y polynomial time = A X polynomial time Nanyang Technological University MAS 714 October 29, 2018 14 / 26

Comparing Problems If Problem X reduces to Problem Y (we write X Y), then Nanyang Technological University MAS 714 October 29, 2018 15 / 26

Comparing Problems If Problem X reduces to Problem Y (we write X Y), then Problem X is no harder to solve than Problem Y. Nanyang Technological University MAS 714 October 29, 2018 15 / 26

Comparing Problems If Problem X reduces to Problem Y (we write X Y), then Problem X is no harder to solve than Problem Y. X Y: X is no harder than Y, or Y is at least as hard as X. Nanyang Technological University MAS 714 October 29, 2018 15 / 26

Example of Reductions Given a graph G, a set of vertices S is: independent set: no two vertices of S connected by an edge. clique: every pair of vertices in S is connected by an edge of G. Nanyang Technological University MAS 714 October 29, 2018 16 / 26

Example of Reductions Given a graph G, a set of vertices S is: independent set: no two vertices of S connected by an edge. clique: every pair of vertices in S is connected by an edge of G. Nanyang Technological University MAS 714 October 29, 2018 16 / 26

Independent Set and Clique Problems Independent Set Instance: A graph G and an integer k. Question: Does G have an independent set of size k? Clique Instance: A graph G and an integer k. Question: Does G have an clique of size k? Nanyang Technological University MAS 714 October 29, 2018 17 / 26

Recall For decision problems X, Y, a reduction from X to Y is an algorithm that takes I X, an instance of X as input and returns I Y, an instance of Y as output such that the solution (Y/N) to I Y is the same as the solution to I X. Nanyang Technological University MAS 714 October 29, 2018 18 / 26

Reducing Independent Set to Clique An instance of Independent Set is a graph G and an integer k. Reduction given G, k outputs G, k, where G is the complement of G, G has an edge (u, v) if and only if (u, v) is not an edge of G. Nanyang Technological University MAS 714 October 29, 2018 19 / 26

Reducing Independent Set to Clique An instance of Independent Set is a graph G and an integer k. Reduction given G, k outputs G, k, where G is the complement of G, G has an edge (u, v) if and only if (u, v) is not an edge of G. Nanyang Technological University MAS 714 October 29, 2018 19 / 26

Correctness of Reduction Lemma G has an independent set of size at least k if and only if G has a clique of size at least k. Nanyang Technological University MAS 714 October 29, 2018 20 / 26

Correctness of Reduction Lemma G has an independent set of size at least k if and only if G has a clique of size at least k. Proof. Need to prove two facts: G has an independent set of size at least k implies that G has a clique of size at least k. G has a clique of size at least k implies that G has an independent set of size at least k. Nanyang Technological University MAS 714 October 29, 2018 20 / 26

Correctness of Reduction Lemma G has an independent set of size at least k if and only if G has a clique of size at least k. Proof. Need to prove two facts: G has an independent set of size at least k implies that G has a clique of size at least k. G has a clique of size at least k implies that G has an independent set of size at least k. Easy to see both from the fact that S V is an independent set in G if and only if S is a clique in G. Nanyang Technological University MAS 714 October 29, 2018 20 / 26

Independent Set and Clique Independent Set Clique what does it mean? Nanyang Technological University MAS 714 October 29, 2018 21 / 26

Independent Set and Clique Independent Set Clique what does it mean? If we have an algorithm for Clique, then we have an algorithm for Independent Set. Clique is at least as hard as Independent Set. Also... Independent Set is at least as hard as Clique. Nanyang Technological University MAS 714 October 29, 2018 21 / 26

Independent Set and Clique Assume you can solve the Clique problem in time T(n), then you can solve the Independent Set problem in time (A) O(T(n)) (B) O(n log n + T(n)) (C) O(n 2 T(n 2 )) (D) O(n 4 T(n 4 )) (E) O(n 2 + T(n 2 )) Nanyang Technological University MAS 714 October 29, 2018 22 / 26

Independent Set and Clique Assume you can solve the Clique problem in time T(n), then you can solve the Independent Set problem in time (A) O(T(n)) (B) O(n log n + T(n)) (C) O(n 2 T(n 2 )) (D) O(n 4 T(n 4 )) (E) O(n 2 + T(n 2 )) (F) We don t care all these are polynomial if T(n) is a polynomial, which is good enough for our purposes. Nanyang Technological University MAS 714 October 29, 2018 22 / 26

Polynomial Time Reductions We say that an algorithm is efficient if it runs in polynomial-time. To find efficient algorithms for problems, we are only interested in polynomial-time reductions. Reductions that take longer are not useful. If we have a polynomial-time reduction from problem X to problem Y (we write X P Y), and a poly-time algorithm A Y for Y, we have a polynomial-time/efficient algorithm for X. Nanyang Technological University MAS 714 October 29, 2018 23 / 26

Polynomial Time Reductions For decision problems X, Y, a polynomial reduction from X to Y is an algorithm A that has the following properties: A takes I X, an instance of X as input returns I Y, an instance of Y as output runs in polynomial time such that the solution (Y/N) to I Y is the same as the solution to I X. Nanyang Technological University MAS 714 October 29, 2018 24 / 26

Polynomial Time Reductions For decision problems X, Y, a polynomial reduction from X to Y is an algorithm A that has the following properties: A takes I X, an instance of X as input returns I Y, an instance of Y as output runs in polynomial time such that the solution (Y/N) to I Y is the same as the solution to I X. Proposition If X P Y then a polynomial time algorithm for Y implies a polynomial time algorithm for X. Such a reduction is called a Karp reduction. Most reductions we will need are Karp reductions. Nanyang Technological University MAS 714 October 29, 2018 24 / 26

Transitivity of Reductions Proposition X P Y and Y P Z implies that X P Z. Nanyang Technological University MAS 714 October 29, 2018 25 / 26

Transitivity of Reductions Proposition X P Y and Y P Z implies that X P Z. Note: X P Y does not imply that Y P X and hence it is very important to know the FROM and TO in a reduction. To prove X P Y you need to show a reduction FROM X TO Y That is, show that an algorithm for Y implies an algorithm for X. Nanyang Technological University MAS 714 October 29, 2018 25 / 26

Polynomial Time Reductions and Hardness For decision problems X and Y, if X P Y, and Y has an efficient algorithm, X has an efficient algorithm. If you believe that Independent Set does not have an efficient algorithm, why should you believe the same of Clique? Nanyang Technological University MAS 714 October 29, 2018 26 / 26

Polynomial Time Reductions and Hardness For decision problems X and Y, if X P Y, and Y has an efficient algorithm, X has an efficient algorithm. If you believe that Independent Set does not have an efficient algorithm, why should you believe the same of Clique? Because we showed Independent Set P Clique. If Clique had an efficient algorithm, so would Independent Set. If X P Y and X does not have an efficient algorithm, Y cannot have an efficient algorithm! Nanyang Technological University MAS 714 October 29, 2018 26 / 26