180 likes | 341 Views
Theory of Computing. Lecture 18 MAS 714 Hartmut Klauck. Before. We have shown NP-completeness of 3-SAT: a k-CNF is a CNF in which all clauses have 3 literals (or less) k-SAT={set of all k-CNF that are satisfiable } Notes: Not hard to give a reduction from CNF-SAT to 3-SAT
E N D
Theory of Computing Lecture 18 MAS 714 Hartmut Klauck
Before • We have shown NP-completeness of 3-SAT: • a k-CNF is a CNF in which all clauses have 3 literals (or less) • k-SAT={set of all k-CNF that are satisfiable} • Notes: Not hard to give a reduction from CNF-SAT to 3-SAT • 2-SAT is in P (and hence not NP-complete unless P=NP) • 3-SAT is the basis of our reductions from now on
Reductions • We will show some reductions from 3-SAT to a few problems • Due to transitivity we can use reductions from any of the problems for which we already have a reduction from 3-SAT • Often this is easier
Vertex Cover • For an undirected Graph G a vertex cover is a subset S of the vertices such that every edge has at least one endpoint in S • VC={G,ksuch that G has a vertex cover of size at most k} • Theorem: VC is NP-complete • Part 1: VC in NP is easy (guess S and check all edges)
Reduction VC • Part 2: we reduce from 3-SAT • Let F be a formula with variables x1,…,xn and 3-clauses z1,…,zm • For each xi we use two vertices vi and wi connected by an edge (variable gadget) • For each zi we use three verticesai, bi, ci connected to form a triangle (clause gadget)
Reduction VC • vi corresponds to the literal xi • wi to the literal :xi • We connect ai, bi, ci with the corresponding literal from clause zi • We set k to n+2m • Observation: For any vertex cover S one of vi and wi needs to be in S, and at least 2 of ai, bi, ci • 1) Assume x satisfies F. We show that a small S exists. • If xi=0 we choose wi else vi for S • For each clause gadget at least one of ai, bi, ci is connected to a vertex in S. Choose other 2 vertices per clause gadget to form a VC of size n+2m
Reduction VC • 2) Now assume there is a VC S of size at most k=n+2m • S must contain either vi or wi • S must contain two vertices for each clause gadget (triangle) • Hence it cannot contain vi and wi • Set x accordingly (xi=1iffvi2 S) • Claim: this is a satisfying assignment • Proof: every clause gadget must have one vertex not in S, connected to a literal node in S • Hence x satisfies F
Clique • We want to show that MaxClique is NP-complete • Surely it is in NP • Reduction from VC • Observation/reduction: • (G,k)2 VC iff (Gc,n-k)2 Max Clique • Gc: complement of G
Observation • If S is a vertex cover in G then all edges in G have one endpoint in S, there are no edges going from V-S to V-S • Hence in the complement of G, V-S is a clique • Gc,n-k in MaxClique • Note: we have shown that VC has a 2-approximation algorithm • Max Clique does not have a n1-² approximation unless P=NP • Notice how a VC of size · 2k implies only a Clique of size ¸ n-2k, which can be much smaller than n-k, e.g., k=n/2
SetCover • Input: set of m subsets s1,…,sn of S, |S|=m • Task: find the smallest set of si such thatS= [i2IsiWe want |I| minimal • SetCover:{s1,…,sn,k: there is Iµ {1,…,n}, |I|=k, [i2Isi= [i=1…nsi} • Theorem: SetCover is NP-complete • Part 1: 2 NP: guess I
SetCover • Part 2: Reduction from VC • G,k is mapped to a SetCover instance as follows: G=(V,E) • Universe: E • Subsets: s1,…,sn • si: {edges adjacent to vertex i} • k unchanged • Then: (G,k)2 VC iff (s1,…,sn,k) 2SetCover
Hamiltonian Cycle • A Hamiltonian cycle in a directed G=(V,E) is a cycle that visits each vertex once • HC={G: G has a Hamiltonian cycle} • Theorem: HC is NP-complete • In NP: guess the cycle • Hardness: reduction from VC
HC • G=(V,E) and k given (input to VC) • Assume edges in E are ordered (e1,…,em) • New vertices: a1,…,akand vertices (u,e,b) where u2 V, e2 E is incident to u and b2{0,1} • Edges: (u,e,0) to (u,e,1) type 1(u,e,b) to (v,e,b) where e={u,v} type 2(u,e,1) to (u,e’,0) where e,e’ inc. to u and there is no e’’ with e<e’’<e’ inc. to u type 3(u,e,1) to all ai where e is max. edge at u type 4all ai to (u,e,0) where e is the min. edge at u type 5
HC • Take vertex cover S of size k • Find the cycle: for v2 S consider all the vertices (v,e,b) and all (u,e,b) where e={u,v} • We traverse these from (v,e,0) in ascending order of e • (v,e,0) to (v’,e,0) to (v’,e,1) to (v,e,1) to (v,e’,0) etc. until (v,e,1) for max e at v reached. Then to a1 and to the next (u,e,0) with u the next vertex in S and e min. at u • A Hamitonian cycle exists • Assume a Hamiltonian cycle ex. It must traverse all ai. Group all vertices visited between ai and ai+1 • Claim: vertex cover of size k exists
Traveling Salesman • Input: matrix of distances (edge weights),k • Output: is there a Hamiltonian cycle of total edge weight at most k? • Reduction from HC: • Use adjacency matrix as weights, k=n
Subgraph Isomorphism • Given G,H, is H isomorphic to a subgraph of G? • subgraph: subset of vertices and edges • isomorphic: same up to renaming vertices • Theorem: Subgraph isomorphism is NP-complete • Reduction from Clique: Map G,k to G and H, where H is a k-clique (undirected case) • Reduction from HC: Map G to G and H, where H is an n-cycle (directed case)
Note • Graph Isomorphism (are G,H isomorphic?)is not known to be in P or NPC
Subset Sum • Input: set S of integers, target t • Is there a subset S’µ S such that the elements in S’ sum to t? • Theorem: Subset Sum is NP-complete • Reduction from 3-SAT