1 / 44

חישוביות וסיבוכיות Computability and Complexity Lecture 8

חישוביות וסיבוכיות Computability and Complexity Lecture 8. TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.: A A A A A. Outline. Last week: Non-deterministic TM Poly-time verifiability The classes NP and coNP Today: Poly-time reducibility

rane
Download Presentation

חישוביות וסיבוכיות Computability and Complexity Lecture 8

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. חישוביות וסיבוכיות Computability and Complexity Lecture 8 TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.: AAAAA

  2. Outline Last week: • Non-deterministic TM • Poly-time verifiability • The classes NP and coNP Today: • Poly-time reducibility • NP completeness • Existence of NP-complete problems

  3. P, NP and coNP • P = class of languages where membership can be decided in polynomial time. • NP = class of languages where membership can be verified in polynomial time. • coNP = class of languages whose complement is in NP.

  4. Poly-time Verifiability Definition:A verifier for a language A is an algorithm V, where A = {w |  string c s.t. V accepts <w,c> } • V’s running time is measured in terms of |w| • A is polynomially verifiable if it has a poly-time V

  5. Two Definitions of NP Definition 1: NP is the class of languages that have a polynomial time verifier. Definition 2: NP is the class of languages that are decidable by a non-deterministic poly-time TM. Theorem: Definition 1 is equivalent to Definition 2.

  6. Example: A problem in NP A path in a directed graph G that goes through each node of G exactly once. HAMPATH={<G,s,t>|G is a directed graph with a Hamiltonian path from stot} e t b a d s c

  7. Example: A Problem in NP II • A clique in an undirected graph is a subgraph for which every two nodes are connected. CLIQUE={<G,k>|G is undirected graph with a k-clique} 2-clique 4-clique

  8. P = NP ? ? NP NP=P P

  9. NP vs. coNP ? NP coNP P

  10. NP-Completeness Cook-Levin (early 70’s): Certain problems in NP are at least as hard as any problem in NP. Such problems are called NP-complete. Many important problems are NP-complete (e.g. HAMPATH, CLIQUE, SAT, SUBSETSUM). Most problems in NP: either in P or NP-complete (however some are not known to be neither).

  11. NPC Theoretical Importance To answer the P vs. NP problem: • Focus on an NP complete problem: • To show P ≠ NP, prove it requires more than poly time. • To show P = NP, find a poly-time algorithm for it. NPC NP NP=P P P

  12. I can’t You’re fired Solve it in poly- time Solve it in poly- time I. No one knows to do it. It is NP-hard! II. Practical Importance

  13. First Example: SAT Boolean variables: {0,1} Boolean operations: {, , } 0 0 = 0 0 0 = 0  0 = 1 0 1 = 0 1 0 = 1  1 = 0 1 0 = 0 0 1 = 1 1 1 = 1 1 1 = 1 Boolean formula:  = (x  y)  (x  z) The satisfiability (SAT) problem: Given a Boolean expression on n variables, can we assign values such that the expression is TRUE?

  14. The Cook-Levin Theorem SAT={<>|  is a satisfiable Boolean formula} Claim: SAT ∈ NP Cook-Levin theorem: SAT ∈ P if and only if P = NP

  15. Polynomial-Time Reducibility Definition:A language A is polynomial time mapping reducible to a language B, A pB, if there exists a polynomial-time computable function f: S* S*where for every w,  A  f() B f w A B f(w) f

  16. f Theorem:IfAPBandBP, thenAP. A polynomial algorithm to decide A: • Given w, Compute f(w)in polynomial time • Decide whether f(w) Bin polynomial time w A B f(w)  A  f() B

  17. f w A B f(w) Corollary: IfAPBandAPthenBP.  A  f() B

  18. 3SAT SAT={<>|  is a satisfiable Boolean formula} A Boolean formula is in conjunctive normal form (CNF) if it is an AND of clauses, each of which is an OR of literals • Example: (x1  x2)  (x1  x3  x4)  (x5) 3CNF: each clause has exactly 3 distinct literals • Example: (x1  x2  x3)  (x1  x2  x3)  (x1  x3  x4) 3SAT={<>|  is a satisfiable 3CNF formula}

  19. 3SAT PCLIQUE Theorem: 3SAT is poly-time reducible to CLIQUE. Proof: Given a 3CNF formula F, build a graph G and specify a number k such that a clique of size k exists in G iff the formula F is satisfiable.

  20. 3SAT PCLIQUE The reduction: • Let F = C1  C2  …  Ck be a 3-CNF formula with k clauses, each of which has 3 distinct literals. • For each clause, Ci, put three vertices in the graph, one for each literal. • Put an edge between two vertices if they are in different triples and their literals are consistent, meaning not each other’s negation. In other words: There are edges between all nodes of G except for nodes in the same triplet and nodes with contradictory labels.

  21. Construction by Example literal clause -x y z -x x G -y y z -z An edge means ‘these two literals do not contradict each other’.

  22. Construction by Example -x y z -x x G -y y z -z Any clique of size k must include exactly one literal from each clause.

  23. General Construction where literals where E = {(aij, ai’,j’): ii’ and aij  ai’j’}

  24. The Reduction Argument We need to show: • F satisfiable implies G has a clique of size k. Given a satisfying assignment for F, for each clause pick a literal that is satisfied. Those literals in the graph G form a k-clique. • G has a clique of size k implies F is satisfiable. Given a k-clique in G, assign TRUE to each literal in the clique. This yields a satisfying assignment to F (why?).

  25. Example: Clique to Assignment -x y z -x x G -y y z -z y=0, z=1, x can take either values

  26. NP-Completeness Definition: A Language B is NP-completeif it satisfies two conditions: • Bis in NP, and • Every A NP is poly-time reducible to B. Definition: A Language B is NP-hard if it satisfies the following condition: • Every A NP is poly-time reducible to B.

  27. NP-completeness vs NP-hardness NP-hard NP-complete NP P

  28. Two Theorems on NP-Completeness Theorem 1: If B is NP-complete and BP then P=NP. Theorem 2: If B is NP-complete and B PC for some C  NP, then C is NP-complete.

  29. Do NP-Complete Languages Exist? Yes: BOUNDED HALTING (BH) BH = {<M,x> | M is a TM and ∃c so that M(x,c) accepts in less than poly(|x|) steps} Claim: BH is NP-complete. Proof: First, note that BH  NP (why?). LetA NP. We will show that A PBH.

  30. A PBH SinceA NP, then it is verifiable in polynomial time. That is, there exists a poly-time TM V for which wA iff ∃c s.t. V(w,c)= ACCEPT Given w, the reduction f(w) generates the pair <V,w> as an instance for BH. Need to show that <V,w> BHif and only ifwA.

  31. Correctness of Reduction <V,w> BH ⇕ ∃c s.t. V(w,c) = ACCEPT ⇕ wA Conclusion: There exists an NP-complete language.

  32. Cook-Levin Theorem Shows a “natural” NP-complete language. Cook-Levin Theorem:SAT is NP-Complete. Proof: We have to show: • SAT  NP • For every A  NP, A PSAT The proof will be given next lecture.

  33. Let’s See if we Understand… Cook-Levin Theorem:SAT is NP-Complete. Previous version: SAT ∈ P if and only if P = NP We saw before: 3SAT PCLIQUE You will see in tirgul: SAT P 3SAT Question: What can we say about CLIQUE?

  34. Showing that other languages are NP-complete To show that B is NP-complete it is sufficient to show that: 1. B is in NP, and 2. Every A  NP, APB or 2’. CPB, where C NP-complete.

  35. Summary So Far • P = problems that can be solved in poly-time • NP = problems for which a solution can be verified in poly-time • Unknown whether P = NP (most conjecture not) • SAT is in NP: • Probably cannot be solved in polynomial time. • Easy to verify solution in polynomial time.

  36. NP-Complete Problems are the “Hardest” Problems in NP • If any one NP-Complete problem can be solved in polynomial time… • …then everyNP-Complete problem can be solved in polynomial time… • …and in fact everyproblem in NP can be solved in polynomial time (which would prove that P = NP) • Solve SAT in O(n100) time, you’ve proved that P = NP. Retire rich & famous.

  37. Why Prove NP-completeness? • Though nobody has proven that P ≠ NP, if you prove a problem is NP-Complete, most people accept that it is probably intractable. • Therefore it can be important to prove that a problem is NP-Complete • Don’t try to come up with efficient algorithm. • Instead: • Try to solve a subproblem • Work on approximation algorithms.

  38. Using Reductions Given one NP-Complete problem, can prove that many interesting problems are NP-Complete. For example: • Graph problems (Clique, Vertex Cover, coloring) • Hamiltonian path/cycle • Knapsack problem • Traveling salesman • Job scheduling • Many, many, many more…

  39. Example: The Vertex Cover Problem A vertex cover for a graph G is a set of vertices incident to every edge in G VERTEX-COVER={<G,k>| G is an undirected graph that has a k-node vertex cover} Theorem: vertex cover is NP-Complete

  40. Vertex Cover (Example) A vertex cover of size 5 A vertex cover of size 4

  41. VERTEX-COVER is in NP Proof:The following V is a polynomial verifier for VERTEX-COVER. V=“On input <<G,k>,c>: 1. Test whether c is a collection of nodes in G. 2. Test whether c has k different nodes. 3. Test whether all edges in G touches the nodes in c. 4. If 1-3 pass, accept; Otherwise, reject.

  42. G Gc Clique P Vertex Cover Reduce k-clique to vertex cover: • The complement GC of a graph G contains exactly those edges not in G • Compute GC in polynomial time • Claim: G has a clique of size kiffGC has a vertex cover of size |V| - k

  43. G Gc Clique P Vertex Cover (cont’) Claim 1: If G has a clique of size k, then GC has a vertex cover of size |V| - k Claim 2: If GChas a vertex cover H  V, with |H| = |V| - k, then G has a clique of size k Proofs: In class

More Related