Download presentation
Presentation is loading. Please wait.
1
NFAs and DFAs Sipser 1.2 (pages 47-63)
2
Last time…
3
CS 311 Mount Holyoke College 3 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 – q 0 ∈ Q is the start state – F ⊆ Q is a set of accept states In-class exercise:
4
CS 311 Mount Holyoke College 4 NFA computation Let N=(Q, Σ, δ, q 0, F) be a NFA and let w be a string over the alphabet Σ Then N accepts w if – w can be written as w 1 w 2 w 3 …w m with each w i ∈ Σε and –There exists a sequence of states s 0,s 1,s 2,…,s m exists in Q with the following conditions: 1.s 0 =q 0 2.s i+1 ∈ δ(s i,w i+1 ) for i = 0,…,m-1 3.s n ∈ F
5
One last operation
6
CS 311 Mount Holyoke College 6 Kleene star operation Let A be a language. The Kleene star operation is A* = {x 1 x 2 …x k | k ≥ 0 and each x i ∈ A} Exercise A = {w | w is a string of 0 s and 1 s containing an odd number of 1 s } B = {w | w is a string of 0 s and 1 s containing an even number of 1 s } C = {0,1} What are A*, B*, and C* ?
7
CS 311 Mount Holyoke College 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 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
8
CS 311 Mount Holyoke College 8 Kleene star Theorem: The class of languages recognized by NFAs is closed under the Kleene star operation.
9
CS 311 Mount Holyoke College 9 If only… … somebody would prove that the class of languages recognized by NFAs and the class of languages recognized by DFAs were equal…
10
CS 311 Mount Holyoke College 10 Then… We’d have: –The class of regular languages is closed under: Concatenation Kleene star
11
CS 311 Mount Holyoke College 11 And… a cute proof for closure under union!
12
CS 311 Mount Holyoke College 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…
13
CS 311 Mount Holyoke College 13 Then there exists a DFA M M is a 5-tuple (Q, Σ, δ M, q 0, F), where – Q is a finite set called the states – Σ is a finite set called the alphabet – δ: Q × Σ → Q is the transition function – q 0 ∈ Q is the start state – F ⊆ Q is a set of accept states
14
CS 311 Mount Holyoke College 14 We need to show there exists an NFA N N is a 5-tuple (Q, Σ, δ N, 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 – q 0 ∈ Q is the start state – F ⊆ Q is a set of accept states Can we define N from M?
15
CS 311 Mount Holyoke College 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, Σ, δ, q 0, F)
16
CS 311 Mount Holyoke College 16 Equivalent machines Definition: Two machines are equivalent if they recognize the same language Let’s prove: Theorem: Every NFA has an equivalent DFA.
17
CS 311 Mount Holyoke College 17 Remember…
18
CS 311 Mount Holyoke College 18 A simpler example
19
CS 311 Mount Holyoke College 19 Removing choice Proof: Let A be a language accepted by NFA N = (Q, Σ, δ, q 0, F) We construct a DFA M=(Q’, Σ, δ’, q 0 ’, F’) recognizing A – Q’ = P(Q) –For R ∈ Q' and a ∈ Σ, define δ'(R,a) = ∪ δ(r,a) – q 0 ’ = {q 0 } – F’ = { R ∈ Q’ | R contains an accept state from F} r∈Rr∈R
20
CS 311 Mount Holyoke College 20 Okay, but what about ε arrows?
21
CS 311 Mount Holyoke College 21 Modifying our construction Proof: Let A be a language accepted by NFA N = (Q, Σ, δ, q 0, F) We construct a DFA M=(Q’, Σ, δ’, q 0 ’, 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 } – q 0 ’ = E({q 0 }) – F’ = { R ∈ Q’ | R contains an accept state from F} r∈Rr∈R
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.