450 likes | 586 Views
חישוביות וסיבוכיות 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
E N D
חישוביות וסיבוכיות Computability and Complexity Lecture 8 TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.: AAAAA
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
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.
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
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.
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
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
P = NP ? ? NP NP=P P
NP vs. coNP ? NP coNP P
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).
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
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
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?
The Cook-Levin Theorem SAT={<>| is a satisfiable Boolean formula} Claim: SAT ∈ NP Cook-Levin theorem: SAT ∈ P if and only if P = NP
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
f Theorem:IfAPBandBP, thenAP. 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
f w A B f(w) Corollary: IfAPBandAPthenBP. A f() B
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}
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.
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.
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’.
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.
General Construction where literals where E = {(aij, ai’,j’): ii’ and aij ai’j’}
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?).
Example: Clique to Assignment -x y z -x x G -y y z -z y=0, z=1, x can take either values
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.
NP-completeness vs NP-hardness NP-hard NP-complete NP P
Two Theorems on NP-Completeness Theorem 1: If B is NP-complete and BP then P=NP. Theorem 2: If B is NP-complete and B PC for some C NP, then C is NP-complete.
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.
A PBH SinceA NP, then it is verifiable in polynomial time. That is, there exists a poly-time TM V for which wA 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 ifwA.
Correctness of Reduction <V,w> BH ⇕ ∃c s.t. V(w,c) = ACCEPT ⇕ wA Conclusion: There exists an NP-complete language.
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.
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?
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, APB or 2’. CPB, where C NP-complete.
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.
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.
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.
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…
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
Vertex Cover (Example) A vertex cover of size 5 A vertex cover of size 4
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.
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
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