NFAs and DFAs

21
NFAs and DFAs Sipser 1.2 (pages 47-63)

description

NFAs and DFAs. Sipser 1.2 (pages 47-63). Last time…. NFA. A nondeterministic finite automaton (NFA) is a 5-tuple (Q, Σ , δ , q 0 , F) , where Q is a finite set called the states Σ is a finite set called the alphabet δ : Q × Σε → P(Q) is the transition function - PowerPoint PPT Presentation

Transcript of NFAs and DFAs

Page 1: NFAs  and  DFAs

NFAs and DFAs

Sipser 1.2 (pages 47-63)

Page 2: NFAs  and  DFAs

Last time…

Page 3: NFAs  and  DFAs

CS 311Fall 2008 3

NFA• A nondeterministic finite

automaton (NFA) is a 5-tuple (Q, Σ, δ, q0, F), where– Q is a finite set called the states– Σ is a finite set called the alphabet– δ: Q × Σε → P(Q) is the transition function– q0 Q∈ is the start state– F Q ⊆ is a set of accept states

• In-class exercise:

Page 4: NFAs  and  DFAs

CS 311Fall 2008 4

NFA computation• Let N=(Q, Σ, δ, q0, F) be a NFA and let

w be a string over the alphabet Σ• Then N accepts w if

– w can be written as w1w2w3…wm with each wi Σε∈and– There exists a sequence of states

s0,s1,s2,…,sm exists in Q with the following conditions:1. s0=q0

2. si+1 δ(s∈ i,wi+1) for i = 0,…,m-13. sn F∈

Page 5: NFAs  and  DFAs

One last operation

Page 6: NFAs  and  DFAs

CS 311Fall 2008 6

Kleene star operation• Let A be a language. • The Kleene star operation is

A* = {x1x2…xk | k ≥ 0 and each xi A} ∈

Exercise• A = {w | w is a string of 0s and 1s containing an odd

number of 1s}• B = {w | w is a string of 0s and 1s containing an even

number of 1s}• C = {0,1}

• What are A*, B*, and C*?

Page 7: NFAs  and  DFAs

CS 311Fall 2008 7

Clay Knee?

Kleene pronounced his last name klay'nee. His son, Ken Kleene, wrote:

"As far as I am aware this pronunciation is incorrect in all known languages. I believe that this novel pronunciation was invented by my father." Dr. "Clay Knee" must have been a geek of the

first water, to be sure!- From http://visualbasic.about.com/od/usevb6/a/RegExVB6.htm

Page 8: NFAs  and  DFAs

CS 311Fall 2008 8

Kleene star• Theorem: The class of languages

recognized by NFAs is closed under the Kleene star operation.

Page 9: NFAs  and  DFAs

CS 311Fall 2008 9

If only…… somebody would prove that the

class of languages recognized by NFAs and

the class of languages recognized by DFAs

were equal…

Page 10: NFAs  and  DFAs

CS 311Fall 2008 10

Then…• We’d have:– The class of regular languages is closed

under:• Concatenation• Kleene star

Page 11: NFAs  and  DFAs

CS 311Fall 2008 11

And…a cute proof for closure under union!

Page 12: NFAs  and  DFAs

CS 311Fall 2008 12

We can be that somebody!• Theorem: A language is regular if and

only if there exists an NFA that recognizes it.

• Proof:(⇒)Let A be a regular language…

Page 13: NFAs  and  DFAs

CS 311Fall 2008 13

Then there exists a DFA M• M is a 5-tuple (Q, Σ, δM, q0, F), where– Q is a finite set called the states– Σ is a finite set called the alphabet– δ: Q × Σ → Q is the transition function– q0 Q∈ is the start state– F Q ⊆ is a set of accept states

Page 14: NFAs  and  DFAs

CS 311Fall 2008 14

We need to show there exists an NFA N

• N is a 5-tuple (Q, Σ, δN, q0, F), where– Q is a finite set called the states– Σ is a finite set called the alphabet– δ: Q × Σε → P(Q) is the transition

function– q0 Q∈ is the start state– F Q ⊆ is a set of accept states

• Can we define N from M?

Page 15: NFAs  and  DFAs

CS 311Fall 2008 15

Now the other way!• Theorem: A language is regular if and

only if there exists an NFA that recognizes it.

• Proof:(⇒)Let A be a language accepted by NFA N = (Q, Σ, δ, q0, F)

Page 16: NFAs  and  DFAs

CS 311Fall 2008 16

Equivalent machines• Definition: Two machines are

equivalent if they recognize the same language

• Let’s prove:Theorem: Every NFA has an equivalent DFA.

Page 17: NFAs  and  DFAs

CS 311Fall 2008 17

Remember…

Page 18: NFAs  and  DFAs

CS 311Fall 2008 18

A simpler example

Page 19: NFAs  and  DFAs

CS 311Fall 2008 19

Removing choiceProof:• Let A be a language accepted by NFA

N = (Q, Σ, δ, q0, F) • We construct a DFA M=(Q’, Σ, δ’, q0’, F’)

recognizing A– Q’ = P(Q)– For R Q'∈ and a Σ∈ ,

define δ'(R,a) = δ(r,a)∪

– q0’ = {q0}– F’ = { R Q’ | R contains an accept state from F}∈

r R∈

Page 20: NFAs  and  DFAs

CS 311Fall 2008 20

Okay, but what about ε arrows?

Page 21: NFAs  and  DFAs

CS 311Fall 2008 21

Modifying our constructionProof:• Let A be a language accepted by NFA

N = (Q, Σ, δ, q0, F) • We construct a DFA M=(Q’, Σ, δ’, q0’, F’) recognizing A– Q’ = P(Q)– For R Q'∈ and a Σ∈ ,

define δ'(R,a) = E(δ(r,a))∪

where E(R) = {q | q can be reached from R along 0 or more ε arrows}

– q0’ = E({q0})– F’ = { R Q’ | R contains an accept state from F}∈

r R∈