Nfa egs28. a b a b
q0
a
b
q1
q2
λ
q3
λ
28
29. a b a b
q0
a
b
q1
q2
λ
q3
λ
29
30. a b a b
q0
a
b
q1
q2
λ
q3
λ
30
31. a b a b
q0
a
b
q1
q2
λ
q3
λ
31
32. a b a b
q0
a
b
q1
q2
λ
q3
λ
32
33. a b a b
q0
a
b
q1
q2
λ
q3
λ
33
34. a b a b
“accept”
q0
a
b
q1
q2
λ
q3
λ
34
38. Formal Definition of NFAs
M = ( Q, Σ, δ , q0 , F )
Q:
Set of states, i.e.
{ q0 , q1, q2 }
Σ:
Input aplhabet, i.e.
{ a, b}
δ:
Transition function
q0 : Initial state
F:
Final states
38
41. δ (q0 , λ ) = {q0 , q2 }
0
q0
1
q1
0, 1 q
2
λ
41
44. δ * ( q0 , aa ) = { q4 , q5 }
q5
q4
a
q0
a
a
b
q1
λ
q2
λ
q3
44
45. δ * ( q0 , ab ) = { q2 , q3 , q0 }
q5
q4
a
q0
a
a
b
q1
λ
q2
λ
q3
45
47. The Language of an NFA M
F = { q0 ,q5 }
q5
q4
a
q0
a
a
b
q1
q2
λ
q3
λ
δ * ( q0 , aa ) = { q4 , q5 }
aa ∈ L(M )
47
48. F = { q0 ,q5 }
q5
q4
a
q0
a
a
b
q1
q2
λ
q3
λ
δ * ( q0 , ab ) = { q2 , q3 , q0 }
ab ∈ L( M )
48
49. F = { q0 ,q5 }
q5
q4
a
q0
a
a
b
q1
q2
λ
q3
λ
δ * ( q0 , abaa ) = { q4 , q5 }
aaba ∈ L(M )
49
50. F = { q0 ,q5 }
q5
q4
a
q0
a
a
b
q1
q2
λ
q3
λ
δ * ( q0 , aba ) = { q1}
aba ∉ L( M )
50
52. Formally
The language accepted by NFA
M
is:
L( M ) = { w1, w2 , w3 ,...}
where
δ * (q0 , wm ) = {qi , q j ,...}
and there is some
qk ∈ F
(final state)
52
53. w∈ L( M )
δ * (q0 , w)
qi
w
q0
qk
w
w
qk ∈ F
qj
53
56. Example
L( M1 ) = {10} *
L( M 2 ) = {10} *
0
q0
1
0
q0
1
NFA
q1
M1
0, 1
q2
λ
DFA
q1
0
M2
0,1
1
q2
56
57. Since
L( M1 ) = L( M 2 ) = {10} *
machines
NFA
DFA
M1
M1
M2
and
M2
are equivalent
0
q0
1
q1
0, 1
λ
0,1
0
q0
1
q2
q1
0
1
q2
57
58. Equivalence of NFAs and DFAs
Question:
NFAs
=
DFAs ?
Same power?
Accept the same languages?
58
59. Equivalence of NFAs and DFAs
Question:
NFAs
=
DFAs ?
YES!
Same power?
Accept the same languages?
59
75. NFA to DFA: Remarks
We are given an NFA
M
We want to convert it
to an equivalent DFA M ′
With
L( M ) = L(M ′)
75
76. If the NFA has states
q0 , q1, q2 ,...
the DFA has states in the powerset
∅, { q0 } , { q1} , { q1, q2 } , { q3 , q4 , q7 } ,....
76
77. Procedure NFA to DFA
1.
Initial state of NFA:
q0
Initial state of DFA:
{ q0 }
77
79. Procedure NFA to DFA
2. For every DFA’s state {qi , q j ,..., qm }
Compute in the NFA
δ * ( qi , a ) ,
δ * ( q j , a ),
′
= {qi′ , q′j ,..., qm }
...
Add transition
′
δ ({qi , q j ,..., qm }, a ) = {qi′ , q′j ,..., qm }
79
81. Procedure NFA to DFA
Repeat Step 2 for all letters in alphabet,
until
no more transitions can be added.
81
83. Procedure NFA to DFA
3. For any DFA state {qi , q j ,..., qm }
If some
qj
is a final state in the NFA
Then, {qi , q j ,..., qm }
is a final state in the DFA
83