CS 301 - Lecture 29 P, NP, and NP-Completeness Fall 2008 Review Languages and Grammars Alphabets, strings, languages Regular Languages Deterministic Finite and Nondeterministic Automata Equivalence of NFA and DFA Regular Expressions and Regular Grammars Properties of Regular Languages Languages that are not regular and the pumping lemma Context Free Languages Context Free Grammars Derivations: leftmost, rightmost and derivation trees Parsing, Ambiguity, Simplifications and Normal Forms Nondeterministic Pushdown Automata Pushdown Automata and Context Free Grammars Deterministic Pushdown Automata Pumping Lemma for context free grammars Properties of Context Free Grammars Turing Machines Definition, Accepting Languages, and Computing Functions Combining Turing Machines and Turing s Thesis Turing Machine Variations, Universal Turing Machine, and Linear Bounded Automata Recursive and Recursively Enumerable Languages, Unrestricted Grammars Context Sensitive Grammars and the Chomsky Hierarchy Computational Limits and Complexity Computability and Decidability Complexity The class P P = DTIME( n k ) for all k Polynomial time Type of deterministic machine no longer matters Adding more tapes changes k for a particular problem, but still polynomial All tractable problems The class NP NP = NTIME( n k ) for all k Non-Deterministic Polynomial time 1
Observation: Open Problem: P = NP? P NP Deterministic Polynomial Non-Deterministic Polynomial WE DO NOT KNOW THE ANSWER Why Does P = NP Matter? From Garey and Johnson Computers and Intractability Function 10 20 30 40 50 60 Our Three Classic Problems: Satisfiability Hamiltonian Path N 0.0001 s 0.0002 s 0.0003 s 0.0004 s 0.0005 s 0.0006 s N^2 0.0001 s 0.0004 s 0.0009 s 0.0016 s 0.0025 s 0.0036 s N^5 0.1 s 3.2 s 24.3 s 1.7 min 5.2 min 13.0 min 2^N 0.001 s 1 s 17.9 min 12.7 days 3^N 0.059 s 58 min 6.5 years 3855 centuries 35.7 years 2 X 10^8 centuries Common Run Times for Representative Algorithms 366 centuries 10^13 centuries Clique All can be solved in polynomial time using non-deterministic Turing machines. Could they be solved in polynomial time using deterministic Turing machines? 2
Polynomial Time Reductions Polynomial Computable function f : w For any computes in polynomial time f (w) Language A is polynomial time reducible to language B if there is a polynomial computable function such that: f w A f ( w) B Theorem: Suppose that is polynomial reducible to. If then. B P A A P B Theorem: 3SAT is polynomial time reducible to CLIQUE Proof: Let M be the machine to accept B Machine to accept w A in polynomial time: On input : 1. Compute f (w) 2. Run on input f (w) M Proof: give a polynomial time reduction of one problem to the other 3
Clique: 3CNF formula: A 5-clique ( x1 x2 x3) ( x3 x5 x6) ( x3 x6 x4) ( x4 x5 x6) Each clause has three literals CLIQUE = { < G, k > : Given a graph does G contains a -clique} k Again, no obvious deterministic polynomial time algorithm.. G Language: 3SAT ={ w : w is a satisfiable 3CNF formula} ( x1 x1 x2) ( x1 x2 x2) ( x1 x2 x3) x1 x x 2 2 x = 1 x 1 2 = 0 x = 1 3 ( x1 x1 x2) ( x1 x2 x2) ( x1 x2 x3) x1 x x 2 2 x 2 x 2 x 2 x 3 x 2 x 3 4
Theorem: Vertex Cover is polynomial time reducible to CLIQUE Clique: A 5-clique Proof: give a polynomial time reduction of one problem to the other CLIQUE = { < G, k > : Given a graph does G contains a -clique} k Again, no obvious deterministic polynomial time algorithm.. G Reduction: Given a Graph G, define its complement Gc All vertices in G are vertices in Gc. An edge (u,v) is in Gc if and only if (u,v) is not an edge in G. 1) Convert G into Gc an easy step. 2) Ask whether Gc has a clique of size K? Cliques and Covers: Let V1 = the Clique found in Gc. Claim (V V1) is a cover in G. Pick an arbitrary edge (u,v) in G. Suppose neither u or v is in (V-V1). Both u and v are V1 Both u and v are in a clique in Gc there must be an edge (u,v) in Gc there must not be an edge (u,v) in G But (u,v) was an edge in G! 5
NP-Completeness A problem is NP-complete if: Theorem: (ANY PROBLEM IN NP) is polynomial time reducible to CLIQUE It is in NP Every NP problem is reduced to it (in polynomial time) Clique is an NP-complete problem. Solve Clique in polynomial time and you solve all NP problems in polynomial time. Observation: If we can solve any NP-complete problem in Deterministic Polynomial Time (P time) then we know: P = NP Observation: If we prove that we cannot solve an NP-complete problem in Deterministic Polynomial Time (P time) then we know: P NP 6
Cook s Theorem: The satisfiability problem is NP-complete Observations: It is unlikely(??) that NP-complete problems are in P Sketch of Proof: Convert a Non-Deterministic Turing Machine to a Boolean expression in conjunctive normal form The NP-complete problems have exponential time algorithms Approximations of these problems are in P Other NP-Complete Problems: The Traveling Salesperson Problem Vertex cover Hamiltonian Path Vertex Cover = { < G, k > : Given a graph G does G contains a size cover? } k A cover is a set of vertices in G such that for every edge (u,v) in G, at least one of u and v belongs to G. All the above are reduced to the satisfiability problem 7
Where to Go From Here? The View We Have From CS 301 NP Where to Go From Here? NP Hard: drop requirement problem is in NP, but still as hard as an NP-complete problem. RP: Randomized Computations PSPACE: Polynomial Space Incorporating distributed computations. P See Papadimitriou, Computational Complexity We have established a starting point for a very rich analysis of complexity in both time and space. Where to Go From Here? A larger view of complexity theory Read What s Next Linz Chapter 1,2.1, 2.2, 2.3, (skip 2.4), 3, 4, 5, 6.1, 6.2, (skip 6.3), 7.1, 7.2, 7.3, (skip 7.4), 8, 9, 10, 11, 12.1, 12.2, (skip 12.3, 12.4, 12.5, 13), 14.1, 14.2, and 14.3 JFLAP Chapter 1, 2.1, (skip 2.2), 3, 4, 5, 6, 7, (skip 8), 9, (skip 10), 11 Next Lecture Topics Review for Final Exam Final exam Friday 12/19 Closed book, but you may bring one sheet of 8.5 1 inch paper with any notes you like. Homework Homework 15 (repeat of previous homework problems) Due Today Homework 16 = study for the final!! 8