x 1 x 1 x 2 x 2 x 3 x 3 x 4 x 4 12 22 32 CS 447 11 13 21 23 31 33 Algorithms NP-Complete Reductions 2 Prof. Gregory Provan Department of Computer Science University College Cork 1
Lecture Outline NP-Complete Reductions 2 Objectives: To introduce more NP-Complete problems. Overview: 3SAT CLIQUE & INDEPENDENT-SET SUBSET-SUM x 1 x 1 x 2 x 2 x 3 x 3 x 4 x 4 12 22 32 11 13 21 23 31 33
Today s Learning Objectives Review of Reduction techniques Local replacement Component design Additional examples of NP-complete problem reductions 3SAT Clique Independent Set Subset-Sum
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 NPhard. CIRCUIT-SAT is NP-complete: CIRCUIT-SAT is in NP For every M in NP, M CIRCUIT-SAT. Inputs: 1 1 1 1 1 Output: 1 1 1
Reducibility Chart CIRCUIT-SAT SAT 3CNF-SAT Clique HAM-CYCLE VERTEX COVER TSP SUBSET-SUM
Method How to show a problem is in NPC? First show it s in NP Then show it is NP-hard by reducing some NP- Hard problem to it.
Reducibility Techniques 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.
New Base Problems Start by introducing a useful variants of SAT 3SAT We ll use it as our base problem Perform reductions to additional problems
3SAT Instance: a 3CNF formula Problem: To decide if the formula is satisfiable. A satisfiable 3CNF formula (x y z) (x y z) An unsatisfiable 3CNF formula (x x x) ( x x x)
3SAT is NP-Complete 3SAT is a special case of SAT, and is therefore clearly in NP. In order to show it s also NP-Complete, reduce SAT s formula so it produces a 3CNF formula. Ensure Polynomial-time reduction
3SAT is NP-Complete 3SAT is a special case of SAT, and is therefore clearly in NP. In order to show it s also NP-Complete, we ll alter the proof of SAT s NP-Completeness so it produces 3CNF formulas. Polynomial-time reduction
Revisiting SAT s NP-Completeness Proof Given a TM and an input we ve produced a conjunction of: φ cell = x i,j,s k 1 i,j n s C s t C (x i,j,s x i,j, t ) φ start = x1,1,# x1,2,q x1,3,w... x1,n 2,_... x k 1 + 1,n 1,_ x 1,n k,# φ accept = ( ) + + φ = x... x move i 1,j,a i 1,j 1,a 1 i,j n legal a,...,a k 1 6 1 6 1 i,j n k x i,j,q accept
Transforming the Formula into a CNF Formula All the sub-formulas, but φ move, form a CNF formula. Using the distributive law we can transform φ move into a conjunction of clauses. The formula stays succinct (check!).
CNF 3CNF (x y) (x 1 x 2... x t )... clauses with 1 or 2 literals clauses with more than 3 literals replication split (x y x) (x 1 x 2 c 11 ) ( c 11 x 3 c 12 )... ( c 1t-3 x t-1 x t )
3SAT is NP-Complete Since we ve shown a reduction from SAT (any NP problem) to 3SAT, and 3SAT is in NP, 3SAT is NP-Complete.
CLIQUE Instance: A graph G=(V,E) and a threshold k. Problem: To decide if there is a set of nodes C={v 1,...,v k } V, s.t for any u,v C: (u,v) E.
CLIQUE is in NP On input G=(V,E),k: Guess C={v 1,...,v k } V For any u,v C: verify (u,v) E Reject if one of the tests fail, accept otherwise. The length of the certificate: O(n) (n= V ) Time complexity: O(n 2 )
CLIQUE is NP-Complete Proof: We ll show 3SAT p CLIQUE. (......)... (......) p
CLIQUE is NP-Complete Already showed that CLIQUE NP. Will show that 3-SAT P CLIQUE, i.e. a poly-time reduction f that takes as input a 3-CNF-formula φ outputs G,k = f( φ ) s.t. φ is satisfiable iff G has a k- clique
The Reduction for any clause (α β γ) V = formula s length α β γ K= no. of clauses connected iff α δ δ
Poly-time Reduction from 3-SAT to CLIQUE Input: A 3-CNF-formula φ. Let k = # of clauses in φ. Output: G,k, where G is constructed as follows: Nodes in G divided into k triples: Each triple corresponds to a clause in φ. φ Each node in a triple corresponds to a literal in the corresponding clause. Edges in G connect all but two types of nodes: No edge between any two nodes (literals) in the same triple (clause) No edge between any two nodes (literals) with contradictory labels, i.e. one labeled with x and the other labeled x for some x.
Poly-time Reduction from 3-SAT to CLIQUE Example: φ = (x y z) ( x y z) ( x y z) x y z x y x y z z
Poly-time Reduction from 3-SAT to CLIQUE Claim φ satisfiable G has a k-clique φ satisfiable an assignment s.t. each of the k clauses of φ has at least 1 satisfied literal Take 1 satisfied literal from each clause. Then by construction of G, the corresponding k nodes in G form a k- clique in G: No two of the k literals can be contradictory, as all the k literals are satisfied. Each of the k literals (nodes) comes from a distinct clause (triple).
Poly-time Reduction from 3-SAT to CLIQUE Claim G has a k-clique φ satisfiable Suppose G has a k-clique C Then by construction of G, Each of the k nodes (literal) of C comes from a distinct triple (clause) No two of the k nodes can be contradictory Hence we can satisfy all the k corresponding literals, thus all the k clauses, and thus φ.
Another View: Proof of Correctness 1 NOT connected!... a clique of size k must contain one node from every layer. k
Correctness given a k-clique, assign x TRUE or FALSE according to whether x or x is in the clique; this satisfies the formula (......)... (......). given a satisfying assignment, a set comprising of one satisfied literal of each clause forms a k-clique.
INDEPENDENT-SET Instance: A graph G=(V,E) and a goal k. Problem: To decide if there is a set of nodes I={v 1,...,v k } V, s.t for any u,v I: (u,v) E.
INDEPENDENT-SET NP On input G=(V,E),k: Guess I={v 1,...,v k } V For any u,v C: verify (u,v) E Reject if one of the tests fail, accept otherwise. The length of the certificate: O(n) (n= V ) Time complexity: O(n 2 )
INDEPENDENT-SET is NPC Proof: By the previous claim and a trivial reduction from CLIQUE. there s a clique of size k in a graph there s an IS of size k in its complement
Formal Proof: Example Vertex Cover is NP-Complete
Vertex Cover Def A vertex cover of a graph G = (V, E) is a subset V V s.t. if (u,v) E, then either u V or v V. Optimization Problem: Find a minimum vertex cover of a graph G. Decision Problem: Does a graph G have a vertex cover of size k? VERTEX-COVER = { G,k : G has a vertex cover of size k} Clearly, VERTEX-COVER NP A VC of size k is a proof that G has a VC of size k.
VERTEX-COVER is NP-Complete Define the complement of G = (V, E) as G c = (V, E c ), where E c = {(u,v): u V, v V, (u,v) E} Thus (u,v) E c iff (u,v) E G G c
VERTEX-COVER is NP-Complete Poly-time Reduction from CLIQUE to VERTEX-COVER: G, k G c, n k, where n = V Claim G, k CLIQUE iff G c, n k VERTEX-COVER. That is, G has a clique of size k iff G c has a vertex cover of size n k. Proof: Suffices to show that C is a clique in G iff V C is a vertex cover in G c.
VERTEX-COVER is NP-Complete Claim 1 C is a clique in G V C is a vertex cover in G c. Let C be a clique in G. Suppose an edge (u,v) E c not covered by V C. Then both u,v C, and (u,v) E. But C is a clique, so (u,v) E, contradiction. Claim 2 V C is a vertex cover in G c C is a clique in G. Suppose V C is a vertex cover in G c. Then (u,v) E c, either u C or v C. Thus u,v C, (u,v) E c, so (u,v) E.
SUBSET-SUM Instance: A multi-set of numbers denoted S and a target number t. Problem: To decide if there exists a subset Y S, s.t Σ y Y y=t.
On input S,t: Guess Y S SUBSET-SUM is in NP Accept iff Σ y Y y=t. The length of the certificate: O(n) (n= S ) Time complexity: O(n)
SUBSET-SUM is NP-Complete Proof: We ll show 3SAT p SUBSET-SUM. (......)... (......) p
Satisfying Clauses digit per clause c 1 c 2 c k number per variable x i assigned true: y i number per variable x i assigned false: z i 1 if x i is in c j 1 if x i is in c j otherwise otherwise
F = (x 1 x2 x3) ( x1 x2 x3) ( x1 x2 x3) (x1 x2 x3) x1 = x 1 x2 x3 C1 C2 C3 C4 x2 = x3 = 1 variables Slack variables v 1 = 1 1 1 v 1 = 1 1 1 v 2 = 1 1 v 2 = 1 1 1 1 v 3 = 1 1 1 v 3 = 1 1 1 s 1 = 1 s 1 = 1 s 2 = 1 s 2 = 1 s 3 = 1 s 3 = 1 s 4 = 1 s 4 = 1 t = 1 1 1 3 3 3 3
Achieving Target digit per clause c 1 c 2 c k <d<4 target:
Achieving Target digit per clause c 1 c 2 c k 1 1 target: 3
Achieving Target Alas, a subset may contain both y i and z i y 1 z 1 y l z l c 1 c 2 c k 1... 1 1 1 1 1... 1 3 3 3
Imposing Assignment Consistency y 1 z 1 y l z l 1 1 1 c 1 c 2 c k 1 1... 1 1 1 1 1 1 1... 1 1 3 3 3
Succinctness l k 2l 2k
Completeness If there is a satisfying assignment, a subset hitting the target is as follows: If the i-th variable is assigned TRUE, take y i, else take z i. Add as many auxiliary numbers as needed. satisfiability 3 in the rightmost k digits 1 in the leftmost l digits
Soundness If there is a subset that sums up to the target, construct an assignment as follows: If y i is in the subset, assign TRUE to the i-th variable. If z i is in the subset, assign FALSE to the i-th variable.
Observation: No Carry All digits are either or 1. Each column contains at most five 1 s. c 1 c 2 c k 1 y 1 Hence, a carry into the 1 1 1 next column never 1 occurs. 1 1 1 1 1 1 z 1 y l z l 1 1 1 1 1 3 3 3
Consistency Thus, to get 1 in the leftmost l digits, our subset necessarily contains either y i or z i (Not both!). 1 1 1 1 c 1 c 2 c k 1 y 1 1 1 1 1 1 z 1 y l z l 1 1 1 1 1 1 3 3 3
Satisfiablity In each column, at most 2 can come from the auxiliary numbers, so all clauses are satisfied. 1 1 1 1 c 1 c 2 c k 1 y 1 1 1 1 1 1 1 z 1 y l z l 1 1 1 1 1 3 3 3
Summing Up 1. SUBSET-SUM is in NP 2. 3SAT p SUBSET-SUM 3. Thus SUBSET-SUM is NP-Complete
Summary In this lecture we ve added many new problems to our NPC bank. Interestingly, NPC contains over 1 different problems!
Appendix 52
Dictionary literal: (negated or not) Boolean variable Examples: x, x clause: several literals connected with Example: (x y z) CNF (Conjunctive Normal Form): several clauses connected with Example: (x y) (x y z) negation: not ( ) conjunction: and ( ) disjunction: or ( ) 3CNF: a CNF formula with three literals in each clause. Example: (x y z) (x y z)
Catalogue of 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
Catalogue of NP-Complete Problems /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 Salesperson 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.