CS 301 - Lecture 28 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 Epressions and Regular Grammars Properties of Regular Languages Languages that are not regular and the pumping lemma Contet Free Languages Contet Free Grammars Derivations: leftmost, rightmost and derivation trees Parsing, Ambiguity, Simplifications and Normal Forms Nondeterministic Pushdown Automata Pushdown Automata and Contet Free Grammars Deterministic Pushdown Automata Pumping Lemma for contet free grammars Properties of Contet 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 Contet Sensitive Grammars and the Chomsky Hierarchy Computational Limits and Compleity Computability and Decidability Compleity
Selecting the Right Machine Model Computation Using Turing machine But the choice of machine seems to matter a great deal! Two tapes machines might take fewer steps than one tape machines Non-Deterministic machines might take fewer steps than Deterministic ones Is there a right choice to make?
Selecting the Right Machine If a two-tape machine takes steps, a one tape machine can simulate this in If a non-deterministic machine takes steps, a deterministic one can simulate this in So do we need classes for each machine type??
Theorem: DTIME( n k+ 1 k ) DTIME( n ) DTIME( k+1 n ) DTIME( n k )
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
P {ww} n n { a b }
Some Classic Problems in Computer Science Satisfiability Problem Hamiltonian Path Problem Clique Problem Are these problems in P??
Eample: The Satisfiability Problem Boolean epressions in Conjunctive Normal Form: t 1 t 2 t 3 t k ti = 1 2 3 p Variables Question: is epression satisfiable?
Eample: ( 1 2) ( 1 3 ) Satisfiable: =, 1, 1 1 0 2 = 3 = ( 3 1 2) ( 1 ) = 1
Eample: ( 1 2) 1 2 Not satisfiable
L = { w:epression w is satisfiable} For n variables: L DTIME( 2 n ) eponential Algorithm: search ehaustively all the possible binary values of the variables
Eample: the Hamiltonian Problem s t Question: is there a simple path that passes through all vertices?
s t YES!
A solution: search ehaustively all paths L = {<G,s,t>: there is a Hamiltonian path in G from s to t} L DTIME( n!) DTIME(2 n ) Eponential time Intractable problem
Clique: A 5-clique CLIQUE = { : Given a graph does G contains a -clique} < G, k > G k Again, no obvious deterministic polynomial time algorithm..
Non-Determinism Language class: NTIME(n) NTIME(n) L 1 L L 3 2 A Non-Deterministic Turing Machine accepts each string of length in time O(n) n
Non-Deterministic Polynomial time algorithms: L NTIME( n k )
The class NP NP = NTIME( n k ) for all k Non-Deterministic Polynomial time
Eample: The satisfiability problem L = { w:epression w is satisfiable} Non-Deterministic algorithm: Guess an assignment of the variables Check if this is a satisfying assignment
L = { w:epression w is satisfiable} Time for n variables: Guess an assignment of the variables O(n) Check if this is a satisfying assignment O(n) Total time: O(n)
L = { w:epression w is satisfiable} L NP The satisfiability problem is an NP - Problem
Our Three Classic Problems: Satisfiability Hamiltonian Path Clique All can be solved in polynomial time using non-deterministic Turing machines. Could they be solved in polynomial time using deterministic Turing machines?
Observation: P NP Deterministic Polynomial Non-Deterministic Polynomial
Open Problem: P = NP? WE DO NOT KNOW THE ANSWER
Open Problem: P = NP? Eample: Does the Satisfiability problem have a polynomial time deterministic algorithm? WE DO NOT KNOW THE ANSWER
Polynomial Time Reductions Polynomial Computable function f : For any w computes in polynomial time f (w)
Language A is polynomial time reducible to language B if there is a polynomial computable function f such that: w A f ( w) B
Theorem: Suppose that is polynomial reducible to. B P A If then. Proof: Let M Machine to accept A P be the machine to accept B On input w : A 1. Compute f (w) in polynomial time: 2. Run M on input f (w) B
3CNF formula: ) ( ) ( ) ( ) ( 6 5 4 4 6 3 6 5 3 3 2 1 Each clause has three literals 3SAT ={ : is a satisfiable 3CNF formula} w w Language:
Theorem: 3SAT is polynomial time reducible to CLIQUE Proof: give a polynomial time reduction of one problem to the other
( 1 1 2) ( 1 2 2) ( 1 2 3) 1 2 2 1 1 1 2 2 3
) ( ) ( ) ( 3 2 1 2 2 1 2 1 1 1 1 2 1 2 2 1 2 3 1 0 1 3 2 1 = = =
NP-Completeness A problem is NP-complete if: It is in NP Every NP problem is reduced to it (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
Cook s Theorem: The satisfiability problem is NP-complete Sketch of Proof: Convert a Non-Deterministic Turing Machine to a Boolean epression in conjunctive normal form
Observations: It is unlikely(??) that NP-complete problems are in P The NP-complete problems have eponential time algorithms Approimations of these problems are in P
Other NP-Complete Problems: The Traveling Salesperson Problem Verte cover Hamiltonian Path All the above are reduced to the satisfiability problem
What s Net Read 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 Net Lecture Topics More Compleity Final eam Friday 12/19 Closed book, but you may bring one sheet of 8.5 11 inch paper with any notes you like. Homework Homework 14 Due Today Homework 15 Due Tuesday Homework 16 = study for the final!!