BBM402-Lecture 11: The Class NP

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

Computability Theory

CS154, Lecture 13: P vs NP

CS154, Lecture 13: P vs NP

Lecture 19: Finish NP-Completeness, conp and Friends

Chapter 7: Time Complexity

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

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

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

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

Lecture 16: Time Complexity and P vs NP

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

Lecture 20: conp and Friends, Oracles in Complexity Theory

1 Non-deterministic Turing Machine

Time Complexity. CS60001: Foundations of Computing Science

The Class NP. NP is the problems that can be solved in polynomial time by a nondeterministic machine.

CSE 135: Introduction to Theory of Computation NP-completeness

P = k T IME(n k ) Now, do all decidable languages belong to P? Let s consider a couple of languages:

Theory of Computation Time Complexity

NP and NP Completeness

CSE 105 THEORY OF COMPUTATION

Applied Computer Science II Chapter 7: Time Complexity. Prof. Dr. Luc De Raedt. Institut für Informatik Albert-Ludwigs Universität Freiburg Germany

Polynomial-time Reductions

NP-Complete Problems. More reductions

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

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

Intro to Theory of Computation

Chapter 2 : Time complexity

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

Essential facts about NP-completeness:

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

Intro to Theory of Computation

Complexity Theory Part II

Lecture 3: Nondeterminism, NP, and NP-completeness

NP-Completeness. A language B is NP-complete iff B NP. This property means B is NP hard

CSCI3390-Lecture 14: The class NP

1 Computational Problems

NP-Complete Reductions 2

SOLUTION: SOLUTION: SOLUTION:

Time Complexity (1) CSCI Spring Original Slides were written by Dr. Frederick W Maier. CSCI 2670 Time Complexity (1)

CSE 105 THEORY OF COMPUTATION

Computational Models Lecture 11, Spring 2009

Notes for Lecture Notes 2

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

CS Lecture 29 P, NP, and NP-Completeness. k ) for all k. Fall The class P. The class NP

CMSC 441: Algorithms. NP Completeness

Complexity (Pre Lecture)

CSE 105 Theory of Computation

Introduction to Complexity Theory

Lecture 25: Cook s Theorem (1997) Steven Skiena. skiena

NP, polynomial-time mapping reductions, and NP-completeness

Polynomial-time reductions. We have seen several reductions:

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

Friday Four Square! Today at 4:15PM, Outside Gates

1. Introduction Recap

Design and Analysis of Algorithms

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

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

Computability and Complexity

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

Problems, and How Computer Scientists Solve Them Manas Thakur

Lecture 4: NP and computational intractability

Finish K-Complexity, Start Time Complexity

Advanced topic: Space complexity

CS21 Decidability and Tractability

SAT, NP, NP-Completeness

TIME COMPLEXITY AND POLYNOMIAL TIME; NON DETERMINISTIC TURING MACHINES AND NP. THURSDAY Mar 20

NP Completeness and Approximation Algorithms

CSE 105 THEORY OF COMPUTATION

COSE215: Theory of Computation. Lecture 20 P, NP, and NP-Complete Problems

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

CISC 4090 Theory of Computation

NP and Computational Intractability

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

NP Complete Problems. COMP 215 Lecture 20

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?

Complexity, P and NP

an efficient procedure for the decision problem. We illustrate this phenomenon for the Satisfiability problem.

Lecture 18: PCP Theorem and Hardness of Approximation I

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

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY. FLAC (15-453) Spring l. Blum TIME COMPLEXITY AND POLYNOMIAL TIME;

Time and space classes

conp, Oracles, Space Complexity

Lecture 13, Fall 04/05

NP-completeness. Chapter 34. Sergey Bereg

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

Lecture Notes 4. Issued 8 March 2018

Lecture 24: Randomized Complexity, Course Summary

Polynomial time reduction and NP-completeness. Exploring some time complexity limits of polynomial time algorithmic solutions

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

More NP-Complete Problems

CS 583: Algorithms. NP Completeness Ch 34. Intractability

Theory of Computation Chapter 9

Computational Complexity

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

Lecture 4 : Quest for Structure in Counting Problems

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

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

NP-Complete problems

Transcription:

BBM402-Lecture 11: The Class NP Lecturer: Lale Özkahya Resources for the presentation: http://ocw.mit.edu/courses/electrical-engineering-andcomputer-science/6-045j-automata-computability-andcomplexity-spring-2011/syllabus/ https://courses.engr.illinois.edu/cs498374/lectures.html

Introduction P = { L there is some polynomial-time deterministic Turing machine that decides L } NP = { L there is some polynomial-time nondeterministic Turing machine that decides L } Alternatively, L NP if and only if ( V, a polynomial-time verifier ) ( p, a polynomial ) such that: x L iff ( c, c p( x ) ) [ V( x, c ) accepts ] certificate To show that L NP, we need only exhibit a suitable verifier V and show that it works (which requires saying what the certificates are). P NP, but it s not known whether P = NP.

Introduction P = { L poly-time deterministic TM that decides L } NP = { L poly-time nondeterministic TM that decides L } L NP if and only if ( V, poly-time verifier ) ( p, poly) x L iff ( c, c p( x ) ) [ V( x, c ) accepts ] Some languages are in NP, but are not known to be in P (and are not known to not be in P ): SAT = { < φ > φ is a satisfiable Boolean formula } 3COLOR= { < G > G is an (undirected) graph whose vertices can be colored with 3 colors with no 2 adjacent vertices colored the same } CLIQUE= { < G, k > G is a graph with a k-clique } VERTEX-COVER = { < G, k > G is a graph having a vertex cover of size k }

CLIQUE CLIQUE = { < G, k > G is a graph with a k-clique } k-clique: k vertices with edges between all pairs in the clique. In NP, not known to be in P, not known to not be in P. b a c f e 3-cliques: { b, c, d }, { c, d, f } Cliques are easy to verify, but may be hard to find. d

CLIQUE CLIQUE = { < G, k > G is a graph with a k-clique } b a c f Input to the VC problem: < G, 3 > Certificate, to show that < G, 3 > CLIQUE, is { b, c, d } (or { c, d, f }). Polynomial-time verifier can check that { b, c, d } is a 3-clique. e d

VERTEX-COVER VERTEX-COVER = { < G, k > G is a graph with a vertex cover of size k } Vertex cover of G = (V, E): A subset C of V such that, for every edge (u,v) in E, either u C or v C. A set of vertices that covers all the edges. In NP, not known to be in P, not known to not be in P. b a c f 3-vc: { a, b, d } e d Vertex covers are easy to verify, may be hard to find.

VERTEX-COVER VERTEX-COVER = { < G, k > G is a graph with a vertex cover of size k } b a c f e d Input to the VC problem: < G, 3 > Certificate, to show that < G, 3 > VC, is { a, b, d }. Polynomial-time verifier can check that { a, b, d } is a 3-vertex-cover.

HAMPATH Problem HAMPATH = {< G, s, t > G is a directed path with a Hamiltonian s, t path} There is an exponential brute force algorithm given in Thm 7.14 (Sipser). Verifying the existence of a Hamiltonian path is much easier than determining its existence.

HAMPATH Problem HAMPATH = {< G, s, t > G is a directed path with a Hamiltonian s, t path} There is an exponential brute force algorithm given in Thm 7.14 (Sipser). Verifying the existence of a Hamiltonian path is much easier than determining its existence. Verier: A verier for a language A is an algorithm, where A = {w V accepts < w, c > for some string c}

HAMPATH Problem HAMPATH = {< G, s, t > G is a directed path with a Hamiltonian s, t path} There is an exponential brute force algorithm given in Thm 7.14 (Sipser). Verifying the existence of a Hamiltonian path is much easier than determining its existence. Verier: A verier for a language A is an algorithm, where A = {w V accepts < w, c > for some string c} Polynomial time verier: The running time of the verier is measured by the length of w. Thus, a poly. time verier runs in O(w k ) (polynomial time in the length of w). Certicate: A verier uses additional information, represented by the symbol c. This information is called a certicate, or proof, of membership in A.

Why is HAMPATH in NP? NP is the class of languages that have polynomial time veriers. The term NP comes from nondeterministic polynomial time. Decider for HAMPATH N : On input < G, s, t >, where G is a directed graph with nodes s and t: 1 Write a list of m numbers p 1,..., p m, where m is the number of nodes in G. Each number in the list is nondeterministically selected between 1 and m. 2 Check for repetitions in the list. If any are found, reject. 3 Check whether s = p 1 and t = p m. If either fail, reject. 4 For each 1 i m 1, check whether (p i, p i+1 ) is an edge of G. If they are not, reject. Otherwise, all tests have been passed, so accept.

Why is HAMPATH in NP? NP is the class of languages that have polynomial time veriers. The term NP comes from nondeterministic polynomial time. Decider for HAMPATH N : On input < G, s, t >, where G is a directed graph with nodes s and t: 1 Write a list of m numbers p 1,..., p m, where m is the number of nodes in G. Each number in the list is nondeterministically selected between 1 and m. 2 Check for repetitions in the list. If any are found, reject. 3 Check whether s = p 1 and t = p m. If either fail, reject. 4 For each 1 i m 1, check whether (p i, p i+1 ) is an edge of G. If they are not, reject. Otherwise, all tests have been passed, so accept. This algorithm runs in nondeterministic polynomial time: - Stage 1: The nondeterministic selection runs in p.t. - Stage 2, 3 and 4: p.t.

More about NP Theorem (Thm 7.20, Sipser) A language is in NP i (if and only if) it is decided by some nondeterministic polynomial time machine. ((1) language in NP = nondet. p. t. machine AND (2) Nondet. p.t. machine = language in NP) To show (1): Let A NP. Show that A is decided by a poly. time NTM N.

More about NP Theorem (Thm 7.20, Sipser) A language is in NP i (if and only if) it is decided by some nondeterministic polynomial time machine. ((1) language in NP = nondet. p. t. machine AND (2) Nondet. p.t. machine = language in NP) To show (1): Let A NP. Show that A is decided by a poly. time NTM N. Let V be the poly. time verier for A that exists because A NP, assuming V runs in time O(n k ).

More about NP Theorem (Thm 7.20, Sipser) A language is in NP i (if and only if) it is decided by some nondeterministic polynomial time machine. ((1) language in NP = nondet. p. t. machine AND (2) Nondet. p.t. machine = language in NP) To show (1): Let A NP. Show that A is decided by a poly. time NTM N. Let V be the poly. time verier for A that exists because A NP, assuming V runs in time O(n k ). N = On input w of length n: (1) Nondeterministically select string c of length at most n k (depth of the tree modelling the nondeterministic machine) (2) Run V on input < w, c >. (3) If V accepts, accept; otherwise, reject.

More about NP Theorem (Thm 7.20, Sipser) A language is in NP i (if and only if) it is decided by some nondeterministic polynomial time machine. ((1) language in NP = nondet. p. t. machine AND (2) Nondet. p.t. machine = language in NP) To show (1): Let A NP. Show that A is decided by a poly. time NTM N. Let V be the poly. time verier for A that exists because A NP, assuming V runs in time O(n k ). N = On input w of length n: (1) Nondeterministically select string c of length at most n k (depth of the tree modelling the nondeterministic machine) (2) Run V on input < w, c >. (3) If V accepts, accept; otherwise, reject. To show (2): Assume that A is decided by a poly. time NTM N. Construct a polynomial time verier V for A.

More about NP Theorem (Thm 7.20, Sipser) A language is in NP i (if and only if) it is decided by some nondeterministic polynomial time machine. ((1) language in NP = nondet. p. t. machine AND (2) Nondet. p.t. machine = language in NP) To show (1): Let A NP. Show that A is decided by a poly. time NTM N. Let V be the poly. time verier for A that exists because A NP, assuming V runs in time O(n k ). N = On input w of length n: (1) Nondeterministically select string c of length at most n k (depth of the tree modelling the nondeterministic machine) (2) Run V on input < w, c >. (3) If V accepts, accept; otherwise, reject. To show (2): Assume that A is decided by a poly. time NTM N. Construct a polynomial time verier V for A. On input < w, c >, where w and c are strings:

More about NP Theorem (Thm 7.20, Sipser) A language is in NP i (if and only if) it is decided by some nondeterministic polynomial time machine. ((1) language in NP = nondet. p. t. machine AND (2) Nondet. p.t. machine = language in NP) To show (1): Let A NP. Show that A is decided by a poly. time NTM N. Let V be the poly. time verier for A that exists because A NP, assuming V runs in time O(n k ). N = On input w of length n: (1) Nondeterministically select string c of length at most n k (depth of the tree modelling the nondeterministic machine) (2) Run V on input < w, c >. (3) If V accepts, accept; otherwise, reject. To show (2): Assume that A is decided by a poly. time NTM N. Construct a polynomial time verier V for A. On input < w, c >, where w and c are strings: Simulate N on input w, treating each symbol of c as a description of the nondeterministic choice to make at each step,

More about NP Theorem (Thm 7.20, Sipser) A language is in NP i (if and only if) it is decided by some nondeterministic polynomial time machine. ((1) language in NP = nondet. p. t. machine AND (2) Nondet. p.t. machine = language in NP) To show (1): Let A NP. Show that A is decided by a poly. time NTM N. Let V be the poly. time verier for A that exists because A NP, assuming V runs in time O(n k ). N = On input w of length n: (1) Nondeterministically select string c of length at most n k (depth of the tree modelling the nondeterministic machine) (2) Run V on input < w, c >. (3) If V accepts, accept; otherwise, reject. To show (2): Assume that A is decided by a poly. time NTM N. Construct a polynomial time verier V for A. On input < w, c >, where w and c are strings: Simulate N on input w, treating each symbol of c as a description of the nondeterministic choice to make at each step, If this branch of N's computation accepts, accept; otherwise, reject.

Some Classical Optimization Problems Maximum Independent Set Maximum Clique Minimum Vertex Cover Traveling Salesman Problem Knapsack Problems Integer Linear Programming... All of these optimization problems have a decision version which is an NP problem. And there are many, many other problems too. Chandra & Lenny (UIUC) CS374 4 Spring 2015 4 / 62

Maximum Independent Set in a Graph Definition Given undirected graph G = (V, E) a subset of nodes S V is an independent set (also called a stable set) if for there are no edges between nodes in S. That is, if u, v S then (u, v) E. A B E C D F Some independent sets in graph above: {D}, {A, C}, {B, E, F} Chandra & Lenny (UIUC) CS374 5 Spring 2015 5 / 62

Maximum Independent Set Problem Input Graph G = (V, E) Goal Find maximum sized independent set in G A B E C D F MIS is an optimization problem. How do we cast it as a decision problem? Chandra & Lenny (UIUC) CS374 6 Spring 2015 6 / 62

Decision version of Maximum Independent Set 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} Chandra & Lenny (UIUC) CS374 7 Spring 2015 7 / 62

MIS is in NP L MIS = {< G, k > G has an independent set of size k} 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 1 S forms an independent set in G by checking that there is no edge in E between any pair of vertices in S 2 S k. 3 If S passes the above two tests output YES Else NO Chandra & Lenny (UIUC) CS374 8 Spring 2015 8 / 62

MIS is in NP L MIS = {< G, k > G has an independent set of size k} 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 1 S forms an independent set in G by checking that there is no edge in E between any pair of vertices in S 2 S k. 3 If S passes the above two tests output YES Else NO Key points: string encoding S, < S > has length polynomial in length of input < G, k > verification of guess is easily seen to be polynomial in length of < S > and < G, k >. Chandra & Lenny (UIUC) CS374 8 Spring 2015 8 / 62

Minimum Vertex Cover Definition Given undirected graph G = (V, E) a subset of nodes S V is an vertex cover if every edge (u, v) has at least one of its end points in S. That is, every edge is covered by S. A B E C D F Examples of vertex covers in graph above: Chandra & Lenny (UIUC) CS374 9 Spring 2015 9 / 62

Minimum Vertex Cover Input Graph G = (V, E) Goal Find minimum sized vertex cover in G A B E C D F Decision version: given G and k, does G have a vertex cover of size at most k? L VC = {< G, k > G has a vertex cover size k} Chandra & Lenny (UIUC) CS374 10 Spring 2015 10 / 62

Minimum Vertex Cover is in NP L VC = {< G, k > G has a vertex cover size k} A non-deterministic polynomial-time algorithm for L VC. 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 1 S forms a vertex cover in G by checking that for each edge (u, v) E at least one of u, v is in S 2 S k. 3 If S passes the above two tests output YES Else NO Chandra & Lenny (UIUC) CS374 11 Spring 2015 11 / 62

Minimum Vertex Cover is in NP L VC = {< G, k > G has a vertex cover size k} A non-deterministic polynomial-time algorithm for L VC. 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 1 S forms a vertex cover in G by checking that for each edge (u, v) E at least one of u, v is in S 2 S k. 3 If S passes the above two tests output YES Else NO Key points: string encoding S, < S > has length polynomial in length of input < G, k > verification of guess is easily seen to be polynomial in length of < S > and < G, k >. Chandra & Lenny (UIUC) CS374 11 Spring 2015 11 / 62

Sudoku Given n n sudoku puzzle, does it have a solution? Chandra & Lenny (UIUC) CS374 12 Spring 2015 12 / 62

Polynomial-Time Reducibility

Polynomial-Time Reducibility Definition: A Σ* is polynomial-time reducible to B Σ*, A p B, provided there is a polynomial-time computable function f: Σ* Σ* such that: ( w) [ w A if and only if f(x) B ] Σ* A f f Σ* B Extends to different alphabets Σ 1 and Σ 2. Same as mapping reducibility, m, but with a polynomial-time restriction.

Polynomial-Time Reducibility Definition: A Σ* is polynomial-time reducible to B Σ*, A p B, provided there is a polynomial-time computable function f: Σ* Σ* such that: ( w) [ w A if and only if f(x) B ] Theorem: (Transitivity of p ) If A p B and B p C then A p C. Proof: Let f be a polynomial-time reducibility function from A to B. Let g be a polynomial-time reducibility function from B to C. Σ* A f Σ* B Σ* B g Σ* C

Polynomial-Time Reducibility Definition: A p B, provided there is a polynomial-time computable function f: Σ* Σ* such that: ( w) [ w A if and only if f(w) B ] Theorem: If A p B and B p C then A p C. Proof: Let f be a polynomial-time reducibility function from A to B. Let g be a polynomial-time reducibility function from B to C. Σ* A f Σ* B Σ* B g Σ* C Define h(w) = g(f(w)). Then w A if and only if f(w) B if and only if g(f(w)) C. h is poly-time computable: h(w)

Polynomial-Time Reducibility Theorem: If A p B and B p C then A p C. Proof: Let f be a polynomial-time reducibility function from A to B. Let g be a polynomial-time reducibility function from B to C. Σ* A f Σ* B Σ* B g Σ* C Define h(w) = g(f(w)). h is poly-time computable: f(w) is bounded by a polynomial in w. Time to compute g(f(w)) is bounded by a polynomial in f(w), and therefore by a polynomial in w. Uses the fact that substituting one polynomial for the variable in another yields yet another polynomial.

Polynomial-Time Reducibility Definition: A p B, provided there is a polynomial-time computable function f: Σ* Σ* such that: ( w) [ w A if and only if f(x) B ] Theorem: If A p B and B P then A P. Proof: Let f be a polynomial-time reducibility function from A to B. Let M be a polynomial-time decider for B. To decide whether w A: Compute x = f(w). Run M to decide whether x B, and accept / reject accordingly. Polynomial time. Corollary: If A p B and A is not in P then B is not in P. Easiness propagates downward, hardness propagates upward.

Polynomial-Time Reducibility Can use p to relate the difficulty of two problems: Theorem: If A p B and B p A then either both A and B are in P or neither is. Also, for problems in NP: Theorem: If A p B and B NP then A NP. Proof: Let f be a polynomial-time reducibility function from A to B. Let M be a polynomial-time nondeterministic TM that decides B. Poly-bounded on all branches. Accepts on at least one branch iff and only if input string is in B. NTM M to decide membership in A: On input w: Compute x = f(w); x is bounded by a polynomial in w. Run M on x and accept/reject (on each branch) if M does. Polynomial time-bounded NTM.

Polynomial-Time Reducibility Theorem: If A p B and B NP then A NP. Proof: Let f be a polynomial-time reducibility function from A to B. Let M be a polynomial-time nondeterministic TM that decides B. NTM M to decide membership in A: On input w: Compute x = f(w); x is bounded by a polynomial in w. Run M on x and accept/reject (on each branch) if M does. Polynomial time-bounded NTM. Decides membership in A: M has an accepting branch on input w iff M has an accepting branch on f(w), by definition of M, iff f(w) B, since M decides B, iff w A, since A p B using f. So M is a poly-time NTM that decides A, A NP.

Polynomial-Time Reducibility Theorem: If A p B and B NP then A NP. Corollary: If A p B and A is not in NP, then B is not in NP.

Polynomial-Time Reducibility A technical result (curiosity): Theorem: If A P and B is any nontrivial language (meaning not, not Σ*), then A p B. Proof: Suppose A P. Suppose B is a nontrivial language; pick b 0 B, b 1 B c. Define f(w) = b 0 if w A, b 1 if w is not in A. f is polynomial-time computable; why? Because A is polynomial time decidable. Clearly w A if and only if f(w) B. So A p B. Trivial reduction: All the work is done by the decider for A, not by the reducibility and the decider for B.