Presentation is loading. Please wait.

Presentation is loading. Please wait.

NP-Complete Proof of correctness; More reductions.

Similar presentations


Presentation on theme: "NP-Complete Proof of correctness; More reductions."— Presentation transcript:

1 NP-Complete Proof of correctness; More reductions

2 Definitions P: problems that can be solved in polynomial time (typically in n, size of input) on a deterministic Turing machine Any normal computer simulates a DTM Any normal computer simulates a DTM NP: problems that can be solved in polynomial time on a non-deterministic Turing machine Informally, if we could “guess” the solution, we can verify the solution in P time (on a DTM) Informally, if we could “guess” the solution, we can verify the solution in P time (on a DTM) NP does NOT stand for non-polynomial, since there are problems harder than NP NP does NOT stand for non-polynomial, since there are problems harder than NP P is actually a subset of NP (we think) P is actually a subset of NP (we think)

3 Definitions, continued NP-hard At least as hard as any known NP problem (could be harder!) At least as hard as any known NP problem (could be harder!) Set of interrelated problems that can be solved by reducing to another known problem Set of interrelated problems that can be solved by reducing to another known problemNP-Complete A problem that is in NP and NP-hard A problem that is in NP and NP-hard Cook’s Theorem SATISFIABILITY (SAT) is NP-Complete SATISFIABILITY (SAT) is NP-Complete Other NP-Complete problems Reduce to SAT or previous reduced problem Reduce to SAT or previous reduced problem

4 Complexity Classes at-a-glance Image taken from Jeff Erickson's lecture notes, notes/21-nphard.pdf notes/21-nphard.pdf notes/21-nphard.pdf We will not discuss co-NP today

5 Correctness To prove unknown problem y is NP- Complete: Prove y is in NP Prove y is in NP Prove y is at least as hard as some x in NP- Complete Prove y is at least as hard as some x in NP- Complete Transform x into y in polynomial time such that x is “yes” if and only if y is “yes” Requires two proofs, one for each direction: x yes  y yes, y yes  x yes (or x no  y no) Requires two proofs, one for each direction: x yes  y yes, y yes  x yes (or x no  y no) Must also prove transformation is polynomial Must also prove transformation is polynomial

6 Example: Independent Set Decision Problem: is there a set of k vertices such that none are adjacent? Proof of NP-Completeness: Is this in NP? Is this in NP? Easy to check in k^2 (Adj. Matrix) or km (Adj. List) Is this in NP-hard? Is this in NP-hard? Reduce known problem to unknown problem NOT the other way! We will use 3-SAT

7 Reductions Always solve a known problem by transforming it into an instance of the unknown problem Ex: 3SAT is NP-Complete. Independent Set is unknown. By transforming 3SAT into ISET and solving, we prove ISET is NP- Complete Ex: 3SAT is NP-Complete. Independent Set is unknown. By transforming 3SAT into ISET and solving, we prove ISET is NP- Complete If you go the other way, you might just make a bad transformation: “Sorting” is an unknown. Transform sorting into 3SAT (somehow) and solve. This does NOT mean sorting is NP- Complete! “Sorting” is an unknown. Transform sorting into 3SAT (somehow) and solve. This does NOT mean sorting is NP- Complete! Think of it this way: “If I can solve x by transforming x into y, then y is at least as hard as x.” (Corollary: if y can be solved quickly, so can x.)

8 3-SAT ≤ p ISET  v 1  v 3 v2 v2  v 2  v 4 v1 v1  v 4 v 5 v2v2 v 4 v 5 v3 v3 C ={  v 1, v 2,  v 3 }, {v 1,  v 2,  v 4 }, {  v 2,  v 4, v 5 }, {v 3, v 4, v 5 } For more details, review Lecture 18. This is a slightly modified version that does not use the “Literal widgets” but just connects each node directly to any node that is its complement.

9 3-SAT to ISET, continued The size of the transformation on the last slide is polynomial in the number of clauses (m) + number of literals (n) Adding opposing literals edges in the worst-case (full exploration of graph for each vertex) is still polynomial in m², so the time of the transformation is also polynomial Now we must prove 3SAT “yes”  ISET “yes” 3SAT  ISET Set target size for ISET = m Set target size for ISET = m Identify only one “true” literal in each clause of 3SAT, select that vertex in that “triangle” in ISET. Our set has no edges between nodes in the same triangle. Identify only one “true” literal in each clause of 3SAT, select that vertex in that “triangle” in ISET. Our set has no edges between nodes in the same triangle. Because this is a legal TA for 3SAT, we can’t select a complementary version of a previously selected literal, so no edges will connect nodes in different triangles. Because this is a legal TA for 3SAT, we can’t select a complementary version of a previously selected literal, so no edges will connect nodes in different triangles.

10 Visual demonstration of 3SAT  ISET C = {  v1, v2,  v3}, {v1,  v2,  v4}, {  v2,  v4, v5}, {v3, v4, v5} Select nodes corresponding to literals in violet. These form an independent set of size m.  v 1  v 3 v2 v2  v 2  v 4 v1 v1  v 4 v 5 v2v2 v 4 v 5 v3 v3

11 3SAT  ISET So we have an ISET of size m, how does this give us a valid TA for 3SAT? At most one node comes from each triangle At most one node comes from each triangle There are m triangles, so there must be one node in every triangle  m clauses covered There are m triangles, so there must be one node in every triangle  m clauses covered Because of the opposing literals edges, no conflicting truth assignments can be in ISET Because of the opposing literals edges, no conflicting truth assignments can be in ISET Assign the literals in the ISET to true; other literals don’t matter Assign the literals in the ISET to true; other literals don’t matter

12 Hamiltonian Path & H. Cycle In Lecture 18, a (complex) proof was given that HAMCYCLE (aka TSP) was NP-Complete How can we show that HAMPATH is also NP- Complete? Take graph G and modify to G' Take graph G and modify to G' Show transformation is polynomial Show that G' has HAMPATH if G has HAMCYCLE Show that G' has HAMPATH if G has HAMCYCLE Show that G has HAMCYCLE if G' has HAMPATH Show that G has HAMCYCLE if G' has HAMPATH

13 HAMPATH/HAMCYCLE, cont'd Run HAMPATH on G' If G had a HAMCYCLE, G' has a path through all the vertices except V1' and V2' starting at V1 and ending at V2 that corresponds to the cycle. Add V1' to the start of the path, V2' to the end, and it's a HAMPATH. If G' has a HAMPATH, it must start/end at V1'/V2' since they have degree 1, so G has a HAMCYCLE starting from V G V Split any vertex V into two identical vertices V1 and V2 (do not create E(V1,V2)). G' V1 V2 V1' V2' Then create V1' and V2' adjacent only to V1 and V2, respectively. (The transformation is trivially polynomial.)

14 Hitting Set Problem, given a set T of sets s 1, s 2 … s n, is there a set H of at most k elements such that H contains at least one element from every s 1 …s n ? Example: T = {{1,2,3},{a,1},{a,b,c},{  }} k=2, no valid H! k=2, no valid H! k=3, H = {1,a,  } (other choices exist) k=3, H = {1,a,  } (other choices exist) How hard is this problem?

15 Hitting Set Complexity Easy to show problem is in NP: would take at most nk time to verify a given solution H Is this NP-Complete? Think about other problems you know are NP- Complete: SAT (and cousins), Independent Set, HP/HC, Vertex Cover (worksheet), Maximum Clique (worksheet) Think about other problems you know are NP- Complete: SAT (and cousins), Independent Set, HP/HC, Vertex Cover (worksheet), Maximum Clique (worksheet) Look for a similar problem: something that involves selecting one item to represent some collection of items Look for a similar problem: something that involves selecting one item to represent some collection of items Work in groups to find a reduction and argue that it is correct

16 Vertex Cover ≤ p Hitting Set Both involve "select some items such that all items are represent" Construct: Given a graph G, for each edge e = (u,v) create a set s = {u,v} and add s to the universe T. Now prove G has a vertex cover of size k  T has a hitting set of size k Select k vertices to represent m edges vs. select k elements to represent m sets Select k vertices to represent m edges vs. select k elements to represent m sets

17 Vertex Cover  Hitting Set Vertex Cover  Hitting Set Suppose C is a cover of G of size k Suppose C is a cover of G of size k By definition then, for every edge (u,v) in G, either u  C or v  C Then H can be set to C, and H must intersect every set in T. Vertex Cover  Hitting Set Suppose H is a hitting set of T of size k Suppose H is a hitting set of T of size k Since H intersects every set, it has at least one endpoint of every edge. Set C to be H.

18 Set Cover Problem, given a set T of sets s 1, s 2 … s n, is there a set S' of at most k sets such that S' contains every element in T? Example: T = {{1,2,3},{a,1},{a,b,c},{  }} k = 2, no legal S'! k = 2, no legal S'! k = 3, S' = {{1,2,3},{a,b,c},{  }} k = 3, S' = {{1,2,3},{a,b,c},{  }} This should look very familiar! Work in groups to find a reduction and argue that it is correct

19 Vertex Cover ≤ p Set Cover Given a graph G, construct a universe of sets T: For each vertex V, create a set s v with all the edges incident on V For each vertex V, create a set s v with all the edges incident on V Our “universe” is now the set of all edges in G (each is listed twice) Our “universe” is now the set of all edges in G (each is listed twice) B C A E F D T = {{ab,ac,ae},{ba,bc,bd},{ca,cb}, {db,de,df},{ea,ed,ef},{fd,fe}}

20 Vertex Cover  Set Cover Vertex Cover  Set Cover Suppose C is a cover of G of size k To find S', select sets s w for every w  C. If there was an edge e=(u,v) in T not in S', then neither s u nor s v was selected, so neither u nor v was in the Vertex Cover, a contradiction. Vertex Cover  Set Cover Suppose S' is a set cover of T of size k To find C, select vertex v for every s v  S' If there is an edge e=(u,v) in G not in C, then neither vertex u nor v was selected, so neither s u nor s v was in S'. Since {uv} can only be found in s u and s v this contradicts that S' is a cover.

21 License This lecture is released under the Creative Commons License,


Download ppt "NP-Complete Proof of correctness; More reductions."

Similar presentations


Ads by Google