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 CS 447, Algorithms
CS 447, Algorithms 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
CS 447, 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 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
CS 447, Algorithms 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. CS 447, Algorithms
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. CS 447, Algorithms
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 CS 447, Algorithms
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) CS 447, Algorithms
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 CS 447, Algorithms
CS 447, Algorithms 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. CS 447, Algorithms
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. CS 447, Algorithms
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 ) CS 447, Algorithms
CS 447, Algorithms CLIQUE is NP-Complete Proof: We ll show 3SAT p CLIQUE. (......)... (......) p
CS 447, Algorithms 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
CS 447, Algorithms The Reduction for any clause ( ) V = formula s length K= no. of clauses connected iff
CS 447, Algorithms 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.
CS 447, Algorithms 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
CS 447, Algorithms 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).
CS 447, Algorithms 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.
CS 447, Algorithms Another View: Proof of Correctness 1 NOT connected!... a clique of size k must contain one node from every layer. k
CS 447, Algorithms 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. CS 447, Algorithms
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 ) CS 447, Algorithms
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 CS 447, Algorithms there s an IS of size k in its complement
CS 447, Algorithms Formal Proof: Example Vertex Cover is NP-Complete
CS 447, Algorithms 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.
CS 447, Algorithms 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
CS 447, Algorithms 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.
CS 447, Algorithms 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. CS 447, Algorithms
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) CS 447, Algorithms
CS 447, Algorithms SUBSET-SUM is NP-Complete Proof: We ll show 3SAT p SUBSET-SUM. (......)... (......) p
CS 447, Algorithms 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
Slack variables variables 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 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 CS 447, Algorithms t = 1 1 1 3 3 3 3
CS 447, Algorithms Achieving Target digit per clause c 1 c 2 c k <d<4 target:
CS 447, Algorithms Achieving Target digit per clause c 1 c 2 c k 1 1 target: 3
CS 447, Algorithms 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
CS 447, Algorithms 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
CS 447, Algorithms 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. 1 in the leftmost l digits satisfiability 3 in the rightmost k digits CS 447, Algorithms
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. CS 447, Algorithms
CS 447, Algorithms Observation: No Carry All digits are either or 1. Each column contains at most five 1 s. Hence, a carry into the next column never occurs. 1 1 1 1 c 1 c 2 c k 1 1 1 1 1 1 1 y 1 z 1 y l z l 1 1 1 1 1 3 3 3
CS 447, Algorithms 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 1 1 1 1 1 y 1 z 1 y l z l 1 1 1 1 1 1 3 3 3
CS 447, Algorithms 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 1 1 1 1 1 1 y 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 CS 447, Algorithms
Summary In this lecture we ve added many new problems to our NPC bank. Interestingly, NPC contains over 1 different problems! CS 447, Algorithms
Appendix 52
CS 447, Algorithms 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) 3CNF: a CNF formula with three literals in each clause. Example: (x y z) (x y z) negation: not ( ) conjunction: and ( ) disjunction: or ( )
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 CS 447, Algorithms
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. CS 447, Algorithms