0, 1
q0 1 q1 0 q2 1 q3
q0 1 q1 0 q2 1 q3
q0 1 q1 0 q2 1 q3
q0 1 q1 0 q2 1 q3
• Answer
0, 1 0, 1
0 0 1 q
q0 q1 q2 q33
Example
• Construct an NFA that accepts all strings with an even
number of 0s or an odd number of 1s
1 1
0
r0 r1 even number of 0s
ε 0
q0
ε 0 0
1 odd number of 1s
s0 s1
1
table of
transition function δ :
alphabet Σ = {0, 1}
inputs
states Q = {q0, q1, q2}
0 1 ε
initial state q0
accepting states F = {q2} q0 ∅ {q1} {q1}
states
q4 q5
a a
q0 a q1 b q2 λ q3
λ 13
δ * ( q0 , aa ) = { q4 , q5 }
q4 q5
a a
q0 a q1 b q2 λ q3
λ 14
δ * ( q0 , ab ) = { q2 , q3 , q0 }
q4 q5
a a
q0 a q1 b q2 λ q3
λ 15
The Language of an NFA
M
•F = { q0 ,q5 } q4 q5
a a
q0 a q1 b q2 λ q3
λ
δ * ( q0 , aa ) = { q4 , q5 } aa ∈ L(M )
∈F 16
F = { q0 ,q5 }
q4 q5
a a
q0 a q1 b q2 λ q3
λ
δ * ( q0 , ab ) = { q2 , q3 , q0 } ab ∈ L( M )
∈F 17
F = { q0 ,q5 }
q4 q5
a a
q0 a q1 b q2 λ q3
λ
L( M ) = { λ } ∪ { ab} * {aa}
19
Formally
MNFA
• The language accepted by is:
L( M ) = { w1, w2 , w3 ,...}
qk
• and there is some ∈F (accepting state)
20
NFAs are as powerful as
DFAs
• Obviously, an NFA can do everything
a DFA can do
• But can it do more?
NFAs are as powerful as
•
DFAs
Obviously, an NFA can do everything a
DFA can do
• But can it do more?
NO!
• Theorem
If a language L is accepted by some NFA, then
it is also accepted by some DFA.
Equivalence of Machines
• Definition:
23
Example of equivalent
machines M1
NFA 0
L•( M 1) = {10} *
q0 q1
1
FA M2 0,1
0
L( M 2 ) = {10} *
q0 q1 1 q2
1
0 24
NFA to DFA conversion
intuition
0, 1
NFA: q0 1 q1 0 q2
0 0
DFA: q0 1 q0 or q1 0 q0 or q2
1 1
NFA to DFA conversion
intuition
0, 1
NFA: q0 1 q1 0 q2
0 0
1 1
General method
NFA DFA
states q0, q1, …, qn ∅, {q0}, {q1}, {q0,q1}, …, {q0,
…,qn}
one for each subset of states in the
NFA
initial q0 {q0}
state
transitions δ δ ’({qi1,…,qik }, a) =
δ (qi1, a) ∪…∪ δ (qik ,
a)
accepting F ⊆ Q F’ = {S: S contains some
states state in F}
Why the method works
After reading n symbols, the DFA is in
state
{qi1,…,qik } if and only if the NFA is in one
of the states qi1,…,qik
• At the end, the DFA accepts when it is
in a state that contains some
accepting state of NFA
FA
M2 a
q2
a
q0 a q1
L( M 2 ) = {a} 29
•NFAs are interesting because we can
express languages easier than FAs
NFA
M1 FA
M2 a
q2
q0 a q1
a
q0 a q1
L( M1 ) = {a} L( M 2 ) = {a} 30