CS 301 - Lecture 28 , 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 – 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 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?? k 1 k Theorem: DTIME(n + ) ⊂ DTIME(n )

DTIME(nk+1)

DTIME(nk ) The class P

k P = ∪DTIME(n ) for 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} {anbn} Some Classic Problems in Computer Science

•Satisfiability Problem

•Hamiltonian Path Problem

•Clique Problem

Are these problems in P ?? Example: The Satisfiability Problem

Boolean expressions in Conjunctive Normal Form:

t1 ∧ t2 ∧ t3 ∧∧ tk

ti = x1 ∨ x2 ∨ x3 ∨∨ xp Variables

Question: is expression satisfiable? Example: (x1 ∨ x2) ∧ (x1 ∨ x3)

Satisfiable: x1 = 0, x2 =1, x3 =1

(x1 ∨ x2) ∧ (x1 ∨ x3) =1 Example: (x1 ∨ x2) ∧ x1 ∧ x2

Not satisfiable ={w: expression w is satisfiable}

n For n variables: L∈ DTIME(2 ) exponential

Algorithm: search exhaustively all the possible binary values of the variables Example: the Hamiltonian Problem

s t

Question: is there a simple path that passes through all vertices? s t

YES! A solution: search exhaustively all paths

L = {: there is a Hamiltonian path in G from s to t}

L∈ DTIME(n!) ≈ DTIME(2n)

Exponential time

Intractable problem Clique:

A 5-clique

CLIQUE = { : Given a graph does G contains< G,k > a -clique} G k Again, no obvious deterministic polynomial time ….. Non-Determinism Language class: NTIME(n)

NTIME(n) L 1 L3 L2

A Non-Deterministic Turing Machine accepts each string of length n in time O(n) Non-Deterministic Polynomial time :

L∈ NTIME(nk ) The class NP

NP = ∪NTIME(nk ) for all k

Non-Deterministic Polynomial time Example: The satisfiability problem

L ={w: expression w is satisfiable}

Non-Deterministic algorithm: •Guess an assignment of the variables

•Check if this is a satisfying assignment L ={w: expression 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: expression 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 Non-Deterministic Polynomial Polynomial Open Problem: P = NP ?

WE DO NOT KNOW THE ANSWER Open Problem: P = NP ?

Example: Does the Satisfiability problem have a polynomial time deterministic algorithm?

WE DO NOT KNOW THE ANSWER Polynomial Time Reductions Polynomial f :

For any w computes f (w) in polynomial time 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 A is polynomial reducible to B . If B ∈ P then A ∈ P .

Proof: Let M be the machine to accept B Machine to accept A in polynomial time: On input w : 1. Compute f (w) 2. Run M on input f (w) 3CNF formula:

(x1 ∨ x2 ∨ x3) ∧ (x3 ∨ x5 ∨ x6) ∧ (x3 ∨ x6 ∨ x4) ∧ (x4 ∨ x5 ∨ x6)

Each clause has three literals

Language:

3SAT ={ w : w is a satisfiable 3CNF formula} Theorem: 3SAT is polynomial time reducible to CLIQUE

Proof: give a polynomial time reduction of one problem to the other (x1 ∨ x1 ∨ x2) ∧ (x1 ∨ x2 ∨ x2) ∧ (x1 ∨ x2 ∨ x3)

x x1 x2 2

x1 x1

x1 x2

x2 x3 (x1 ∨ x1 ∨ x2) ∧ (x1 ∨ x2 ∨ x2) ∧ (x1 ∨ x2 ∨ x3) x1 =1 x2 = 0 x3 =1 x x1 x2 2

x1 x1

x1 x2

x2 x3 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 expression in conjunctive normal form Observations:

It is unlikely(??) that NP-complete problems are in P

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

All the above are reduced to the satisfiability problem What’s Next

• 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 • Next Lecture Topics – More Complexity • Final exam Friday 12/19 – Closed book, but you may bring one sheet of 8.5 x 11 inch paper with any notes you like. • Homework – Homework 14 Due Today – Homework 15 Due Tuesday – Homework 16 = study for the final!!