3. Remarks:
•The symbol never appears on the
input tape
•Simple automata:
M1 M2
q0 q0
L(M1 ) = {} L(M 2 ) = {λ}
Fall 2004 COMP 335 3
4. •NFAs are interesting because we can
express languages easier than DFAs
NFA M1 DFA M2 a
q2
q0 a q1
a
q0 a q1
L( M1 ) = {a} L( M 2 ) = {a}
Fall 2004 COMP 335 4
5. Formal Definition of NFAs
M Q, , , q0 , F
Q : Set of states, i.e. q0 , q1, q2
: Input aphabet, i.e. a, b
: Transition function
q0 : Initial state
F : Final states
Fall 2004 COMP 335 5
11. * q0 , aa q4 , q5
q4 q5
a a
q0 a q1 b q2 q3
Fall 2004 COMP 335 11
12. * q0 , ab q2 , q3 , q0
q4 q5
a a
q0 a q1 b q2 q3
Fall 2004 COMP 335 12
13. Formally
q j * qi , w : there is a walk from qi to q j
with label w
qi w qj
w 1 2 k
1 2 k
qi qj
Fall 2004 COMP 335 13
14. 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
Fall 2004 COMP 335 14
15. F q0 ,q5
q4 q5
a a
q0 a q1 b q2 q3
* q0 , ab q2 , q3 , q0 ab LM
F
Fall 2004 COMP 335 15
16. F q0 ,q5
q4 q5
a a
q0 a q1 b q2 q3
* q0 , abaa q4 , q5 abaa L(M )
F
Fall 2004 COMP 335 16
17. F q0 ,q5
q4 q5
a a
q0 a q1 b q2 q3
* q0 , aba q1 aba LM
F
Fall 2004 COMP 335 17
18. q4 q5
a a
q0 a q1 b q2 q3
LM ab* {ab}*{aa}
Fall 2004 COMP 335 18
19. Formally
The language accepted by NFA M is:
LM w1, w2 , w3 ,...
where * (q0 , wm ) {qi , q j ,..., qk ,}
and there is some qk F (final state)
Fall 2004 COMP 335 19
20. w LM * (q0 , w)
qi
w
q0
qk qk F
w
w qj
Fall 2004 COMP 335 20
22. Equivalence of FA
Definition:
An FA M1 is equivalent to FA M2
if LM1 LM 2
that is if both accept the same language.
Fall 2004 COMP 335 22
23. Example of equivalent FA
NFA M1
LM1 {10} * 0
q0 q1
1
DFA M2 0,1
LM 2 {10}* 0
q0 q1 1 q2
1
0
Fall 2004 COMP 335 23
24. We will prove:
Languages
Regular
accepted
Languages
by NFA
Languages
accepted
by DFA
That is, NFA and DFA have
the same computation power
Fall 2004 COMP 335 24
25. Step 1
Languages
accepted Regular
Languages
by NFA
Proof: Every DFA is trivially an NFA
Any language L accepted by a DFA
is also accepted by an NFA
Fall 2004 COMP 335 25
26. Step 2
Languages
accepted Regular
Languages
by NFA
Proof: Any NFA can be converted into an
equivalent DFA
Any language accepted by an NFA
is also accepted by a DFA
Fall 2004 COMP 335 26
27. Convert NFA to DFA
NFA M
a
q a q 0
q 1 2
b
DFA M
q0
Fall 2004 COMP 335 27
28. Convert NFA to DFA
NFA M
a
q a q 0
q 1 2
b
DFA M
q0 a
q1, q2
Fall 2004 COMP 335 28
29. Convert NFA to DFA
NFA M
a
q a q 0
q 1 2
b
DFA M
q0 a
q1, q2
b
Fall 2004 COMP 335 29
30. Convert NFA to DFA
NFA M
a
q a q 0
q 1 2
b
a
DFA M
q0 a
q1, q2
b
Fall 2004 COMP 335 30
31. Convert NFA to DFA
NFA M
a
q a q 0
q 1 2
b
a
DFA M b
q0 a
q1, q2
b
Fall 2004 COMP 335 31
32. Convert NFA to DFA
NFA M
a
q a q 0
q 1 2
b
a
DFA M b
q0 a
q1, q2
b
a, b
Fall 2004 COMP 335 32
33. Convert NFA to DFA
NFA M
a
q a q 0
q 1 2
LM L(M )
b
a
DFA M b
q0 a
q1, q2
b
a, b
Fall 2004 COMP 335 33
34. NFA to DFA: Remarks
We are given an NFA M
We want to convert it
into an equivalent DFA M
That is, LM L(M )
Fall 2004 COMP 335 34
35. If the NFA has states
q0 , q1, q2 ,...
Then the DFA has states in the powerset
, q0 , q1, q1 , q2 ,....
Fall 2004 COMP 335 35
36. Procedure NFA to DFA
1. Initial state of NFA: q0
Initial state of DFA: q0
Fall 2004 COMP 335 36
37. Example
NFA M a
q0 a q1 q2
b
DFA M
q0
Fall 2004 COMP 335 37
38. Procedure NFA to DFA
2. For every DFA’s state {qi , q j ,..., qm}
Compute in the NFA
* qi , a ,
* q j , a , {qi , qj ,..., qm}
...
Add the following transition to the DFA
{qi , q j ,..., qm}, a {qi , qj ,..., qm}
Fall 2004 COMP 335 38
39. Example
NFA M a
q0 a q1 q2
b
* (q0 , a ) {q1, q2 }
DFA M
q0 a
q1, q2
q0 , a q1, q2
Fall 2004 COMP 335 39
40. Procedure NFA to DFA
Repeat step 2 for all symbols in the alphabet
∑, until no more transitions can be added.
Fall 2004 COMP 335 40
41. Example
NFA M a
q0 a q1 q2
b
a
DFA M b
q0 a
q1, q2
b
a, b
Fall 2004 COMP 335 41
42. 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
Fall 2004 COMP 335 42
43. Example
NFA M a
q0 a q1 q2 q1 F
b
a
DFA M b
q0 a
q1, q2
b q1, q2 F
a, b
Fall 2004 COMP 335 43
44. Theorem
Take NFA M
Apply the procedure to obtain DFA M
Then, M and M are equivalent:
LM LM
Fall 2004 COMP 335 44
45. Proof
LM LM
L M L M AND L M L M
Fall 2004 COMP 335 45
46. First we show: L M L M
Take arbitrary string : w L (M )
We will prove: w L(M )
Fall 2004 COMP 335 46
47. w L(M )
M: q0 w qf
w 1 2 k
1 2 k
M: q0 qf
Fall 2004 COMP 335 47
48. We will show that if w L(M )
w 1 2 k
1 2 k
M: q0 qf
1 2 k
M:
{q0} {q f ,}
w L(M )
Fall 2004 COMP 335 48
49. More generally, we will show that if in M:
(arbitrary string) v a1a2 an
a1 a2 an
M: q0 qi qj ql qm
M:
a1 a2 an
{q0} {qi ,} {q j ,} {ql ,} {qm ,}
Fall 2004 COMP 335 49
50. Proof by induction on |v|
The basis case: v a1
a1
M: q0 qi
M:
a1
{q0} {qi ,}
Fall 2004 COMP 335 50
51. Induction hypothesis: 1 | v | k
v a1a2 ak
a1 a2 ak
M: q0 qi qj qc qd
M:
a1 a2 ak
{q0} {qi ,} {q j ,} {qc ,} {qd ,}
Fall 2004 COMP 335 51
52. Induction Step: | v | k 1
v a1a2 ak ak 1 vak 1
v
a1 a2 ak
M: q0 qi qj qc qd
v
M:
a1 a2 ak
{q0} {qi ,} {q j ,} {qc ,} {qd ,}
Fall 2004
v
COMP 335 52
53. Induction Step: | v | k 1
v a1a2 ak ak 1 vak 1
v
a1 a2 ak ak 1
M: q0 qi qj qc qd qe
v
M:
a1 a2 ak ak 1
{q0} {qi ,} {q j ,} {qc ,} {qd ,} {qe ,}
Fall 2004
v
COMP 335 53
54. Therefore if w L(M )
w 1 2 k
1 2 k
M: q0 qf
1 2 k
M:
{q0} {q f ,}
w L(M )
Fall 2004 COMP 335 54
55. We have shown: L M L M
We also need to show: L M L M
(proof is similar)
Fall 2004 COMP 335 55