Top Banner
CS 301 - Lecture 28 P, NP, and NP-Completeness Fall 2008
40

CS 301 - Lecture 28 P, NP, and NP-Completenessmassey/Teaching/cs301/Restric… ·  · 2008-12-09Review • Languages and Grammars – Alphabets, strings, languages • Regular Languages

May 14, 2018

Download

Documents

duongkiet
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: CS 301 - Lecture 28 P, NP, and NP-Completenessmassey/Teaching/cs301/Restric… ·  · 2008-12-09Review • Languages and Grammars – Alphabets, strings, languages • Regular Languages

CS 301 - Lecture 28 P, NP, and

NP-Completeness

Fall 2008

Page 2: CS 301 - Lecture 28 P, NP, and NP-Completenessmassey/Teaching/cs301/Restric… ·  · 2008-12-09Review • Languages and Grammars – Alphabets, strings, languages • Regular Languages

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

Page 3: CS 301 - Lecture 28 P, NP, and NP-Completenessmassey/Teaching/cs301/Restric… ·  · 2008-12-09Review • Languages and Grammars – Alphabets, strings, languages • Regular Languages

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?

Page 4: CS 301 - Lecture 28 P, NP, and NP-Completenessmassey/Teaching/cs301/Restric… ·  · 2008-12-09Review • Languages and Grammars – Alphabets, strings, languages • Regular Languages

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??

Page 5: CS 301 - Lecture 28 P, NP, and NP-Completenessmassey/Teaching/cs301/Restric… ·  · 2008-12-09Review • Languages and Grammars – Alphabets, strings, languages • Regular Languages

Theorem:

)( knDTIME

)( 1+knDTIME

)()( 1 kk nDTIMEnDTIME ⊂+

Page 6: CS 301 - Lecture 28 P, NP, and NP-Completenessmassey/Teaching/cs301/Restric… ·  · 2008-12-09Review • Languages and Grammars – Alphabets, strings, languages • Regular Languages

)( knDTIMEP ∪= for all k

The class P

• All tractable problems

• Polynomial time • Type of deterministic machine no longer matters • Adding more tapes changes k for a particular problem, but still polynomial

Page 7: CS 301 - Lecture 28 P, NP, and NP-Completenessmassey/Teaching/cs301/Restric… ·  · 2008-12-09Review • Languages and Grammars – Alphabets, strings, languages • Regular Languages

P

}{ nnba}{ww

Page 8: CS 301 - Lecture 28 P, NP, and NP-Completenessmassey/Teaching/cs301/Restric… ·  · 2008-12-09Review • Languages and Grammars – Alphabets, strings, languages • Regular Languages

Some Classic Problems in Computer Science

• Satisfiability Problem

• Hamiltonian Path Problem

• Clique Problem

Are these problems in P ??

Page 9: CS 301 - Lecture 28 P, NP, and NP-Completenessmassey/Teaching/cs301/Restric… ·  · 2008-12-09Review • Languages and Grammars – Alphabets, strings, languages • Regular Languages

Example: The Satisfiability Problem

Boolean expressions in Conjunctive Normal Form:

ktttt ∧∧∧∧ 321

pi xxxxt ∨∨∨∨= 321Variables

Question: is expression satisfiable?

Page 10: CS 301 - Lecture 28 P, NP, and NP-Completenessmassey/Teaching/cs301/Restric… ·  · 2008-12-09Review • Languages and Grammars – Alphabets, strings, languages • Regular Languages

)()( 3121 xxxx ∨∧∨

Satisfiable: 1,1,0 321 === xxx

1)()( 3121 =∨∧∨ xxxx

Example:

Page 11: CS 301 - Lecture 28 P, NP, and NP-Completenessmassey/Teaching/cs301/Restric… ·  · 2008-12-09Review • Languages and Grammars – Alphabets, strings, languages • Regular Languages

2121 )( xxxx ∧∧∨

Not satisfiable

Example:

Page 12: CS 301 - Lecture 28 P, NP, and NP-Completenessmassey/Teaching/cs301/Restric… ·  · 2008-12-09Review • Languages and Grammars – Alphabets, strings, languages • Regular Languages

e}satisfiabl is expression :{ wwL =

)2( nDTIMEL∈For variables: n

Algorithm: search exhaustively all the possible binary values of the variables

exponential

Page 13: CS 301 - Lecture 28 P, NP, and NP-Completenessmassey/Teaching/cs301/Restric… ·  · 2008-12-09Review • Languages and Grammars – Alphabets, strings, languages • Regular Languages

Example: the Hamiltonian Problem

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

s t

Page 14: CS 301 - Lecture 28 P, NP, and NP-Completenessmassey/Teaching/cs301/Restric… ·  · 2008-12-09Review • Languages and Grammars – Alphabets, strings, languages • Regular Languages

s t

YES!

Page 15: CS 301 - Lecture 28 P, NP, and NP-Completenessmassey/Teaching/cs301/Restric… ·  · 2008-12-09Review • Languages and Grammars – Alphabets, strings, languages • Regular Languages

)2()!( nDTIMEnDTIMEL ≈∈

Exponential time

Intractable problem

A solution: search exhaustively all paths

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

Page 16: CS 301 - Lecture 28 P, NP, and NP-Completenessmassey/Teaching/cs301/Restric… ·  · 2008-12-09Review • Languages and Grammars – Alphabets, strings, languages • Regular Languages

Clique:

A 5-clique

CLIQUE = { : Given a graph does G contains a -clique}

Again, no obvious deterministic polynomial time algorithm…..

>< kG, Gk

Page 17: CS 301 - Lecture 28 P, NP, and NP-Completenessmassey/Teaching/cs301/Restric… ·  · 2008-12-09Review • Languages and Grammars – Alphabets, strings, languages • Regular Languages

Non-Determinism Language class: )(nNTIME

A Non-Deterministic Turing Machine accepts each string of length in time

)(nNTIME

1L2L 3L

)(nOn

Page 18: CS 301 - Lecture 28 P, NP, and NP-Completenessmassey/Teaching/cs301/Restric… ·  · 2008-12-09Review • Languages and Grammars – Alphabets, strings, languages • Regular Languages

Non-Deterministic Polynomial time algorithms:

)( knNTIMEL∈

Page 19: CS 301 - Lecture 28 P, NP, and NP-Completenessmassey/Teaching/cs301/Restric… ·  · 2008-12-09Review • Languages and Grammars – Alphabets, strings, languages • Regular Languages

)( knNTIMENP ∪= for all k

The class NP

Non-Deterministic Polynomial time

Page 20: CS 301 - Lecture 28 P, NP, and NP-Completenessmassey/Teaching/cs301/Restric… ·  · 2008-12-09Review • Languages and Grammars – Alphabets, strings, languages • Regular Languages

Example: The satisfiability problem

Non-Deterministic algorithm:

• Guess an assignment of the variables

e}satisfiabl is expression :{ wwL =

• Check if this is a satisfying assignment

Page 21: CS 301 - Lecture 28 P, NP, and NP-Completenessmassey/Teaching/cs301/Restric… ·  · 2008-12-09Review • Languages and Grammars – Alphabets, strings, languages • Regular Languages

Time for variables: n

)(nO

e}satisfiabl is expression :{ wwL =

Total time:

• Guess an assignment of the variables

• Check if this is a satisfying assignment )(nO

)(nO

Page 22: CS 301 - Lecture 28 P, NP, and NP-Completenessmassey/Teaching/cs301/Restric… ·  · 2008-12-09Review • Languages and Grammars – Alphabets, strings, languages • Regular Languages

e}satisfiabl is expression :{ wwL =

NPL∈

The satisfiability problem is an - Problem NP

Page 23: CS 301 - Lecture 28 P, NP, and NP-Completenessmassey/Teaching/cs301/Restric… ·  · 2008-12-09Review • Languages and Grammars – Alphabets, strings, languages • Regular Languages

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?

Page 24: CS 301 - Lecture 28 P, NP, and NP-Completenessmassey/Teaching/cs301/Restric… ·  · 2008-12-09Review • Languages and Grammars – Alphabets, strings, languages • Regular Languages

Observation:

NPP ⊆

Deterministic Polynomial

Non-Deterministic Polynomial

Page 25: CS 301 - Lecture 28 P, NP, and NP-Completenessmassey/Teaching/cs301/Restric… ·  · 2008-12-09Review • Languages and Grammars – Alphabets, strings, languages • Regular Languages

Open Problem: ?NPP =

WE DO NOT KNOW THE ANSWER

Page 26: CS 301 - Lecture 28 P, NP, and NP-Completenessmassey/Teaching/cs301/Restric… ·  · 2008-12-09Review • Languages and Grammars – Alphabets, strings, languages • Regular Languages

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

WE DO NOT KNOW THE ANSWER

Open Problem: ?NPP =

Page 27: CS 301 - Lecture 28 P, NP, and NP-Completenessmassey/Teaching/cs301/Restric… ·  · 2008-12-09Review • Languages and Grammars – Alphabets, strings, languages • Regular Languages

Polynomial Time Reductions Polynomial Computable function : f

For any computes in polynomial time

)(wfw

Page 28: CS 301 - Lecture 28 P, NP, and NP-Completenessmassey/Teaching/cs301/Restric… ·  · 2008-12-09Review • Languages and Grammars – Alphabets, strings, languages • Regular Languages

Language A is polynomial time reducible to language B if there is a polynomial computable function such that: f

BwfAw ∈⇔∈ )(

Page 29: CS 301 - Lecture 28 P, NP, and NP-Completenessmassey/Teaching/cs301/Restric… ·  · 2008-12-09Review • Languages and Grammars – Alphabets, strings, languages • Regular Languages

Suppose that is polynomial reducible to . If then .

Theorem:

PB∈A B

PA∈

Proof:

Machine to accept in polynomial time: AOn input : w

1. Compute )(wf

Let be the machine to accept BM

2. Run on input )(wfM

Page 30: CS 301 - Lecture 28 P, NP, and NP-Completenessmassey/Teaching/cs301/Restric… ·  · 2008-12-09Review • Languages and Grammars – Alphabets, strings, languages • Regular Languages

3CNF formula:

)()()()( 654463653321 xxxxxxxxxxxx ∨∨∧∨∨∧∨∨∧∨∨

Each clause has three literals

3SAT ={ : is a satisfiable 3CNF formula}

w wLanguage:

Page 31: CS 301 - Lecture 28 P, NP, and NP-Completenessmassey/Teaching/cs301/Restric… ·  · 2008-12-09Review • Languages and Grammars – Alphabets, strings, languages • Regular Languages

Theorem: 3SAT is polynomial time reducible to CLIQUE

Proof: give a polynomial time reduction of one problem to the other

Page 32: CS 301 - Lecture 28 P, NP, and NP-Completenessmassey/Teaching/cs301/Restric… ·  · 2008-12-09Review • Languages and Grammars – Alphabets, strings, languages • Regular Languages

)()()( 321221211 xxxxxxxxx ∨∨∧∨∨∧∨∨

1x

1x

2x

1x 2x 2x

1x

2x

3x

Page 33: CS 301 - Lecture 28 P, NP, and NP-Completenessmassey/Teaching/cs301/Restric… ·  · 2008-12-09Review • Languages and Grammars – Alphabets, strings, languages • Regular Languages

)()()( 321221211 xxxxxxxxx ∨∨∧∨∨∧∨∨

1x

1x

2x

1x 2x 2x

1x

2x

3x

101

3

2

1

=

=

=

xxx

Page 34: CS 301 - Lecture 28 P, NP, and NP-Completenessmassey/Teaching/cs301/Restric… ·  · 2008-12-09Review • Languages and Grammars – Alphabets, strings, languages • Regular Languages

NP-Completeness A problem is NP-complete if:

• It is in NP

• Every NP problem is reduced to it

(in polynomial time)

Page 35: CS 301 - Lecture 28 P, NP, and NP-Completenessmassey/Teaching/cs301/Restric… ·  · 2008-12-09Review • Languages and Grammars – Alphabets, strings, languages • Regular Languages

Observation:

If we can solve any NP-complete problem in Deterministic Polynomial Time (P time) then we know:

NPP =

Page 36: CS 301 - Lecture 28 P, NP, and NP-Completenessmassey/Teaching/cs301/Restric… ·  · 2008-12-09Review • Languages and Grammars – Alphabets, strings, languages • Regular Languages

Observation:

If we prove that we cannot solve an NP-complete problem in Deterministic Polynomial Time (P time) then we know:

NPP ≠

Page 37: CS 301 - Lecture 28 P, NP, and NP-Completenessmassey/Teaching/cs301/Restric… ·  · 2008-12-09Review • Languages and Grammars – Alphabets, strings, languages • Regular Languages

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

Page 38: CS 301 - Lecture 28 P, NP, and NP-Completenessmassey/Teaching/cs301/Restric… ·  · 2008-12-09Review • Languages and Grammars – Alphabets, strings, languages • Regular Languages

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

Page 39: CS 301 - Lecture 28 P, NP, and NP-Completenessmassey/Teaching/cs301/Restric… ·  · 2008-12-09Review • Languages and Grammars – Alphabets, strings, languages • Regular Languages

Other NP-Complete Problems:

• The Traveling Salesperson Problem

• Vertex cover

• Hamiltonian Path

All the above are reduced to the satisfiability problem

Page 40: CS 301 - Lecture 28 P, NP, and NP-Completenessmassey/Teaching/cs301/Restric… ·  · 2008-12-09Review • Languages and Grammars – Alphabets, strings, languages • Regular Languages

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!!