COSC 3101A - Design and Analysis of Algorithms 14 NP-Completeness.

Slides:



Advertisements
Similar presentations
Analysis of Algorithms
Advertisements

Theory of Computing Lecture 18 MAS 714 Hartmut Klauck.
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.
NP-Completeness: Reductions
1 NP-Complete Problems. 2 We discuss some hard problems:  how hard? (computational complexity)  what makes them hard?  any solutions? Definitions 
CSC5160 Topics in Algorithms Tutorial 2 Introduction to NP-Complete Problems Feb Jerry Le
February 23, 2015CS21 Lecture 201 CS21 Decidability and Tractability Lecture 20 February 23, 2015.
Approximation Algorithms Lecture for CS 302. What is a NP problem? Given an instance of the problem, V, and a ‘certificate’, C, we can verify V is in.
NP-Complete Problems Reading Material: Chapter 10 Sections 1, 2, 3, and 4 only.
The Theory of NP-Completeness
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Spring, 2006 Lecture 7 Monday, 4/3/06 Approximation Algorithms.
NP-Complete Problems Problems in Computer Science are classified into
Analysis of Algorithms CS 477/677
Time Complexity.
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.
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.
P, NP, and NP-Complete Suzan Köknar-Tezel.
The Theory of NP-Completeness 1. Nondeterministic algorithms A nondeterminstic algorithm consists of phase 1: guessing phase 2: checking If the checking.
The Theory of NP-Completeness 1. What is NP-completeness? Consider the circuit satisfiability problem Difficult to answer the decision problem in polynomial.
MCS312: NP-completeness and Approximation Algorithms
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.
Nattee Niparnan. Easy & Hard Problem What is “difficulty” of problem? Difficult for computer scientist to derive algorithm for the problem? Difficult.
1 The TSP : NP-Completeness Approximation and Hardness of Approximation All exact science is dominated by the idea of approximation. -- Bertrand Russell.
Complexity Classes (Ch. 34) The class P: class of problems that can be solved in time that is polynomial in the size of the input, n. if input size is.
Lecture 22 More NPC problems
CSEP 521 Applied Algorithms Richard Anderson Lecture 10 NP Completeness.
Prabhas Chongstitvatana1 NP-complete proofs The circuit satisfiability proof of NP- completeness relies on a direct proof that L  p CIRCUIT-SAT for every.
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.
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.
NP-COMPLETE PROBLEMS. Admin  Two more assignments…  No office hours on tomorrow.
NP-Complete problems.
Instructor Neelima Gupta Table of Contents Class NP Class NPC Approximation Algorithms.
CS 3343: Analysis of Algorithms Lecture 25: P and NP Some slides courtesy of Carola Wenk.
NP-Algorithms Tractable vs Intractable Some problems are intractable: as they grow large, we are unable to solve them in reasonable time.
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.
NPC.
NP Completeness Piyush Kumar. Today Reductions Proving Lower Bounds revisited Decision and Optimization Problems SAT and 3-SAT P Vs NP Dealing with NP-Complete.
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.
CSE 421 Algorithms Richard Anderson Lecture 27 NP-Completeness Proofs.
The Theory of NP-Completeness 1. Nondeterministic algorithms A nondeterminstic algorithm consists of phase 1: guessing phase 2: checking If the checking.
COMPLEXITY. Satisfiability(SAT) problem Conjunctive normal form(CNF): Let S be a Boolean expression in CNF. That is, S is the product(and) of several.
The NP class. NP-completeness Lecture2. The NP-class The NP class is a class that contains all the problems that can be decided by a Non-Deterministic.
34.NP Completeness. Computer Theory Lab. Chapter 34P.2.
CSE 332: NP Completeness, Part II Richard Anderson Spring 2016.
TU/e Algorithms (2IL15) – Lecture 10 1 NP-Completeness, II.
Advanced Algorithms NP-hard and NP-Complete Problems Instructor: Saeid Abrishami Ferdowsi University of Mashhad.
Costas Busch - LSU 1 More NP-complete Problems. Costas Busch - LSU 2 Theorem: If: Language is NP-complete Language is in NP is polynomial time reducible.
ICS 353: Design and Analysis of Algorithms NP-Complete Problems King Fahd University of Petroleum & Minerals Information & Computer Science Department.
The Theory of NP-Completeness
NP-Completeness A problem is NP-complete if: It is in NP
More NP-complete problems
NP-completeness Ch.34.
Richard Anderson Lectures NP-Completeness
Richard Anderson Lecture 26 NP-Completeness
Advanced Algorithms Analysis and Design
More NP-complete Problems
Richard Anderson Lecture 26 NP-Completeness
ICS 353: Design and Analysis of Algorithms
Richard Anderson Lecture 25 NP-Completeness
Richard Anderson Lecture 28 NP-Completeness
Chapter 34: NP-Completeness
The Theory of NP-Completeness
CS154, Lecture 16: More NP-Complete Problems; PCPs
Presentation transcript:

COSC 3101A - Design and Analysis of Algorithms 14 NP-Completeness

8/03/2004 Lecture 14COSC3101A2 Classes “P” and “NP”  Class P consists of decision problems that are solvable in polynomial time:  O(n k ), k constant  Class NP consists of problems that are verifiable in polynomial time  Could be solved by nondeterministic polynomial algorithms

8/03/2004 Lecture 14COSC3101A3 Nondeterministic Algorithms Nondeterministic algorithm = two stage procedure: 1)Nondeterministic (“guessing”) stage: generate an arbitrary string that can be thought of as a candidate solution (“certificate”) 2)Deterministic (“verification”) stage: take the certificate and the instance to the problem and returns YES if the certificate represents a solution  Nondeterministic polynomial (NP) = verification stage is polynomial

8/03/2004 Lecture 14COSC3101A4 Polynomial time algorithm to decide A Polynomial Reduction Algorithm  To solve a decision problem A in polynomial time 1.Use a polynomial time reduction algorithm to transform A into B 2.Run a known polynomial time algorithm for B 3.Use the answer for B as the answer for A f Polynomial time algorithm to decide B  yes no yes no

8/03/2004 Lecture 14COSC3101A5 Reductions  Given two problems A, B, we say that A is reducible to B (A  p B) if: 1.There exists a function f that converts the input of A to inputs of B in polynomial time 2.A(i) = YES  B(f(i)) = YES

8/03/2004 Lecture 14COSC3101A6 NP-Completeness  A problem B is NP-complete if: 1) B  NP 2) A  p B for all A  NP  If B satisfies only property 2) we say that B is NP-hard  No polynomial time algorithm has been discovered for an NP-Complete problem  No one has ever proven that no polynomial time algorithm can exist for any NP-Complete problem

8/03/2004 Lecture 14COSC3101A7 Is P = NP?  Any problem in P is also in NP: P  NP  We can solve problems in P, even without having a certificate  The big (and open question) is whether P = NP Theorem: If any NP-Complete problem can be solved in polynomial time  then P = NP. P NP NP-complete

8/03/2004 Lecture 14COSC3101A8 P & NP-Complete Problems  Shortest simple path  Given a graph G = (V, E) find a shortest path from a source to all other vertices  Polynomial solution: O(VE)  Longest simple path  Given a graph G = (V, E) find a longest path from a source to all other vertices  NP-complete

8/03/2004 Lecture 14COSC3101A9 P & NP-Complete Problems  Euler tour  G = (V, E) a connected, directed graph find a cycle that traverses each edge of G exactly once (may visit a vertex multiple times)  Polynomial solution O(E)  Hamiltonian cycle  G = (V, E) a connected, directed graph find a cycle that visits each vertex of G exactly once  NP-complete

8/03/2004 Lecture 14COSC3101A10 Reduction and NP-Completeness  Suppose we know:  No polynomial time algorithm exists for problem A  We have a polynomial reduction f from A to B  No polynomial time algorithm exists for B f Problem B  yes no yes no Problem A

8/03/2004 Lecture 14COSC3101A11 Proving NP-Completeness Theorem: If A is NP-Complete and A  p B  B is NP-Hard In addition, if B  NP  B is NP-Complete Proof: Assume that B  P Since A  p B  A  P contradiction!  B is NP-Hard

8/03/2004 Lecture 14COSC3101A12 Proving NP-Completeness  Prove that the problem B is in NP  A randomly generated string can be checked in polynomial time to determine if it represents a solution  Show that one known NP-Complete problem can be transformed to B in polynomial time  No need to check that all NP-Complete problems are reducible to B

8/03/2004 Lecture 14COSC3101A13 Boolean Formula Satisfiability Formula Satisfiability Problem: a boolean formula  composed of 1.n boolean variables: x 1, x 2, …, x n 2.m boolean connectives:  (AND),  (OR),  (NOT),  (implication),  if and only if 3.Parenthesis Satisfying assignment: an assignment of values (0, 1) to variables x i that causes  to evaluate to 1 E.g.:  = (x 1  x 2 )  (x 1   x 2 )  (  x 1   x 2 ) Certificate: x 1 = 1, x 2 = 0   = 1  1  1 = 1  Formula Satisfiability is first to be proven NP-Complete

8/03/2004 Lecture 14COSC3101A14 3-CNF Satisfiability 3-CNF Satisfiability Problem:  n boolean variables: x 1, x 2, …, x n  Literal: x i or  x i (a variable or its negation)  Clause: c j = an OR of three literals (m clauses)  Formula:  = c 1  c 2  …  c m  E.g.:  = (x 1   x 1   x 2 )  (x 3  x 2  x 4 )  (  x 1   x 3   x 4 )  3-CNF is NP-Complete

8/03/2004 Lecture 14COSC3101A15 Clique Clique Problem:  Undirected graph G = (V, E)  Clique: a subset of vertices in V all connected to each other by edges in E (i.e., forming a complete graph)  Size of a clique: number of vertices it contains Optimization problem:  Find a clique of maximum size Decision problem:  Does G have a clique of size k? Clique(G, 2) = YES Clique(G, 3) = NO Clique(G, 3) = YES Clique(G, 4) = NO

8/03/2004 Lecture 14COSC3101A16 Clique Verifier  Given: an undirected graph G = (V, E)  Problem: Does G have a clique of size k?  Certificate:  A set of k nodes  Verifier:  Verify that for all pairs of vertices in this set there exists an edge in E

8/03/2004 Lecture 14COSC3101A17 3-CNF  p Clique  Start with an instance of 3-CNF:   = C 1  C 2  …  C k (k clauses)  Each clause C r has three literals: C r = l 1 r  l 2 r  l 3 r  Idea:  Construct a graph G such that  is satisfiable only if G has a clique of size k

8/03/2004 Lecture 14COSC3101A18 3-CNF  p Clique  For each clause C r = l 1 r  l 2 r  l 3 r place a triple of vertices v 1 r, v 2 r, v 3 r in V  Put an edge between two vertices v i r and v j s if:  v i r and v j s are in different triples  l i r is not the negation of l j s (consistent correspondent literals) x1x1 x2x2 x3x3 x1x1 x2x2 x3x3 x1x1 x2x2 x3x3 C 1 = x 1   x 2   x 3 C 2 =  x 1  x 2  x 3 C 3 = x 1  x 2  x 3  = C 1  C 2  C 3

8/03/2004 Lecture 14COSC3101A19 3-CNF  p Clique  Suppose  has a satisfying assignment  Each clause C r has a literal assigned to 1 – this corresponds to a vertex v i r  Picking one such literal from each C r  a set V’ of k vertices x1x1 x2x2 x3x3 x1x1 x2x2 x3x3 x1x1 x2x2 x3x3 C 1 = x 1   x 2   x 3 C 2 =  x 1  x 2  x 3 C 3 = x 1  x 2  x 3  = C 1  C 2  C 3 Claim: V’ is a clique –  v i r, v j s  V’ the corresponding literals are 1  cannot be complements – by the design of G the edge (v i r, v j s )  E

8/03/2004 Lecture 14COSC3101A20 3-CNF  p Clique  Suppose G has a clique of size k  No edges between nodes in the same clause  Clique contains only one vertex from each clause  Assign 1 to vertices in the clique  The literals of these vertices cannot belong to complementary literals  Each clause is satisfied   is satisfied x1x1 x2x2 x3x3 x1x1 x2x2 x3x3 x1x1 x2x2 x3x3 C 1 = x 1   x 2   x 3 C 2 =  x 1  x 2  x 3 C 3 = x 1  x 2  x 3  = C 1  C 2  C 3

8/03/2004 Lecture 14COSC3101A21 Vertex Cover  G = (V, E), undirected graph  Vertex cover = a subset V’  V such that covers all the edges  if (u, v)  E then u  V’ or v  V’ or both.  Size of a vertex cover = number of vertices in it Problem:  Find a vertex cover of minimum size  Does graph G have a vertex cover of size k? uv zw yx zw

8/03/2004 Lecture 14COSC3101A22 Clique  p Vertex Cover Size[Clique](G) + Size[V-C](G C ) = n  G has a clique of size k  G C has a vertex cover of size n – k  S is a clique in G  V – S is a vertex cover in G C Clique = 2V-C = 2 Clique = 2V-C = 3 G G GCGC GCGC

8/03/2004 Lecture 14COSC3101A23 Clique  p Vertex Cover uv zw yx GGCGC  G = (V, E)  G C = (V, E C ) E C = {(u, v):, u, v  V, and (u, v)  E} Idea:  G, k  (clique)   G C, |V|-k  (vertex cover) uv zw yx

8/03/2004 Lecture 14COSC3101A24 Clique  p Vertex Cover uv zw yx GGCGC  G has a clique V’  V, |V’| = k  V-V’ is a V-C in G C  Let (u, v)  E C  (u, v)  E  u and v were not connected in E  at least one of u or v does not belong in the clique V’  at least one of u or v belongs in V - V’  edge (u, v) is covered by V – V’  edge (u, v) was arbitrary  every edge of E C is covered uv zw yx

8/03/2004 Lecture 14COSC3101A25 Clique  p Vertex Cover uv zw yx GGCGC  G C has a vertex cover V’  V, |V’| = |V| - k  For all u, v  V, if (u, v)  E C  u  V’ or v  V’ or both  V’  For all u, v  V, if u  V’ and v  V’:  no edge between u, v in E G uv zw yx  V – V’ is a clique, of size |V| - |V’| = k  (u, v)  E

8/03/2004 Lecture 14COSC3101A26 The Traveling Salesman Problem  G = (V, E), |V| = n, vertices represent cities  Cost: c(i, j) = cost of travel from city i to city j  Problem: salesman should make a tour (hamiltonian cycle):  Visit each city only once  Finish at the city he started from  Total cost is minimum  TSP = tour with cost at most k uv xw  u, w, v, x, u 

8/03/2004 Lecture 14COSC3101A27 TSP  NP  Certificate:  Sequence of n vertices  Verification:  Each vertex occurs only once  Sum of costs is at most k uv xw

8/03/2004 Lecture 14COSC3101A28 HAM-CYCLE  p TSP  Start with an instance of Hamiltonian cycle G = (V, E)  Form the complete graph G’ = (V, E’) E’ = {(i, j): i, j  V and i  j} 0if (i, j)  E 1if (i, j)  E  TSP:  G’, c, 0   G has a hamiltonian cycle  G’ has a tour of cost at most 0 uv xw uv xw c(i, j) =

8/03/2004 Lecture 14COSC3101A29 HAM-CYCLE  p TSP  G has a hamiltonian cycle h  Each edge in h  E  has cost 0 in G’  h is a tour in G’ with cost 0 G’ has a tour h’ of cost at most 0  Each edge on tour must have cost 0  h’ contains only edges in E uv xw uv xw

8/03/2004 Lecture 14COSC3101A30 Approximation Algorithms Ways to get around NP-completeness: 1.If inputs are small, an algorithm with exponential time may be satisfactory 2.Isolate special cases, solvable in polynomial time 3.Find near-optimal solutions in polynomial time Approximation algorithms

8/03/2004 Lecture 14COSC3101A31 The Vertex-Cover Problem  Vertex cover of G = (V, E), undirected graph  A subset V’  V that covers all the edges in G  Idea:  Repeatedly pick an arbitrary edge (u, v)  Add its endpoints u and v to the vertex-cover set  Remove all edges incident on u or v bc a d efg

8/03/2004 Lecture 14COSC3101A32 APPROX-VERTEX-COVER(G) 1.C   2.E’  E[G] 3.while E’   4. do choose (u, v) arbitrary from E’ 5. C  C  {u, v} 6. remove from E’ all edges incident on u, v 7.return C bc a d efg bc a d efg bc a d efg

8/03/2004 Lecture 14COSC3101A33 APPROX-VERTEX-COVER(G) bc a d efg APPROX-VERTEX-COVER: bc a d efg Optimal VERTEX-COVER: The approximation algorithm returns an optimal solution that is no more than twice the optimal vertex cover

8/03/2004 Lecture 14COSC3101A34 The Set Covering Problem  Finite set X  Family F of subsets of X: F = {S 1, S 2, …, S n } X =  S  Find a minimum-size subset C  F that covers all the elements in X  Decision: given a number k find if there exist k sets S i1, S i2, …, S ik such that: S i1  S i2  …  S ik = X S  F

8/03/2004 Lecture 14COSC3101A35 Greedy Set Covering Idea:  At each step pick a set S that covers the greatest number of remaining elements S3S3 S5S5 S2S2 S6S6 S1S1 S4S4 Optimal: C = {S 3, S 4, S 5 }

8/03/2004 Lecture 14COSC3101A36 GREEDY-SET-COVER(X, F ) 1.U  X 2.C   3.while U   4. do select an S  F that maximizes |S  U| 5. U  U – S 6. C  C  {S} 7.return C S3S3 S5S5 S2S2 S6S6 S1S1 S4S4 S3S3 S5S5 S1S1 S4S4

8/03/2004 Lecture 14COSC3101A37 Readings  Chapters 34