cs 302: discrete math ii a review. an alphabet Σ is a finite set (e.g., Σ = {0,1}) a string over...

39
CS 302: Discrete Math II A Review

Post on 19-Dec-2015

215 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: CS 302: Discrete Math II A Review. An alphabet Σ is a finite set (e.g., Σ = {0,1}) A string over Σ is a finite-length sequence of elements of Σ For x

CS 302: Discrete Math II

A Review

Page 2: CS 302: Discrete Math II A Review. An alphabet Σ is a finite set (e.g., Σ = {0,1}) A string over Σ is a finite-length sequence of elements of Σ For x

An alphabet Σ is a finite set (e.g., Σ = {0,1})

A string over Σ is a finite-length sequence of elements of Σ

For x a string, |x| is the length of x

The unique string of length 0 will be denoted by ε and will be called the empty or null string

NOTATION

A language over Σ is a set of strings over Σ

Page 3: CS 302: Discrete Math II A Review. An alphabet Σ is a finite set (e.g., Σ = {0,1}) A string over Σ is a finite-length sequence of elements of Σ For x

Q = {q0, q1, q2, q3} are states

Σ = {0,1} is the alphabet

: Q Σ → Q transition function*q0 Q is start state

F = {q1, q2} Q accept states

M = (Q, Σ, , q0, F) where

0 1

q0 q0 q1

q1 q2 q2

q2 q3 q2

q3 q0 q2

*q2

00,1

00

1

1

1

q0

q1

q3

M

NFAs have “choices” -- : Q Σ P (Q), and accepton input w if there is a path from q0 to a qa in F.

Page 4: CS 302: Discrete Math II A Review. An alphabet Σ is a finite set (e.g., Σ = {0,1}) A string over Σ is a finite-length sequence of elements of Σ For x

DFA NFA

RegularLanguage

RegularExpression

DEF

Page 5: CS 302: Discrete Math II A Review. An alphabet Σ is a finite set (e.g., Σ = {0,1}) A string over Σ is a finite-length sequence of elements of Σ For x

THE REGULAR PUMPING LEMMA

Let L be a regular language

Then there exists P such that For every w L with |w| ≥ P

1. |y| > 0

there exist xyz=w, where:

3. xyiz L for any i ≥ 0

2. |xy| ≤ P

{ ww : w 2 Σ* } is not regular!

Page 6: CS 302: Discrete Math II A Review. An alphabet Σ is a finite set (e.g., Σ = {0,1}) A string over Σ is a finite-length sequence of elements of Σ For x

SOME LANGUAGES ARE NOT REGULAR!

B = {0n1n | n ≥ 0} is NOT regular!

Suppose B is regular and let P be the pumping length. The string 0P1P B and has length at least P. So by the pumping lemma, there shouldbe xyz = 0P1P so that |xy| ≤ P, |y| > 0, and xyyzB. But y must be only 0s (otherwise |xy| > P), so xyyz has at least P+1 “0”s (because |y| > 0) but only P “1”s. So xyyz B, contradicting the pumping lemma. Therefore B is not regular.

Page 7: CS 302: Discrete Math II A Review. An alphabet Σ is a finite set (e.g., Σ = {0,1}) A string over Σ is a finite-length sequence of elements of Σ For x

ε,ε → $0,ε → 0

1,0 → ε

1,0 → εε,$ → ε

string pop push

A PDA accepts the string x if there is a path on input x and empty stack from q0 to some qa 2 F.

Following transition “a,bc” reads “a” from the input, pops “b” off the stack, and pushes “c” onto it.

Page 8: CS 302: Discrete Math II A Review. An alphabet Σ is a finite set (e.g., Σ = {0,1}) A string over Σ is a finite-length sequence of elements of Σ For x

A → 0A1A → BB → #

CONTEXT-FREE GRAMMARS

A 0A1 00A11 00B11 00#11

A derives 00#11 in 4 steps.

uVw yields uvw if (V → v) in G.

variablesterminals

productionrules

start variable

Page 9: CS 302: Discrete Math II A Review. An alphabet Σ is a finite set (e.g., Σ = {0,1}) A string over Σ is a finite-length sequence of elements of Σ For x

THE CHOMSKY NORMAL FORM

A context-free grammar is in Chomsky normal form if every rule is of the form:

A → BC

A → a

S → ε

B and C are not start variable

a is a terminal

S is the start variable

Any variable A that is not the start variable can only generate strings of length > 0

Theorem: All grammars can be converted to CNF

Page 10: CS 302: Discrete Math II A Review. An alphabet Σ is a finite set (e.g., Σ = {0,1}) A string over Σ is a finite-length sequence of elements of Σ For x

THE CONTEXT-FREE PUMPING LEMMA

Let L be a context-free language

Then there exists P such that For every w L with |w| ≥ P

1. |vy| > 0

there exist uvxyz=w, where:

3. uvixyiz L for any i ≥ 0

2. |vxy| ≤ P

{ ww : w in Σ* } is not context-free!

Page 11: CS 302: Discrete Math II A Review. An alphabet Σ is a finite set (e.g., Σ = {0,1}) A string over Σ is a finite-length sequence of elements of Σ For x

0 → 0, R

read write move

→ , R

qaccept

qreject

0 → 0, R

→ , R

0 → 0, R

→ , L

TURING MACHINES

UNBOUNDED TAPE

0

q0

q0 q1

q2

q1 qa

0

Page 12: CS 302: Discrete Math II A Review. An alphabet Σ is a finite set (e.g., Σ = {0,1}) A string over Σ is a finite-length sequence of elements of Σ For x

Definition: A Turing Machine is a 7-tuple T = (Q, Σ, Γ, , q0, qaccept, qreject), where:

Q is a finite set of states; q0 is the start state

Σ is the input alphabet, Γ is the tape alphabet

: Q Γ → Q Γ {L,R} is the transition functionqaccept qreject are the accept and reject states

We can encode a TM as a string of 0s and 1s:

0n10m10k10s10t10r1…

n states

m tape symbols (first k are input

symbols)

start state

accept state

reject state

0n10m10k10s10t10r1…

n states

m tape symbols (first k are input

symbols)

start state

accept state

reject state

Page 13: CS 302: Discrete Math II A Review. An alphabet Σ is a finite set (e.g., Σ = {0,1}) A string over Σ is a finite-length sequence of elements of Σ For x

TerminologyEvery TM recognizes a language. The language of M is the set

L(M) = { w | M(w) eventually accepts }

A TM decides L if it accepts all strings in L and rejects all strings not in L

A language is decidable if some TM decides it

A language is recursively enumerable if some TM recognizes it.

THE CHURCH-TURING THESIS:

There is a program for L iff there is a TM for L

Page 14: CS 302: Discrete Math II A Review. An alphabet Σ is a finite set (e.g., Σ = {0,1}) A string over Σ is a finite-length sequence of elements of Σ For x

UNDECIDABILITY

A language is a set of strings. It is a mathematicalway of expressing a problem: given an input, is itin the set L?

If a language is decidable, there is a computer program (TM) that can always solve the problemcorrectly – it terminates and has the right answer.

If a language is undecidable, then no matter howsmart you are, and no matter how long you give it,you cannot program a computer to always solvethe problem correctly.

Page 15: CS 302: Discrete Math II A Review. An alphabet Σ is a finite set (e.g., Σ = {0,1}) A string over Σ is a finite-length sequence of elements of Σ For x

Let S be any set and P(S) be the power set of STheorem: There is no onto map from S to P(S)Proof: Assume, for a contradiction, that there is an onto map f : S P(S)

Let Df = { d S | d f(d) }

If Df = f(y) then y Df if and only if y Df

Turing MachinesStrings of 0s and 1s Sets of strings of

0s and 1s

Languages over {0,1}

S P(S)

Page 16: CS 302: Discrete Math II A Review. An alphabet Σ is a finite set (e.g., Σ = {0,1}) A string over Σ is a finite-length sequence of elements of Σ For x

UNDECIDABLE PROBLEMSDTM = { (M) : M is a TM that does not accept (M) }Theorem. DTM is undecidable.Proof. Suppose machine N decides DTM. ThenN accepts <N> → <N>DTM → N does not accept <N>

ATM = { (M,w) : M is a TM that accepts on input w }Theorem. If ATM is decidable, so is DTM.Proof. If ¬ATM is decided by the program nAcceptwe can decide if <M> DTM by calling nAccept(M,M).

Here we have reduced deciding DTM to decidingATM. Since we know DTM is undecidable, ATM

must also be undecidable.

Page 17: CS 302: Discrete Math II A Review. An alphabet Σ is a finite set (e.g., Σ = {0,1}) A string over Σ is a finite-length sequence of elements of Σ For x

MAPPING REDUCTIONS

f : Σ* Σ* is a computable function if there is a TM that on input w, halts with f(w) on its tape

A m B if there is a computable f, such thatw A f(w) B

f is called a reduction from A to B

A B

f

f

Page 18: CS 302: Discrete Math II A Review. An alphabet Σ is a finite set (e.g., Σ = {0,1}) A string over Σ is a finite-length sequence of elements of Σ For x

RICE’S THEOREM

Let P be a set of Turing machines. If P satisfies the following two properties:

For any TMs M1 and M2, where L(M1) = L(M2), M1 P if and only if M2 P

There exist TMs MIN P and MOUT P

Then P is undecidable

EXTREMELY POWERFUL

(i.e. P is a “nontrivial property of the r.e. languages.”)

Page 19: CS 302: Discrete Math II A Review. An alphabet Σ is a finite set (e.g., Σ = {0,1}) A string over Σ is a finite-length sequence of elements of Σ For x

CONTEXT-FREELANGUAGES

100

200

300

REGULARLANGUAGES

100

200

300

NON-REGULARNON-CFL

100

200

300

JEOPARDY

Page 20: CS 302: Discrete Math II A Review. An alphabet Σ is a finite set (e.g., Σ = {0,1}) A string over Σ is a finite-length sequence of elements of Σ For x

A DFA for the language (ab + ba)*

Page 21: CS 302: Discrete Math II A Review. An alphabet Σ is a finite set (e.g., Σ = {0,1}) A string over Σ is a finite-length sequence of elements of Σ For x

A regular expression for the set ofstrings accepted by the NFA:

0,1

1

Page 22: CS 302: Discrete Math II A Review. An alphabet Σ is a finite set (e.g., Σ = {0,1}) A string over Σ is a finite-length sequence of elements of Σ For x

A proof that the language { w Σ*: w ≠ wR }is not regular.

Page 23: CS 302: Discrete Math II A Review. An alphabet Σ is a finite set (e.g., Σ = {0,1}) A string over Σ is a finite-length sequence of elements of Σ For x

The language accepted by the following PDA:

ε,ε → $

0,ε → 0

1,0 → ε

1,0 → ε

ε, $ → ε

Page 24: CS 302: Discrete Math II A Review. An alphabet Σ is a finite set (e.g., Σ = {0,1}) A string over Σ is a finite-length sequence of elements of Σ For x

A CFG for the language { w # bn : |w| = n }.

Page 25: CS 302: Discrete Math II A Review. An alphabet Σ is a finite set (e.g., Σ = {0,1}) A string over Σ is a finite-length sequence of elements of Σ For x

Regular operations that the Context-Free Languages are closed under.

DAILY DOUBLE

Page 26: CS 302: Discrete Math II A Review. An alphabet Σ is a finite set (e.g., Σ = {0,1}) A string over Σ is a finite-length sequence of elements of Σ For x

A string in the language L = { 1n#1n : n ≥ 0} that contradicts the regular pumping lemma.

Page 27: CS 302: Discrete Math II A Review. An alphabet Σ is a finite set (e.g., Σ = {0,1}) A string over Σ is a finite-length sequence of elements of Σ For x

A string in the language {an#an#an : n ≥ 0 } thatcontradicts the context-free pumping lemma.

Page 28: CS 302: Discrete Math II A Review. An alphabet Σ is a finite set (e.g., Σ = {0,1}) A string over Σ is a finite-length sequence of elements of Σ For x

A proof that the language { an#bm : m = n2, n ≥ 0 } is not context-free.

Page 29: CS 302: Discrete Math II A Review. An alphabet Σ is a finite set (e.g., Σ = {0,1}) A string over Σ is a finite-length sequence of elements of Σ For x

Do there exist non-regular languages that satisfy the Regular Pumping Lemma?

Page 30: CS 302: Discrete Math II A Review. An alphabet Σ is a finite set (e.g., Σ = {0,1}) A string over Σ is a finite-length sequence of elements of Σ For x

UNDECIDABLE LANGUAGES

100

200

300

DECIDABLELANGUAGES

100

200

300

NP-COMPLETEREDUCTIONS

100

200

300

DOUBLE JEOPARDY

Page 31: CS 302: Discrete Math II A Review. An alphabet Σ is a finite set (e.g., Σ = {0,1}) A string over Σ is a finite-length sequence of elements of Σ For x

Show that if L1 and L2 are decidable,then so is L1 – L2.

Page 32: CS 302: Discrete Math II A Review. An alphabet Σ is a finite set (e.g., Σ = {0,1}) A string over Σ is a finite-length sequence of elements of Σ For x

A proof that the set {0,1,2}* is countable.

Page 33: CS 302: Discrete Math II A Review. An alphabet Σ is a finite set (e.g., Σ = {0,1}) A string over Σ is a finite-length sequence of elements of Σ For x

A proof that ODD ≤m EVEN, where

Σ = {0,1}ODD = { 1i : i is odd}

EVEN = { 1i : i is even}

Page 34: CS 302: Discrete Math II A Review. An alphabet Σ is a finite set (e.g., Σ = {0,1}) A string over Σ is a finite-length sequence of elements of Σ For x

A proof, using Rice’s Theorem, thatP3 = { (M) : M accepts all strings of length 3 }

is undecidable.

Page 35: CS 302: Discrete Math II A Review. An alphabet Σ is a finite set (e.g., Σ = {0,1}) A string over Σ is a finite-length sequence of elements of Σ For x

What operations are recursivelyenumerable languages closed

under?

Page 36: CS 302: Discrete Math II A Review. An alphabet Σ is a finite set (e.g., Σ = {0,1}) A string over Σ is a finite-length sequence of elements of Σ For x

A proof that ATM ≤m AJAVA ,where

AJAVA = { (J,w) : J is a Java program with method “public boolean test(string w)” that

returns true on string w. }

Page 37: CS 302: Discrete Math II A Review. An alphabet Σ is a finite set (e.g., Σ = {0,1}) A string over Σ is a finite-length sequence of elements of Σ For x

What’s the definition of NP?NP-Complete?

NP-hard?

Page 38: CS 302: Discrete Math II A Review. An alphabet Σ is a finite set (e.g., Σ = {0,1}) A string over Σ is a finite-length sequence of elements of Σ For x

Is Addition an NP-Complete problem?Why or why not?

Page 39: CS 302: Discrete Math II A Review. An alphabet Σ is a finite set (e.g., Σ = {0,1}) A string over Σ is a finite-length sequence of elements of Σ For x

Show that 4-SAT is NP-Complete byreducing it to 3-SAT.