CSC401 – Analysis of Algorithms Chapter 13 NP-Completeness Objectives: Introduce the definitions of P and NP problems Introduce the definitions of NP-hard.

Slides:



Advertisements
Similar presentations
Polynomial-time reductions We have seen several reductions:
Advertisements

1 NP-completeness Lecture 2: Jan P The class of problems that can be solved in polynomial time. e.g. gcd, shortest path, prime, etc. There are many.
Lecture 21 NP-complete problems
The Theory of NP-Completeness
INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011.
Complexity 11-1 Complexity Andrei Bulatov NP-Completeness.
February 23, 2015CS21 Lecture 201 CS21 Decidability and Tractability Lecture 20 February 23, 2015.
Computability and Complexity 15-1 Computability and Complexity Andrei Bulatov NP-Completeness.
Graphs 4/16/2017 8:41 PM NP-Completeness.
NP-Complete Problems Reading Material: Chapter 10 Sections 1, 2, 3, and 4 only.
The Theory of NP-Completeness
NP-Complete Problems Problems in Computer Science are classified into
Analysis of Algorithms CS 477/677
NP-Completeness NP-Completeness Graphs 4/17/2017 4:10 AM x x x x x x x
NP-Completeness (2) NP-Completeness Graphs 4/17/2017 6:25 AM x x x x x
CSE 421 Algorithms Richard Anderson Lecture 27 NP Completeness.
CS Master – Introduction to the Theory of Computation Jan Maluszynski - HT Lecture NP-Completeness Jan Maluszynski, IDA, 2007
Chapter 11: Limitations of Algorithmic Power
Toward NP-Completeness: Introduction Almost all the algorithms we studies so far were bounded by some polynomial in the size of the input, so we call them.
1 CSE 417: Algorithms and Computational Complexity Winter 2001 Lecture 22 Instructor: Paul Beame.
1 The Theory of NP-Completeness 2012/11/6 P: the class of problems which can be solved by a deterministic polynomial algorithm. NP : the class of decision.
NP-Completeness x 1 x 3 x 2 x 1 x 4 x 3 x 2 x
Lecture 22 More NPC problems
INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011.
Prabhas Chongstitvatana1 NP-complete proofs The circuit satisfiability proof of NP- completeness relies on a direct proof that L  p CIRCUIT-SAT for every.
1 NP-Completeness Poly time algorithm: input size n (in some encoding), worst case running time – O(n c ) for some constant c. Three classes of problems.
Polynomial-time reductions We have seen several reductions:
Week 10Complexity of Algorithms1 Hard Computational Problems Some computational problems are hard Despite a numerous attempts we do not know any efficient.
CSE 024: Design & Analysis of Algorithms Chapter 9: NP Completeness Sedgewick Chp:40 David Luebke’s Course Notes / University of Virginia, Computer Science.
EMIS 8373: Integer Programming NP-Complete Problems updated 21 April 2009.
1 The Theory of NP-Completeness 2 Cook ’ s Theorem (1971) Prof. Cook Toronto U. Receiving Turing Award (1982) Discussing difficult problems: worst case.
Unit 9: Coping with NP-Completeness
NP-Complete Problems. Running Time v.s. Input Size Concern with problems whose complexity may be described by exponential functions. Tractable problems.
1 Chapter 34: NP-Completeness. 2 About this Tutorial What is NP ? How to check if a problem is in NP ? Cook-Levin Theorem Showing one of the most difficult.
CS 3343: Analysis of Algorithms Lecture 25: P and NP Some slides courtesy of Carola Wenk.
CSE 589 Part V One of the symptoms of an approaching nervous breakdown is the belief that one’s work is terribly important. Bertrand Russell.
CS6045: Advanced Algorithms NP Completeness. NP-Completeness Some problems are intractable: as they grow large, we are unable to solve them in reasonable.
Lecture 25 NP Class. P = ? NP = ? PSPACE They are central problems in computational complexity.
Chapter 11 Introduction to Computational Complexity Copyright © 2011 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1.
NPC.
CSC 413/513: Intro to Algorithms
1 Ch 10 - NP-completeness Tractable and intractable problems Decision/Optimization problems Deterministic/NonDeterministic algorithms Classes P and NP.
CSCI 2670 Introduction to Theory of Computing December 2, 2004.
CSCI 2670 Introduction to Theory of Computing December 7, 2005.
CSE 421 Algorithms Richard Anderson Lecture 27 NP-Completeness Proofs.
Spring 2007NP-Completeness1 x 1 x 3 x 2 x 1 x 4 x 3 x 2 x
COSC 3101A - Design and Analysis of Algorithms 14 NP-Completeness.
Computability Examples. Reducibility. NP completeness. Homework: Find other examples of NP complete problems.
CSE 332: NP Completeness, Part II Richard Anderson Spring 2016.
TU/e Algorithms (2IL15) – Lecture 10 1 NP-Completeness, II.
ICS 353: Design and Analysis of Algorithms NP-Complete Problems King Fahd University of Petroleum & Minerals Information & Computer Science Department.
NP-Completeness (2) NP-Completeness Graphs 4/13/2018 5:22 AM x x x x x
Graphs 4/13/2018 5:25 AM Presentation for use with the textbook, Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, 2015 NP-Completeness.
NP-Completeness NP-Completeness Graphs 5/7/ :49 PM x x x x x x x
Richard Anderson Lecture 26 NP-Completeness
NP-Completeness (2) NP-Completeness Graphs 7/23/ :02 PM x x x x
NP-Completeness (2) NP-Completeness Graphs 7/23/ :02 PM x x x x
NP-Completeness Proofs
Richard Anderson Lecture 26 NP-Completeness
Hard Problems Introduction to NP
NP-Completeness Yin Tat Lee
NP-Completeness Merge Sort 11/16/2018 2:30 AM Spring 2007
NP-Completeness NP-Completeness Graphs 11/16/2018 2:32 AM x x x x x x
ICS 353: Design and Analysis of Algorithms
NP-Completeness (2) NP-Completeness Graphs 11/23/2018 2:12 PM x x x x
NP-Completeness NP-Completeness Graphs 12/3/2018 2:46 AM x x x x x x x
NP-Completeness NP-Completeness Graphs 12/6/2018 1:58 PM x x x x x x x
Chapter 34: NP-Completeness
NP-Completeness Yin Tat Lee
NP-Completeness (2) NP-Completeness Graphs 7/9/2019 6:12 AM x x x x x
Presentation transcript:

CSC401 – Analysis of Algorithms Chapter 13 NP-Completeness Objectives: Introduce the definitions of P and NP problems Introduce the definitions of NP-hard and NP-complete problems Present the Cook-Levin Theorem: the first NP-Complete problem Present some NP-complete problems

CSC401: Analysis of Algorithms Running Time Revisited Input size, n –To be exact, let n denote the number of bits in a nonunary encoding of the input All the polynomial-time algorithms studied so far in this course run in polynomial time using this definition of input size. –Exception: any pseudo-polynomial time algorithm ORD PVD MIA DFW SFO LAX LGA HNL

CSC401: Analysis of Algorithms Dealing with Hard Problems What to do when we find a problem that looks hard… – –I couldn’t find a polynomial-time algorithm, because I’m too dumb Sometimes we can prove a strong lower bound… (but not usually) – –I couldn’t find a polynomial-time algorithm, because no such algorithm exists! NP-completeness let’s us show collectively that a problem is hard. – –I couldn’t find a polynomial-time algorithm, but neither could all these other smart people.

CSC401: Analysis of Algorithms Polynomial-Time Decision Problems To simplify the notion of “hardness,” we will focus on the following: –Polynomial-time as the cut-off for efficiency –Decision problems: output is 1 or 0 (“yes” or no”) –Examples: Does a given graph G have an Euler tour? Does a text T contain a pattern P? Does an instance of 0/1 Knapsack have a solution with benefit at least K? Does a graph G have an MST with weight at most K?

CSC401: Analysis of Algorithms Problems and Languages A language L is a set of strings defined over some alphabet Σ Every decision algorithm A defines a language L –L is the set consisting of every string x such that A outputs “yes” on input x. –We say “A accepts x’’ in this case –Example: If A determines whether or not a given graph G has an Euler tour, then the language L for A is all graphs with Euler tours.

CSC401: Analysis of Algorithms The Complexity Class P A complexity class is a collection of languages P is the complexity class consisting of all languages that are accepted by polynomial-time algorithms For each language L in P there is a polynomial-time decision algorithm A for L. –If n=|x|, for x in L, then A runs in p(n) time on input x. –The function p(n) is some polynomial

CSC401: Analysis of Algorithms The Complexity Class NP We say that an algorithm is non-deterministic if it uses the following operation: –Choose(b): chooses a bit b –Can be used to choose an entire string y (with |y| choices) We say that a non-deterministic algorithm A accepts a string x if there exists some sequence of choose operations that causes A to output “yes” on input x. NP is the complexity class consisting of all languages accepted by polynomial-time non-deterministic algorithms. Example –Problem: Decide if a graph has an MST of weight K –Algorithm: 1.Non-deterministically choose a set T of n-1 edges 2.Test that T forms a spanning tree 3.Test that T has weight at most K –Analysis: Testing takes O(n+m) time, so this algorithm runs in polynomial time.

CSC401: Analysis of Algorithms The Complexity Class NP: Alternate Definition We say that an algorithm B verifies the acceptance of a language L if and only if, for any x in L, there exists a certificate y such that B outputs “yes” on input (x,y). NP is the complexity class consisting of all languages verified by polynomial-time algorithms. Example: –Problem: Decide if a graph has an MST of weight K –Verification Algorithm: 1.Use as a certificate, y, a set T of n-1 edges 2.Test that T forms a spanning tree 3.Test that T has weight at most K –Analysis: Verification takes O(n+m) time, so this algorithm runs in polynomial time.

CSC401: Analysis of Algorithms Equivalence of the Two Definitions Suppose A is a non-deterministic algorithm Let y be a certificate consisting of all the outcomes of the choose steps that A uses We can create a verification algorithm that uses y instead of A’s choose steps If A accepts on x, then there is a certificate y that allows us to verify this (namely, the choose steps A made) If A runs in polynomial-time, so does this verification algorithm Suppose B is a verification algorithm Non-deterministically choose a certificate y Run B on y If B runs in polynomial-time, so does this non-deterministic algorithm

CSC401: Analysis of Algorithms P and NP P is a subset of NP. –P is the complexity class consisting of all languages that are accepted by polynomial-timealgorithms. –P is the complexity class consisting of all languages that are accepted by polynomial-time algorithms. –NP is the complexity class consisting of all languages verified by polynomial-time algorithms. –A language that is accepted by polynomial- time algorithms must be verified by polynomial-time algorithms Major open question: P=NP? Most researchers believe that P and NP are different, but no body can prove it.

CSC401: Analysis of Algorithms An Interesting Problem: CIRCUIT-SAT A Boolean circuit is a circuit of AND, OR, and NOT gates; the CIRCUIT-SAT problem is to determine if there is an assignment of 0’s and 1’s to a circuit’s inputs so that the circuit outputs 1. CIRCUIT-SAT is in NP : Non-deterministically choose a set of inputs and the outcome of every gate, then test each gate’s I/O.

CSC401: Analysis of Algorithms NP-hard and NP-Completeness A problem (language) L is NP-Hard if every problem in NP can be reduced to L in polynomial time. –That is, for each language M in NP, we can take an input x for M, transform it in polynomial time to an input x’ for L such that x is in M if and only if x’ is in L. L is NP-complete if it’s in NP and is NP-hard. NP poly-time L

CSC401: Analysis of Algorithms Cook-Levin Theorem CIRCUIT-SAT is NP-complete. –We already showed it is in NP. To prove it is NP-hard, we have to show that every language in NP can be reduced to it. –Let M be in NP, and let x be an input for M. –Let y be a certificate that allows us to verify membership in M in polynomial time, p(n), by some algorithm D. –Let S be a circuit of size at most O(p(n) 2 ) that simulates a computer (details omitted…) NP poly-time CIRCUIT-SAT M

CSC401: Analysis of Algorithms Cook-Levin Proof We can build a circuit that simulates the verification of x’s membership in M using y. Let W be the working storage for D (including registers, such as program counter); let D be given in RAM “machine code.” Simulate p(n) steps of D by replicating circuit S for each step of D. Only input: y. Circuit is satisfiable if and only if x is accepted by D with some certificate y Total size is still polynomial: O(p(n) 3 ).

CSC401: Analysis of Algorithms Some Thoughts about P and NP Belief: P is a proper subset of NP. Implication: the NP-complete problems are the hardest in NP. Why: Because if we could solve an NP-complete problem in polynomial time, we could solve every problem in NP in polynomial time. That is, if an NP-complete problem is solvable in polynomial time, then P=NP. Since so many people have attempted without success to find polynomial-time solutions to NP-complete problems, showing your problem is NP-complete is equivalent to showing that a lot of smart people have worked on your problem and found no polynomial-time algorithm. NP P CIRCUIT-SAT NP-complete problems live here

CSC401: Analysis of Algorithms Problem Reduction A language M is polynomial-time reducible to a language L if an instance x for M can be transformed in polynomial time to an instance x’ for L such that x is in M if and only if x’ is in L. –Denote this by ML. A problem (language) L is NP-hard if every problem in NP is polynomial-time reducible to L. A problem (language) is NP-complete if it is in NP and it is NP-hard. CIRCUIT-SAT is NP-complete: –CIRCUIT-SAT is in NP –For every M in NP, M  CIRCUIT-SAT. Inputs: Output:

CSC401: Analysis of Algorithms Transitivity of Reducibility If A  B and B  C, then A  C. –An input x for A can be converted to x’ for B, such that x is in A if and only if x’ is in B. Likewise, for B to C. –Convert x’ into x’’ for C such that x’ is in B iff x’’ is in C. –Hence, if x is in A, x’ is in B, and x’’ is in C. –Likewise, if x’’ is in C, x’ is in B, and x is in A. –Thus, A  C, since polynomials are closed under composition. Types of reductions: –Local replacement: Show A  B by dividing an input to A into components and show how each component can be converted to a component for B. –Component design: Show A  B by building special components for an input of B that enforce properties needed for A, such as “choice” or “evaluate.”

CSC401: Analysis of Algorithms SAT A Boolean formula is a formula where the variables and operations are Boolean (0/1): –(a+b+¬d+e)(¬a+¬c)(¬b+c+d+e)(a+¬c+¬e) –OR: +, AND: (times), NOT: ¬ SAT: Given a Boolean formula S, is S satisfiable? that is, can we assign 0’s and 1’s to the variables so that S is 1 (“true”)? –Easy to see that SAT is in NP: Non-deterministically choose an assignment of 0’s and 1’s to the variables and then evaluate each clause. If they are all 1 (“true”), then the formula is satisfiable.

CSC401: Analysis of Algorithms SAT is NP-complete Reduce CIRCUIT-SAT to SAT. –Given a Boolean circuit, make a variable for every input and gate. –Create a sub-formula for each gate, characterizing its effect. Form the formula as the output variable AND-ed with all these sub-formulas: Example: m((a+b) ↔ e)(c ↔ ¬f)(d ↔ ¬g)(e ↔ ¬h)(ef ↔ i)… Inputs: a b c e f i d m Output: h k g j n The formula is satisfiable if and only if the Boolean circuit is satisfiable.

CSC401: Analysis of Algorithms SAT The SAT problem is still NP-complete even if the formula is a conjunction of disjuncts, that is, it is in conjunctive normal form (CNF)  CNF-SAT. The SAT problem is still NP-complete even if it is in CNF and every clause has just 3 literals (a variable or its negation)  3SAT –(a+b+¬d)(¬a+¬c+e)(¬b+d+e)(a+¬c+¬e) Reduction from SAT (See §13.3.1).

CSC401: Analysis of Algorithms Vertex Cover A vertex cover of graph G=(V,E) is a subset W of V, such that, for every edge (a,b) in E, a is in W or b is in W. VERTEX-COVER: Given an graph G and an integer K, is does G have a vertex cover of size at most K? VERTEX-COVER is in NP: Non-deterministically choose a subset W of size K and check that every edge is covered by W. Vertex-Cover is NP-hard: It can be transformed (reduced) from the 3SAT problem Therefore, Vertex-Cover is NP-Complete.

CSC401: Analysis of Algorithms Reduce 3SAT to VERTEX-COVER Let S be a Boolean formula in 3CNF x¬x a cb Construction: For each variable x, create a node for x and ¬x, and connect these two: For each clause (a+b+c), create a triangle and connect these three nodes. Connect each literal in a clause triangle to its copy in a variable pair. ¬d¬dd ¬c¬cc ¬a¬aa¬b¬bb Let n=# of variables, m=# of clauses 3SAT: The # of vertices =2n+3m, and K=n+2m Example: (a+b+c)(¬a+b+¬c)(¬b+¬c+¬d) Graph has vertex cover of size K=4+6=10 iff formula is satisfiable.

CSC401: Analysis of Algorithms Clique A clique of a graph G=(V,E) is a subgraph C that is fully-connected (every pair in C has an edge). CLIQUE: Given a graph G and an integer K, is there a clique in G of size at least K? This graph has a clique of size 5 CLIQUE is NP-Complete: –Reduction from VERTEX- COVER. –A graph G has a vertex cover of size K if and only if it’s complement has a clique of size n-K. CLIQUE is in NP: non-deterministically choose a subset C of size K and check that every pair in C has an edge in G. G G’

CSC401: Analysis of Algorithms Some Other NP-Complete Problems SET-COVER: Given a collection of m sets, are there K of these sets whose union is the same as the whole collection of m sets? –NP-complete by reduction from VERTEX-COVER SUBSET-SUM: Given a set of integers and a distinguished integer K, is there a subset of the integers that sums to K? –NP-complete by reduction from VERTEX-COVER 0/1 Knapsack: Given a collection of items with weights and benefits, is there a subset of weight at most W and benefit at least K? –NP-complete by reduction from SUBSET-SUM Hamiltonian-Cycle: Given an graph G, is there a cycle in G that visits each vertex exactly once? –NP-complete by reduction from VERTEX-COVER Traveling Saleperson Tour: Given a complete weighted graph G, is there a cycle that visits each vertex and has total cost at most K? –NP-complete by reduction from Hamiltonian-Cycle.