SAT, NP, NP-Completeness

Similar documents
NP and NP Completeness

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

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

More NP-Complete Problems

Intro to Theory of Computation

COP 4531 Complexity & Analysis of Data Structures & Algorithms

NP and Computational Intractability

Essential facts about NP-completeness:

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?

Recap from Last Time

Lecture 4: NP and computational intractability

Design and Analysis of Algorithms

Algorithm Design and Analysis

CS 583: Algorithms. NP Completeness Ch 34. Intractability

More on NP and Reductions

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

NP-Completeness Part II

Lecture 2 (Notes) 1. The book Computational Complexity: A Modern Approach by Sanjeev Arora and Boaz Barak;

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

NP-Complete Reductions 1

COMP Analysis of Algorithms & Data Structures

Correctness of Dijkstra s algorithm

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

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

NP Completeness and Approximation Algorithms

Lecture 20: conp and Friends, Oracles in Complexity Theory

CSE 135: Introduction to Theory of Computation NP-completeness

1. Introduction Recap

CSC 373: Algorithm Design and Analysis Lecture 15

CS 5114: Theory of Algorithms. Tractable Problems. Tractable Problems (cont) Decision Problems. Clifford A. Shaffer. Spring 2014

NP-Completeness Part II

NP-Complete Problems. More reductions

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

Algorithm Design and Analysis

Introduction to Computational Complexity

Geometric Steiner Trees

NP-Completeness. Subhash Suri. May 15, 2018

CSC 1700 Analysis of Algorithms: P and NP Problems

NP-Hardness reductions

Show that the following problems are NP-complete

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

Computability and Complexity Theory: An Introduction

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

P, NP, NP-Complete, and NPhard

CS 5114: Theory of Algorithms

CSE 421 NP-Completeness

SAT, Coloring, Hamiltonian Cycle, TSP

Computational Intractability 2010/4/15. Lecture 2

Spring Lecture 21 NP-Complete Problems

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

1.1 P, NP, and NP-complete

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

BBM402-Lecture 11: The Class NP

CS154, Lecture 13: P vs NP

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

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

Complexity Theory. Jörg Kreiker. Summer term Chair for Theoretical Computer Science Prof. Esparza TU München

NP-Completeness and Boolean Satisfiability

Polynomial-Time Reductions

NP-Completeness Part II

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

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

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

Algorithm Design and Analysis

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

U.C. Berkeley CS278: Computational Complexity Professor Luca Trevisan August 30, Notes for Lecture 1

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

CSE 555 HW 5 SAMPLE SOLUTION. Question 1.

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

Complexity Theory VU , SS The Polynomial Hierarchy. Reinhard Pichler

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

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

NP-Completeness. Algorithmique Fall semester 2011/12

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

Non-Deterministic Time

Introduction. Pvs.NPExample

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

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

Theory of Computation Chapter 9

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

Limitations of Algorithm Power

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

CS21 Decidability and Tractability

CS154, Lecture 13: P vs NP

Lecture 19: Finish NP-Completeness, conp and Friends

About the impossibility to prove P NP or P = NP and the pseudo-randomness in NP

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

Chapter 34: NP-Completeness

Instructor N.Sadagopan Scribe: P.Renjith

NP Completeness and Approximation Algorithms

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

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

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

Complexity, P and NP

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

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

6.080 / Great Ideas in Theoretical Computer Science Spring 2008

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

CSC373: Algorithm Design, Analysis and Complexity Fall 2017

Transcription:

CS 473: Algorithms, Spring 2018 SAT, NP, NP-Completeness Lecture 22 April 13, 2018 Most slides are courtesy Prof. Chekuri Ruta (UIUC) CS473 1 Spring 2018 1 / 57

Part I Reductions Continued Ruta (UIUC) CS473 2 Spring 2018 2 / 57

II: Partition and subset sum? Problem: Partition Instance: A set S of n numbers. Question: Is there a subset T S s.t. t T t = s S\T s? Problem: Subset Sum Instance: S - set of positive integers,t: - an integer number (target). Question: Is there a subset X S such that x X x = t? Assume that we can solve Partition in polynomial time, then we can solve Subset Sum in polynomial time. This statement is (A) True. (B) Mostly true. (C) False. (D) Mostly false. Ruta (UIUC) CS473 3 Spring 2018 3 / 57

Polynomial Time Reduction Karp reduction X P Y : algorithm A reduces problem X to problem Y in polynomial-time: 1 given an instance I X of X, A produces an instance I Y of Y 2 A runs in time poly( I X ) I Y = poly( I X ) 3 Answer to I X YES iff answer to I Y is YES. Ruta (UIUC) CS473 4 Spring 2018 4 / 57

Polynomial Time Reduction Karp reduction X P Y : algorithm A reduces problem X to problem Y in polynomial-time: 1 given an instance I X of X, A produces an instance I Y of Y 2 A runs in time poly( I X ) I Y = poly( I X ) 3 Answer to I X YES iff answer to I Y is YES. Consequences: poly-time algorithm for Y poly-time algorithm for X. X is hard Y is hard. Ruta (UIUC) CS473 4 Spring 2018 4 / 57

Polynomial Time Reduction Karp reduction X P Y : algorithm A reduces problem X to problem Y in polynomial-time: 1 given an instance I X of X, A produces an instance I Y of Y 2 A runs in time poly( I X ) I Y = poly( I X ) 3 Answer to I X YES iff answer to I Y is YES. Consequences: poly-time algorithm for Y poly-time algorithm for X. X is hard Y is hard. Note. X P Y Y P X Ruta (UIUC) CS473 4 Spring 2018 4 / 57

A More General Reduction Turing Reduction Definition (Turing reduction.) Problem X polynomial time reduces to Y if there is an algorithm A for X that has the following properties: 1 on any given instance I X of X, A uses polynomial in I X steps 2 a step is either a standard computation step, or 3 a sub-routine call to an algorithm that solves Y. This is a Turing reduction. Ruta (UIUC) CS473 5 Spring 2018 5 / 57

A More General Reduction Turing Reduction Definition (Turing reduction.) Problem X polynomial time reduces to Y if there is an algorithm A for X that has the following properties: 1 on any given instance I X of X, A uses polynomial in I X steps 2 a step is either a standard computation step, or 3 a sub-routine call to an algorithm that solves Y. This is a Turing reduction. Note: In making sub-routine call to algorithm to solve Y, A can only ask questions of size polynomial in I X. Why? Ruta (UIUC) CS473 5 Spring 2018 5 / 57

Comparing reductions 1 Karp reduction: yes I X Reduction I Y Solver for X Solver for Y no 2 Turing reduction: I X Algorithm Solver for Y yes no Turing reduction 1 Algorithm to solve X can call solver for Y poly( I x ) many times. 2 Input to every call is of size poly( I x ). Ruta (UIUC) CS473 6 Spring 2018 6 / 57

Example of Turing Reduction Problem (Independent set in circular arcs graph.) Input: Collection of arcs on a circle. Goal: Compute the maximum number of non-overlapping arcs. Reduced to the following problem:? Problem (Independent set of intervals.) Input: Collection of intervals on the line. Goal: Compute the maximum number of non-overlapping intervals. How? Ruta (UIUC) CS473 7 Spring 2018 7 / 57

Example of Turing Reduction Problem (Independent set in circular arcs graph.) Input: Collection of arcs on a circle. Goal: Compute the maximum number of non-overlapping arcs. Reduced to the following problem:? Problem (Independent set of intervals.) Input: Collection of intervals on the line. Goal: Compute the maximum number of non-overlapping intervals. How? Used algorithm for interval problem multiple times. Ruta (UIUC) CS473 7 Spring 2018 7 / 57

Turing vs Karp Reductions 1 Turing reductions more general than Karp reductions. 2 Turing reduction useful in obtaining algorithms via reductions. 3 Karp reduction is simpler and easier to use to prove hardness of problems. 4 Perhaps surprisingly, Karp reductions, although limited, suffice for most known NP-Completeness proofs. 5 Karp reductions allow us to distinguish between NP and co-np (more on this later). Ruta (UIUC) CS473 8 Spring 2018 8 / 57

Part II The Satisfiability Problem (SAT) Ruta (UIUC) CS473 9 Spring 2018 9 / 57

Propositional Formulas Definition Consider a set of boolean variables x 1, x 2,... x n. 1 A literal is either a boolean variable x i or its negation x i. Ruta (UIUC) CS473 10 Spring 2018 10 / 57

Propositional Formulas Definition Consider a set of boolean variables x 1, x 2,... x n. 1 A literal is either a boolean variable x i or its negation x i. 2 A clause is a disjunction of literals. For example, x 1 x 2 x 4 is a clause. Ruta (UIUC) CS473 10 Spring 2018 10 / 57

Propositional Formulas Definition Consider a set of boolean variables x 1, x 2,... x n. 1 A literal is either a boolean variable x i or its negation x i. 2 A clause is a disjunction of literals. For example, x 1 x 2 x 4 is a clause. 3 A formula in conjunctive normal form (CNF) is propositional formula which is a conjunction of clauses 1 (x 1 x 2 x 4 ) (x 2 x 3 ) x 5 is a CNF formula. Ruta (UIUC) CS473 10 Spring 2018 10 / 57

Propositional Formulas Definition Consider a set of boolean variables x 1, x 2,... x n. 1 A literal is either a boolean variable x i or its negation x i. 2 A clause is a disjunction of literals. For example, x 1 x 2 x 4 is a clause. 3 A formula in conjunctive normal form (CNF) is propositional formula which is a conjunction of clauses 1 (x 1 x 2 x 4 ) (x 2 x 3 ) x 5 is a CNF formula. 4 A formula ϕ is a 3CNF: A CNF formula such that every clause has exactly 3 literals. 1 (x 1 x 2 x 4 ) (x 2 x 3 x 1 ) is a 3CNF formula, but (x 1 x 2 x 4 ) (x 2 x 3 ) x 5 is not. Ruta (UIUC) CS473 10 Spring 2018 10 / 57

Satisfiability Problem: SAT Instance: A CNF formula ϕ. Question: Is there a truth assignment to the variable of ϕ such that ϕ evaluates to true? Problem: 3SAT Instance: A 3CNF formula ϕ. Question: Is there a truth assignment to the variable of ϕ such that ϕ evaluates to true? Ruta (UIUC) CS473 11 Spring 2018 11 / 57

Satisfiability SAT Given a CNF formula ϕ, is there a truth assignment to variables such that ϕ evaluates to true? Example 1 (x 1 x 2 x 4 ) (x 2 x 3 ) x 5 is satisfiable; take x 1, x 2,... x 5 to be all true 2 (x 1 x 2 ) ( x 1 x 2 ) ( x 1 x 2 ) (x 1 x 2 ) is not satisfiable. Ruta (UIUC) CS473 12 Spring 2018 12 / 57

Importance of SAT and 3SAT 1 SAT and 3SAT are basic constraint satisfaction problems. 2 Many different problems can reduced to them because of the simple yet powerful expressively of logical constraints. 3 Arise naturally in many applications involving hardware and software verification and correctness. 4 As we will see, it is a fundamental problem in theory of NP-Completeness. Ruta (UIUC) CS473 13 Spring 2018 13 / 57

3SAT P SAT 1 3SAT P SAT. 2 Because... A 3SAT instance is also an instance of SAT. Ruta (UIUC) CS473 14 Spring 2018 14 / 57

SAT P 3SAT Claim SAT P 3SAT. Ruta (UIUC) CS473 15 Spring 2018 15 / 57

SAT P 3SAT Claim SAT P 3SAT. Given ϕ a SAT formula we create a 3SAT formula ϕ such that 1 ϕ is satisfiable iff ϕ is satisfiable. 2 ϕ can be constructed from ϕ in time polynomial in ϕ. Ruta (UIUC) CS473 15 Spring 2018 15 / 57

SAT P 3SAT How SAT is different from 3SAT? In SAT clauses might have arbitrary length: 1, 2, 3,... variables: ( ) ( ) ( ) x y z w x y z w u x In 3SAT every clause must have exactly 3 different literals. Ruta (UIUC) CS473 16 Spring 2018 16 / 57

SAT P 3SAT How SAT is different from 3SAT? In SAT clauses might have arbitrary length: 1, 2, 3,... variables: ( ) ( ) ( ) x y z w x y z w u x In 3SAT every clause must have exactly 3 different literals. Consider ( x y z w ) Replace it with ( ) ( ) x y α α w u Ruta (UIUC) CS473 16 Spring 2018 16 / 57

SAT P 3SAT 1 Pad short clauses so they have 3 literals. 2 Break long clauses into shorter clauses. (Need to add new variables) 3 Repeat the above till we have a 3CNF. Ruta (UIUC) CS473 16 Spring 2018 16 / 57 How SAT is different from 3SAT? In SAT clauses might have arbitrary length: 1, 2, 3,... variables: ( ) ( ) ( ) x y z w x y z w u x In 3SAT every clause must have exactly 3 different literals. Consider ( x y z w ) Replace it with ( ) ( ) x y α α w u

What about 2SAT? Ruta (UIUC) CS473 17 Spring 2018 17 / 57

What about 2SAT? 2SAT can be solved in polynomial time! (specifically, linear time!) Ruta (UIUC) CS473 17 Spring 2018 17 / 57

What about 2SAT? 2SAT can be solved in polynomial time! (specifically, linear time!) No known polynomial time reduction from SAT (or 3SAT) to 2SAT. If there was, then SAT and 3SAT would be solvable in polynomial time. Ruta (UIUC) CS473 17 Spring 2018 17 / 57

What about 2SAT? 2SAT can be solved in polynomial time! (specifically, linear time!) No known polynomial time reduction from SAT (or 3SAT) to 2SAT. If there was, then SAT and 3SAT would be solvable in polynomial time. Why the reduction from 3SAT to 2SAT fails? Consider a clause (x y z). We need to reduce it to a collection of 2CNF clauses. Introduce a face variable α, and rewrite this as (x y α) ( α z) (bad! clause with 3 vars) or (x α) ( α y z) (bad! clause with 3 vars). (In animal farm language: 2SAT good, 3SAT bad.) Ruta (UIUC) CS473 17 Spring 2018 17 / 57

What about 2SAT? A challenging exercise: Given a 2SAT formula show to compute its satisfying assignment... Look in books etc. Ruta (UIUC) CS473 18 Spring 2018 18 / 57

Independent Set Problem: Independent Set Instance: A graph G, integer k. Question: Is there an independent set in G of size k? Ruta (UIUC) CS473 19 Spring 2018 19 / 57

Independent Set Problem: Independent Set Instance: A graph G, integer k. Question: Is there an independent set in G of size k? 3SAT P Independent Set Later (if time permits) Ruta (UIUC) CS473 19 Spring 2018 19 / 57

Part III Definition of P and NP Ruta (UIUC) CS473 20 Spring 2018 20 / 57

Recap... Problems 1 Independent Set 2 Vertex Cover 3 Set Cover 4 SAT 5 3SAT Ruta (UIUC) CS473 21 Spring 2018 21 / 57

Recap... Problems 1 Independent Set 2 Vertex Cover 3 Set Cover 4 SAT 5 3SAT Relationship 3SAT P Independent Set Ruta (UIUC) CS473 21 Spring 2018 21 / 57

Recap... Problems 1 Independent Set 2 Vertex Cover 3 Set Cover 4 SAT 5 3SAT Relationship 3SAT P Independent Set P P Vertex Cover Ruta (UIUC) CS473 21 Spring 2018 21 / 57

Recap... Problems 1 Independent Set 2 Vertex Cover 3 Set Cover 4 SAT 5 3SAT Relationship 3SAT P Independent Set P P Vertex Cover P Set Cover Ruta (UIUC) CS473 21 Spring 2018 21 / 57

Recap... Problems 1 Independent Set 2 Vertex Cover 3 Set Cover 4 SAT 5 3SAT Relationship 3SAT P Independent Set P P Vertex Cover P Set Cover 3SAT P SAT P 3SAT Ruta (UIUC) CS473 21 Spring 2018 21 / 57

Problems and Algorithms: Formal Approach Decision Problems 1 Problem Instance: Binary string s, with size s 2 Problem: A set X of strings on which the answer should be yes ; we call these YES instances of X. Strings not in X are NO instances of X. Definition 1 A is an algorithm for problem X if A(I x ) = yes iff I x X. 2 A is said to have a polynomial running time if there is a polynomial p( ) such that for every string I x, A(I x ) terminates in at most O(p( I x )) steps. Ruta (UIUC) CS473 22 Spring 2018 22 / 57

Deterministic Turing Machine P (polynomial-time): problems that deterministic TM solves in polynomial time. Ruta (UIUC) CS473 23 Spring 2018 23 / 57

Nondeterministic Turing Machine NP (nondeterministic polynomial time): problems that nondeterministc TM solves in polynomial time. Ruta (UIUC) CS473 24 Spring 2018 24 / 57

Polynomial Time Definition Polynomial time (denoted by P) is the class of all (decision) problems that have an algorithm that solves it in polynomial time. Ruta (UIUC) CS473 25 Spring 2018 25 / 57

Polynomial Time Definition Polynomial time (denoted by P) is the class of all (decision) problems that have an algorithm that solves it in polynomial time. Example Problems in P include 1 Is there a shortest path from s to t of length k in G? 2 Is there a flow of value k in network G? 3 Is there an assignment to variables to satisfy given linear constraints? Ruta (UIUC) CS473 25 Spring 2018 25 / 57

Problems with no known polynomial time algorithms Problems 1 Independent Set 2 Vertex Cover 3 Set Cover 4 SAT 5 3SAT There are of course undecidable problems (no algorithm at all!) but many problems that we want to solve are of similar flavor to the above. Question: What is common to above problems? Ruta (UIUC) CS473 26 Spring 2018 26 / 57

Efficient Checkability Above problems share the following feature: Checkability For any YES instance I X of X there is a proof/certificate/solution that is of length poly( I X ) such that given a proof one can efficiently check that I X is indeed a YES instance. Ruta (UIUC) CS473 27 Spring 2018 27 / 57

Efficient Checkability Above problems share the following feature: Checkability For any YES instance I X of X there is a proof/certificate/solution that is of length poly( I X ) such that given a proof one can efficiently check that I X is indeed a YES instance. Examples: 1 SAT formula ϕ: proof is a satisfying assignment. 2 Independent Set in graph G and k: Ruta (UIUC) CS473 27 Spring 2018 27 / 57

Efficient Checkability Above problems share the following feature: Checkability For any YES instance I X of X there is a proof/certificate/solution that is of length poly( I X ) such that given a proof one can efficiently check that I X is indeed a YES instance. Examples: 1 SAT formula ϕ: proof is a satisfying assignment. 2 Independent Set in graph G and k: a subset S of vertices. Ruta (UIUC) CS473 27 Spring 2018 27 / 57

Certifiers Definition An algorithm C(, ) is a certifier for problem X if for every I x X there is some string t such that C(I x, t) = yes, and conversely, if for some I x and t, C(I x, t) = yes then I x X. The string t is called a certificate or proof for s. Ruta (UIUC) CS473 28 Spring 2018 28 / 57

Certifiers Definition An algorithm C(, ) is a certifier for problem X if for every I x X there is some string t such that C(I x, t) = yes, and conversely, if for some I x and t, C(I x, t) = yes then I x X. The string t is called a certificate or proof for s. Definition (Efficient Certifier.) A certifier C is an efficient certifier for problem X if there is a polynomial p( ) such that for every string s, we have that I x X if and only if there is a string t: 1 t p( I x ), 2 C(I x, t) = yes, 3 and C runs in polynomial time in I x. Ruta (UIUC) CS473 28 Spring 2018 28 / 57

Example: Independent Set 1 Problem: Does G = (V, E) have an independent set of size k? 1 Certificate: Set S V. 2 Certifier: Check S k and no pair of vertices in S is connected by an edge. Ruta (UIUC) CS473 29 Spring 2018 29 / 57

Example: Vertex Cover 1 Problem: Does G have a vertex cover of size k? Ruta (UIUC) CS473 30 Spring 2018 30 / 57

Example: Vertex Cover 1 Problem: Does G have a vertex cover of size k? 1 Certificate: S V. 2 Certifier: Check S k and that for every edge at least one endpoint is in S. Ruta (UIUC) CS473 30 Spring 2018 30 / 57

Example: SAT 1 Problem: Does formula ϕ have a satisfying truth assignment? Ruta (UIUC) CS473 31 Spring 2018 31 / 57

Example: SAT 1 Problem: Does formula ϕ have a satisfying truth assignment? 1 Certificate: Assignment a of 0/1 values to each variable. 2 Certifier: Check each clause under a and say yes if all clauses are true. Ruta (UIUC) CS473 31 Spring 2018 31 / 57

Example: Composites Problem: Composite Instance: A number s. Question: Is the number s a composite? Ruta (UIUC) CS473 32 Spring 2018 32 / 57

Example: Composites Problem: Composite Instance: A number s. Question: Is the number s a composite? 1 Problem: Composite. 1 Certificate: A factor t s such that t 1 and t s. 2 Certifier: Check that t divides s. Ruta (UIUC) CS473 32 Spring 2018 32 / 57

Not composite? Problem: Not Composite Instance: A number s. Question: Is the number s not a composite? The problem Not Composite is (A) Can be solved in linear time. (B) in P. (C) Can be solved in exponential time. (D) Does not have a certificate or an efficient certifier. (E) The status of this problem is still open. Ruta (UIUC) CS473 33 Spring 2018 33 / 57

Nondeterministic Polynomial Time Alternate definition Definition Nondeterministic Polynomial Time (denoted by NP) is the class of all problems that have efficient certifiers. Ruta (UIUC) CS473 34 Spring 2018 34 / 57

Nondeterministic Polynomial Time Alternate definition Definition Nondeterministic Polynomial Time (denoted by NP) is the class of all problems that have efficient certifiers. Example Independent Set, Vertex Cover, Set Cover, SAT, 3SAT, and Composite are all examples of problems in NP. Guess the certificate and verify nondeterministic TM. Ruta (UIUC) CS473 34 Spring 2018 34 / 57

Asymmetry in Definition of NP Note that only YES instances have a short proof/certificate. NO instances need not have a short certificate. Example SAT formula ϕ. No easy way to prove that ϕ is NOT satisfiable! More on this and co-np later on. Ruta (UIUC) CS473 35 Spring 2018 35 / 57

P versus NP Proposition P NP. Ruta (UIUC) CS473 36 Spring 2018 36 / 57

P versus NP Proposition P NP. For a problem in P no need for a certificate! Proof. Consider problem X P with algorithm A. 1 Certifier C on input I x, t, runs A(I x ) and returns the answer. C runs in polynomial time. If I x X, then for every t, C(I x, t) = yes. If I x X, then for every t, C(I x, t) = no. Ruta (UIUC) CS473 36 Spring 2018 36 / 57

Exponential Time Definition Exponential Time (denoted EXP) is the collection of all problems that have an algorithm which on input I x runs in exponential time, i.e., O(2 poly( Ix ) ). Ruta (UIUC) CS473 37 Spring 2018 37 / 57

Exponential Time Definition Exponential Time (denoted EXP) is the collection of all problems that have an algorithm which on input I x runs in exponential time, i.e., O(2 poly( Ix ) ). Example: O(2 n ), O(2 n log n ), O(2 n3 ),... Ruta (UIUC) CS473 37 Spring 2018 37 / 57

NP versus EXP Proposition NP EXP. Proof. Let X NP with certifier C. Need to design an exponential time algorithm for X. 1 For every t, with t p( I x ) run C(I x, t); answer yes if any one of these calls returns yes. 2 The above algorithm correctly solves X (exercise). 3 Algorithm runs in O(q( I x + p( I x ))2 p( Ix ) ), where q is the running time of C. Ruta (UIUC) CS473 38 Spring 2018 38 / 57

Examples 1 SAT: try all possible truth assignment to variables. 2 Independent Set: try all possible subsets of vertices. 3 Vertex Cover: try all possible subsets of vertices. Ruta (UIUC) CS473 39 Spring 2018 39 / 57

Is NP efficiently solvable? We know P NP EXP. Ruta (UIUC) CS473 40 Spring 2018 40 / 57

Is NP efficiently solvable? We know P NP EXP. Big Question Is there a problem in NP that does not belong to P? Or is P = NP? Ruta (UIUC) CS473 40 Spring 2018 40 / 57

If P = NP... Or: If pigs could fly then life would be sweet. 1 Many important optimization problems can be solved efficiently. Ruta (UIUC) CS473 41 Spring 2018 41 / 57

If P = NP... Or: If pigs could fly then life would be sweet. 1 Many important optimization problems can be solved efficiently. 2 The RSA cryptosystem can be broken. Ruta (UIUC) CS473 41 Spring 2018 41 / 57

If P = NP... Or: If pigs could fly then life would be sweet. 1 Many important optimization problems can be solved efficiently. 2 The RSA cryptosystem can be broken. 3 No security on the web. Ruta (UIUC) CS473 41 Spring 2018 41 / 57

If P = NP... Or: If pigs could fly then life would be sweet. 1 Many important optimization problems can be solved efficiently. 2 The RSA cryptosystem can be broken. 3 No security on the web. 4 No e-commerce... Ruta (UIUC) CS473 41 Spring 2018 41 / 57

If P = NP... Or: If pigs could fly then life would be sweet. 1 Many important optimization problems can be solved efficiently. 2 The RSA cryptosystem can be broken. 3 No security on the web. 4 No e-commerce... 5 Creativity can be automated! Proofs for mathematical statement can be found by computers automatically (if short ones exist). Ruta (UIUC) CS473 41 Spring 2018 41 / 57

If P = NP this implies that... (A) Vertex Cover can be solved in polynomial time. (B) P = EXP. (C) EXP P. (D) All of the above. Ruta (UIUC) CS473 42 Spring 2018 42 / 57

P versus NP Status Relationship between P and NP remains one of the most important open problems in mathematics/computer science. Consensus: Most people feel/believe P NP. Resolving P versus NP is a Clay Millennium Prize Problem. You can win a million dollars in addition to a Turing award and major fame! Ruta (UIUC) CS473 43 Spring 2018 43 / 57

Part IV NP-Completeness and Cook-Levin Theorem Ruta (UIUC) CS473 44 Spring 2018 44 / 57

Hardest Problems Question What is the hardest problem in NP? How do we define it? Towards a definition 1 Hardest problem must be in NP. 2 Hardest problem must be at least as difficult as every other problem in NP. Ruta (UIUC) CS473 45 Spring 2018 45 / 57

NP-Complete Problems Definition A problem X is said to be NP-Hard if 1 (Hardness) For any Y NP, we have that Y P X. Ruta (UIUC) CS473 46 Spring 2018 46 / 57

NP-Complete Problems Definition A problem X is said to be NP-Hard if 1 (Hardness) For any Y NP, we have that Y P X. Definition A problem X is said to be NP-Complete if 1 X NP, and 2 X is NP-Hard Ruta (UIUC) CS473 46 Spring 2018 46 / 57

NP-Complete Problems Definition A problem X is said to be NP-Hard if 1 (Hardness) For any Y NP, we have that Y P X. Definition A problem X is said to be NP-Complete if 1 X NP, and 2 X is NP-Hard An NP-Hard problem need not be in NP! Example: Halting problem is NP-Hard (why?) but not NP-Complete. Ruta (UIUC) CS473 46 Spring 2018 46 / 57

Solving NP-Complete Problems Proposition Suppose X is NP-Complete. Then X can be solved in polynomial time if and only if P = NP. Proof. Suppose X can be solved in polynomial time 1 Let Y NP. We know Y P X. 2 Then Y can be solved in polynomial time. Y P. Ruta (UIUC) CS473 47 Spring 2018 47 / 57

Solving NP-Complete Problems Proposition Suppose X is NP-Complete. Then X can be solved in polynomial time if and only if P = NP. Proof. Suppose X can be solved in polynomial time 1 Let Y NP. We know Y P X. 2 Then Y can be solved in polynomial time. Y P. 3 Thus, Y NP Y P; NP P. 4 Since P NP, we have P = NP. Ruta (UIUC) CS473 47 Spring 2018 47 / 57

Solving NP-Complete Problems Proposition Suppose X is NP-Complete. Then X can be solved in polynomial time if and only if P = NP. Proof. Suppose X can be solved in polynomial time 1 Let Y NP. We know Y P X. 2 Then Y can be solved in polynomial time. Y P. 3 Thus, Y NP Y P; NP P. 4 Since P NP, we have P = NP. Since P = NP, and X NP, we have a polynomial time algorithm for X. Ruta (UIUC) CS473 47 Spring 2018 47 / 57

Consequences of proving NP-Completeness If X is NP-Complete 1 Since we believe P NP, 2 and solving X implies P = NP. X is unlikely to be efficiently solvable. Ruta (UIUC) CS473 48 Spring 2018 48 / 57

Consequences of proving NP-Completeness If X is NP-Complete 1 Since we believe P NP, 2 and solving X implies P = NP. X is unlikely to be efficiently solvable. At the very least, many smart people before you have failed to find an efficient algorithm for X. Ruta (UIUC) CS473 48 Spring 2018 48 / 57

Consequences of proving NP-Completeness If X is NP-Complete 1 Since we believe P NP, 2 and solving X implies P = NP. X is unlikely to be efficiently solvable. At the very least, many smart people before you have failed to find an efficient algorithm for X. Ruta (UIUC) CS473 48 Spring 2018 48 / 57

Consequences of proving NP-Completeness If X is NP-Complete 1 Since we believe P NP, 2 and solving X implies P = NP. X is unlikely to be efficiently solvable. At the very least, many smart people before you have failed to find an efficient algorithm for X. (This is proof by mob opinion take with a grain of salt.) Ruta (UIUC) CS473 48 Spring 2018 48 / 57

NP-Complete Problems Question Are there any problems that are NP-Complete? Answer Yes! Many, many problems are NP-Complete. Ruta (UIUC) CS473 49 Spring 2018 49 / 57

Cook-Levin Theorem Theorem SAT is NP-Complete. Ruta (UIUC) CS473 50 Spring 2018 50 / 57

Cook-Levin Theorem Theorem SAT is NP-Complete. Using reductions one can prove that many other problems are NP-Complete Ruta (UIUC) CS473 50 Spring 2018 50 / 57

Proving that a problem X is NP-Complete To prove X is NP-Complete, show 1 Show X is in NP. 1 certificate/proof of polynomial size in input 2 polynomial time certifier C(s, t) 2 Reduction from a known NP-Complete problem such as 3SAT or SAT to X Ruta (UIUC) CS473 51 Spring 2018 51 / 57

Proving that a problem X is NP-Complete To prove X is NP-Complete, show 1 Show X is in NP. 1 certificate/proof of polynomial size in input 2 polynomial time certifier C(s, t) 2 Reduction from a known NP-Complete problem such as 3SAT or SAT to X SAT P X implies that every NP problem Y P X. Why? Ruta (UIUC) CS473 51 Spring 2018 51 / 57

Proving that a problem X is NP-Complete To prove X is NP-Complete, show 1 Show X is in NP. 1 certificate/proof of polynomial size in input 2 polynomial time certifier C(s, t) 2 Reduction from a known NP-Complete problem such as 3SAT or SAT to X SAT P X implies that every NP problem Y P X. Why? Transitivity of reductions: Y P SAT and SAT P X and hence Y P X. Ruta (UIUC) CS473 51 Spring 2018 51 / 57

NP-Completeness via Reductions 1 SAT is NP-Complete. 2 SAT P 3-SAT and hence 3-SAT is NP-Complete. 3 3-SAT P Independent Set (which is in NP) and hence Independent Set is NP-Complete. 4 Clique is NP-Complete 5 Vertex Cover is NP-Complete 6 Set Cover is NP-Complete 7 Hamilton Cycle is NP-Complete 8 3-Color is NP-Complete Ruta (UIUC) CS473 52 Spring 2018 52 / 57

NP-Completeness via Reductions 1 SAT is NP-Complete. 2 SAT P 3-SAT and hence 3-SAT is NP-Complete. 3 3-SAT P Independent Set (which is in NP) and hence Independent Set is NP-Complete. 4 Clique is NP-Complete 5 Vertex Cover is NP-Complete 6 Set Cover is NP-Complete 7 Hamilton Cycle is NP-Complete 8 3-Color is NP-Complete Hundreds and thousands of different problems from many areas of science and engineering have been shown to be NP-Complete. A surprisingly frequent phenomenon! Ruta (UIUC) CS473 52 Spring 2018 52 / 57

3SAT P Independent Set The reduction 3SAT P Independent Set Input: Given a 3CNF formula ϕ Goal: Construct a graph G ϕ and number k such that G ϕ has an independent set of size k if and only if ϕ is satisfiable. Ruta (UIUC) CS473 53 Spring 2018 53 / 57

3SAT P Independent Set The reduction 3SAT P Independent Set Input: Given a 3CNF formula ϕ Goal: Construct a graph G ϕ and number k such that G ϕ has an independent set of size k if and only if ϕ is satisfiable. G ϕ should be constructable in time polynomial in size of ϕ Ruta (UIUC) CS473 53 Spring 2018 53 / 57

3SAT P Independent Set The reduction 3SAT P Independent Set Input: Given a 3CNF formula ϕ Goal: Construct a graph G ϕ and number k such that G ϕ has an independent set of size k if and only if ϕ is satisfiable. G ϕ should be constructable in time polynomial in size of ϕ Importance of reduction: Although 3SAT is much more expressive, it can be reduced to a seemingly specialized Independent Set problem. Ruta (UIUC) CS473 53 Spring 2018 53 / 57

Interpreting 3SAT There are two ways to think about 3SAT Ruta (UIUC) CS473 54 Spring 2018 54 / 57

Interpreting 3SAT There are two ways to think about 3SAT 1 Find a way to assign 0/1 (false/true) to the variables such that the formula evaluates to true, that is each clause evaluates to true. Ruta (UIUC) CS473 54 Spring 2018 54 / 57

Interpreting 3SAT There are two ways to think about 3SAT 1 Find a way to assign 0/1 (false/true) to the variables such that the formula evaluates to true, that is each clause evaluates to true. 2 Pick a literal from each clause and find a truth assignment to make all of them true Ruta (UIUC) CS473 54 Spring 2018 54 / 57

Interpreting 3SAT There are two ways to think about 3SAT 1 Find a way to assign 0/1 (false/true) to the variables such that the formula evaluates to true, that is each clause evaluates to true. 2 Pick a literal from each clause and find a truth assignment to make all of them true. You will fail if two of the literals you pick are in conflict, i.e., you pick x i and x i We will take the second view of 3SAT to construct the reduction. Ruta (UIUC) CS473 54 Spring 2018 54 / 57

The Reduction 1 G ϕ will have one vertex for each literal in a clause x 1 x 2 x 1 x 3 x 2 x 1 x 3 x 2 x 4 Figure: Graph for ϕ = ( x 1 x 2 x 3 ) (x 1 x 2 x 3 ) ( x 1 x 2 x 4 ) Ruta (UIUC) CS473 55 Spring 2018 55 / 57

The Reduction 1 G ϕ will have one vertex for each literal in a clause 2 Connect the 3 literals in a clause to form a triangle; the independent set will pick at most one vertex from each clause, which will correspond to the literal to be set to true x 1 x 2 x 1 x 3 x 2 x 1 x 3 x 2 x 4 Figure: Graph for ϕ = ( x 1 x 2 x 3 ) (x 1 x 2 x 3 ) ( x 1 x 2 x 4 ) Ruta (UIUC) CS473 55 Spring 2018 55 / 57

The Reduction 1 G ϕ will have one vertex for each literal in a clause 2 Connect the 3 literals in a clause to form a triangle; the independent set will pick at most one vertex from each clause, which will correspond to the literal to be set to true x 1 x 2 x 1 x 3 x 2 x 1 x 3 x 2 x 4 Figure: Graph for ϕ = ( x 1 x 2 x 3 ) (x 1 x 2 x 3 ) ( x 1 x 2 x 4 ) Ruta (UIUC) CS473 55 Spring 2018 55 / 57

The Reduction 1 G ϕ will have one vertex for each literal in a clause 2 Connect the 3 literals in a clause to form a triangle; the independent set will pick at most one vertex from each clause, which will correspond to the literal to be set to true 3 Connect 2 vertices if they label complementary literals; this ensures that the literals corresponding to the independent set do not have a conflict x 1 x 2 x 1 x 3 x 2 x 1 x 3 x 2 x 4 Figure: Graph for ϕ = ( x 1 x 2 x 3 ) (x 1 x 2 x 3 ) ( x 1 x 2 x 4 ) Ruta (UIUC) CS473 55 Spring 2018 55 / 57

The Reduction 1 G ϕ will have one vertex for each literal in a clause 2 Connect the 3 literals in a clause to form a triangle; the independent set will pick at most one vertex from each clause, which will correspond to the literal to be set to true 3 Connect 2 vertices if they label complementary literals; this ensures that the literals corresponding to the independent set do not have a conflict 4 Take k to be the number of clauses x 1 x 2 x 1 x 3 x 2 x 1 x 3 x 2 x 4 Figure: Graph for ϕ = ( x 1 x 2 x 3 ) (x 1 x 2 x 3 ) ( x 1 x 2 x 4 ) Ruta (UIUC) CS473 55 Spring 2018 55 / 57

Correctness Proposition ϕ is satisfiable iff G ϕ has an independent set of size k (= number of clauses in ϕ). Proof. Let a be the truth assignment satisfying ϕ Ruta (UIUC) CS473 56 Spring 2018 56 / 57

Correctness Proposition ϕ is satisfiable iff G ϕ has an independent set of size k (= number of clauses in ϕ). Proof. Let a be the truth assignment satisfying ϕ 1 Pick one of the vertices, corresponding to true literals under a, from each triangle. This is an independent set of the appropriate size Ruta (UIUC) CS473 56 Spring 2018 56 / 57

Correctness (contd) Proposition ϕ is satisfiable iff G ϕ has an independent set of size k (= number of clauses in ϕ). Proof. Let S be an independent set of size k 1 S must contain exactly one vertex from each clause 2 S cannot contain vertices labeled by conflicting clauses 3 Thus, it is possible to obtain a truth assignment that makes in the literals in S true; such an assignment satisfies one literal in every clause Ruta (UIUC) CS473 57 Spring 2018 57 / 57