Professional Documents
Culture Documents
Finite Automata
Alphabet = {a}
q1 a q2
a
q0
a
q3
Two choices q1 a q2
a
q0
a
q3
Two choices a
q1 q2 No transition
a
q0
a
q3 No transition
a a
q1 a q2
a
q0
a
q3
a a
q1 a q2
a
q0
a
q3
a a
All input is consumed
q1 a q2 “accept”
a
q0
a
q3
a a
q1 a q2
a
q0
a
q3
a a
Input cannot be consumed
q1 a q2
a
q0 Automaton Halts
a
q3 “reject”
“accept”
q1 a q2 q1 a q2
a a
q0 q0
a a
q3 q3 “reject”
because this
this computation
computation
is ignored
accepts aa
Fall 2006 Costas Busch - RPI 11
Rejection example
q1 a q2
a
q0
a
q3
a
“reject”
q1 a q2
a
q0
a
q3
q1 a q2
a
q0
a
q3
q1 a q2
a
q0
a
q3 “reject”
a a a
q1 a q2
a
q0
a
q3
a a a
q1 a q2
a
q0
a
q3
a a a
Input cannot be consumed
q1 a q2 “reject”
a
q0
a
Automaton halts
q3
a a a
q1 a q2
a
q0
a
q3
a a a
Input cannot be consumed
q1 a q2
a
q0 Automaton halts
a
q3 “reject”
OR
• The input cannot be consumed
Fall 2006 Costas Busch - RPI 21
a is rejected by the NFA:
“reject”
q1 a q2 a
q1 q2
a a
q0 q0
a a
q3 “reject” q3
“reject”
q1 a q2 q1 a q2
a a
q0 q0
a a
q3 q3 “reject”
q1 a q2
a
q0
a
q3
q0 a q1 q2 a q3
q0 a q1 q2 a q3
q0 a q1 q2 a q3
a a
q0 a q1 q2 a q3
a a
“accept”
q0 a q1 q2 a q3
String aa is accepted
Fall 2006 Costas Busch - RPI 29
Rejection Example
a a a
q0 a q1 q2 a q3
q0 a q1 q2 a q3
a a a
q0 a q1 q2 a q3
a a a
Automaton halts
“reject”
q0 a q1 q2 a q3
q0 a q1 q2 a q3
q0 a q1 b q2 q3
Fall 2006 Costas Busch - RPI 35
a b
q0 a q1 b q2 q3
Fall 2006 Costas Busch - RPI 36
a b
q0 a q1 b q2 q3
Fall 2006 Costas Busch - RPI 37
a b
“accept”
q0 a q1 b q2 q3
Fall 2006 Costas Busch - RPI 38
Another String
a b a b
q0 a q1 b q2 q3
Fall 2006 Costas Busch - RPI 39
a b a b
q0 a q1 b q2 q3
Fall 2006 Costas Busch - RPI 40
a b a b
q0 a q1 b q2 q3
Fall 2006 Costas Busch - RPI 41
a b a b
q0 a q1 b q2 q3
Fall 2006 Costas Busch - RPI 42
a b a b
q0 a q1 b q2 q3
Fall 2006 Costas Busch - RPI 43
a b a b
q0 a q1 b q2 q3
Fall 2006 Costas Busch - RPI 44
a b a b
“accept”
q0 a q1 b q2 q3
Fall 2006 Costas Busch - RPI 45
Language accepted
q0 a q1 b q2 q3
Fall 2006 Costas Busch - RPI 46
Another NFA Example
0
q0 q1 0, 1 q2
1
Fall 2006 Costas Busch - RPI 47
Language accepted
•Simple automata:
M1 M2
q0 q0
NFA M1 DFA M2 a
q2
q0 a q1
a
q0 a q1
L( M1 ) = {a} L( M 2 ) = {a}
Fall 2006 Costas Busch - RPI 50
Formal Definition of NFAs
M Q, , , q0 , F
q0 : Initial state
F: Accepting states
Fall 2006 Costas Busch - RPI 51
Transition Function
q , x q1, q2,, qk
q1
x resulting states with
q x
q1 following one transition
x
with symbol x
qk
Fall 2006 Costas Busch - RPI 52
q0 , 1 q1
0
q0 q1 0, 1 q
2
1
Fall 2006 Costas Busch - RPI 53
(q1,0) {q0 , q2}
0
q0 q1 0, 1 q
2
1
Fall 2006 Costas Busch - RPI 54
(q0 , ) {q2 }
0
q0 q1 0, 1 q
2
1
Fall 2006 Costas Busch - RPI 55
(q2 ,1)
0
q0 q1 0, 1 q
2
1
Fall 2006 Costas Busch - RPI 56
*
Extended Transition Function
Same with but applied on strings
q0 , a q1
*
q4 q5
a a
q0 a q1 b q2 q3
Fall 2006 Costas Busch - RPI 57
q0 , aa q4 , q5
*
q4 q5
a a
q0 a q1 b q2 q3
Fall 2006 Costas Busch - RPI 58
q0 , ab q2 , q3, q0
*
q4 q5
a a
q0 a q1 b q2 q3
Fall 2006 Costas Busch - RPI 59
Special case:
q q ,
*
with label w
qi w qj
w 1 2 k
1 2 k
qi qj
LM w1,w2,...wn
qi
wm
q0 w
qk qk F
m
wm qj
q0 , aa q4 , q5
*
aa L(M )
F
Fall 2006 Costas Busch - RPI 64
F q0 ,q5
q4 q5
a a
q0 a q1 b q2 q3
q0 , ab q2, q3, q0
*
ab LM
F
Fall 2006 Costas Busch - RPI 65
F q0 ,q5
q4 q5
a a
q0 a q1 b q2 q3
q0 , abaa q4 , q5
*
aaba L(M )
F
Fall 2006 Costas Busch - RPI 66
F q0 ,q5
q4 q5
a a
q0 a q1 b q2 q3
Definition:
if L M1 L M 2
NFA M1
LM1 {10} * 0
q0 q1
1
DFA M2 0,1
LM 2 {10} * 0
q0 q1 1 q2
1
0
Fall 2006 Costas Busch - RPI 71
Theorem:
Languages
Regular
accepted
Languages
by NFAs
Languages
accepted
by DFAs
Languages
accepted
by NFAs
Regular
Languages
AND
Languages
accepted Regular
Languages
by NFAs
Languages
accepted
by NFAs
Regular
Languages
Languages
accepted
by NFAs
Regular
Languages
DFA M
q0
DFA M
q0 a
q1,q2
NFA M a
q0 a q1 q2
b
DFA M
q0 a
q1,q2
b
trap state
Fall 2006 Costas Busch - RPI 78
(q1 , a ) {q1 , q2 }
*
NFA M a * (q2 , a )
q0 a q1 q2 union
b q1,q2
a
DFA M
q0 a
q1,q2
b
Fall 2006 Costas Busch - RPI 79
(q1 , b ) {q0 }
*
a
DFA M b
q0 a
q1,q2
b
Fall 2006 Costas Busch - RPI 80
NFA M a
q0 a q1 q2
b
a
DFA M b
q0 a
q1,q2
b
a, b trap state
Fall 2006 Costas Busch - RPI 81
END OF CONSTRUCTION
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 2006 Costas Busch - RPI 82
General Conversion Procedure
Input: an NFA M
step
1. Initial state of NFA: q0
DFA M
q0
q0 , a q1, q2
DFA M
q0 a
q1,q2
a
DFA M b
q0 a
q1,q2
b
a, b
Fall 2006 Costas Busch - RPI 90
step
4. For any DFA state {qi , q j ,..., qm }
q0 a
q1,q2
b
q1, q2 F
a, b
Fall 2006 Costas Busch - RPI 92
Lemma:
If we convert NFA M to DFA M
then the two automata are equivalent:
L M L M
Proof:
We only need to show: L M L M
AND
L M L M
Fall 2006 Costas Busch - RPI 93
First we show: L M L M
w L(M ) w L(M )
q0 w qf
symbols
w 1 2 k
1 2 k
q0 qf
symbol
i
qi qj
w 1 2 k
1 2 k
NFA M: q0 qf
then
1 2 k
DFA M:
{q0 } {q f ,}
state
w L(M ) state
label label
Fall 2006 Costas Busch - RPI 97
More generally, we will show that if in M:
(arbitrary string) v a1a2 an
a1 a2 an
NFA M: q0 qi qj ql qm
then
M:
a1 a2 an
DFA
{q0 } {qi ,} {q j ,} {ql ,} {qm ,}
Induction Basis: |v | 1 v a1
a1
NFA M: q0 qi
M:
a1
DFA
{q0 } {qi ,}
is true by construction of M
M:
a1 a2 ak
DFA
{q0 } {qi ,} {q j ,} {qc ,} {qd ,}
v
M:
a1 a2 ak ak 1
DFA
{q0 } {qi ,} {q j ,} {qc ,} {qd ,} {qe ,}
Fall 2006
v
Costas Busch - RPI 101
Therefore if w L(M )
w 1 2 k
1 2 k
q0 qf
NFA M:
then
1 2 k
DFA M:
{q0 } {q f ,}
w L(M )
Fall 2006 Costas Busch - RPI 102
We have shown: L M L M