1 / 20

NP-Complete

NP-Complete. Proof of correctness; More reductions. 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

tacy
Download Presentation

NP-Complete

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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 • NP: problems that can be solved in polynomial time on a non-deterministicTuring machine • 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 • 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!) • Set of interrelated problems that can be solved by reducing to another known problem • NP-Complete • A problem that is in NP and NP-hard • Cook’s Theorem • SATISFIABILITY (SAT) is NP-Complete • Other NP-Complete problems • Reduce to SAT or previous reduced problem

  4. Complexity Classes at-a-glance • Image taken from Jeff Erickson's lecture notes, http://compgeom.cs.uiuc.edu/~jeffe/teaching/algorithms/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 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 ify is “yes” • 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

  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? • Easy to check in k^2 (Adj. Matrix) or km (Adj. List) • 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 • 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! • Think of it this way: “If I can solve x by transforming x into y, then y is at least as hard asx.” (Corollary: if y can be solved quickly, so can x.)

  8. 3-SAT ≤p ISET 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. C = {v1, v2, v3} , {v1, v2, v4} , {v2, v4, v5} , {v3, v4, v5} v2 v1 v2 v3 v1v3 v2v4 v4v5 v4v5

  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 • 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.

  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. v2 v1 v2 v3 v1v3 v2v4 v4v5 v4v5

  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 • 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 • 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' • Show transformation is polynomial • Show that G' has HAMPATH if G has HAMCYCLE • Show that G has HAMCYCLE if G' has HAMPATH

  13. HAMPATH/HAMCYCLE, cont'd G' V2' G V2 V Then create V1' and V2' adjacent only to V1 and V2, respectively. (The transformation is trivially polynomial.) V1 Split any vertex V into two identical vertices V1 and V2 (do not create E(V1,V2)). V1' • 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

  14. Hitting Set • Problem, given a set T of sets s1, s2 … sn, is there a set H of at most k elements such that H contains at least one element from every s1…sn? • Example: T = {{1,2,3},{a,1},{a,b,c},{}} • k=2, no valid H! • 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) • 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

  17. Vertex Cover  Hitting Set • Vertex Cover  Hitting Set • 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 • 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 s1, s2 … sn, 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 = 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 sv with all the edges incident on V • Our “universe” is now the set of all edges in G (each is listed twice) T = {{ab,ac,ae},{ba,bc,bd},{ca,cb},{db,de,df},{ea,ed,ef},{fd,fe}} A D BC EF

  20. Vertex Cover  Set Cover • Vertex Cover  Set Cover • Suppose C is a cover of G of size k • To find S', select sets sw for every w  C. • If there was an edge e=(u,v) in T not in S', then neither su nor sv 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 sv  S' • If there is an edge e=(u,v) in G not in C, then neither vertex u nor v was selected, so neither su nor sv was in S'. Since {uv} can only be found in su and sv this contradicts that S' is a cover.

More Related