Lect 04
Lect 04
Finite Automata
Alphabet = {a}
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
q1 a q2 “accept”
a
q0
a
q3
a a
q1 a q2
a
q0
a
q3
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
Based on slides by Costas Busch 9
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
q1 a q2 “reject”
a
q0
a
Automaton halts
q3
a a a
q1 a q2
a
q0
a
q3
q1 a q2
a
q0 Automaton halts
a
q3 “reject”
OR
• The input cannot be consumed
Based on slides by Costas Busch 19
a is rejected by the NFA:
“reject”
q1 a q2 q1 a 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
Based on slides by Costas Busch 27
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
Based on slides by Costas Busch 33
a b
q0 a q1 b q2 q3
Based on slides by Costas Busch 34
a b
q0 a q1 b q2 q3
Based on slides by Costas Busch 35
a b
“accept”
q0 a q1 b q2 q3
Based on slides by Costas Busch 36
Another String
a b a b
q0 a q1 b q2 q3
Based on slides by Costas Busch 37
a b a b
q0 a q1 b q2 q3
Based on slides by Costas Busch 38
a b a b
q0 a q1 b q2 q3
Based on slides by Costas Busch 39
a b a b
q0 a q1 b q2 q3
Based on slides by Costas Busch 40
a b a b
q0 a q1 b q2 q3
Based on slides by Costas Busch 41
a b a b
q0 a q1 b q2 q3
Based on slides by Costas Busch 42
a b a b
“accept”
q0 a q1 b q2 q3
Based on slides by Costas Busch 43
Language accepted
q0 a q1 b q2 q3
Based on slides by Costas Busch 44
Another NFA Example
0
q0 q1 0, 1 q2
1
Based on slides by Costas Busch 45
Language accepted
0
q0 q1 0, 1 q2
1 (redundant
state)
Based on slides by Costas Busch 46
Simple Automata
M1 M2
q0 q0
L( M 1 ) = {} L( M 2 ) = { }
NFA M1 DFA M2 a
q2
q0 a q1
a
q0 a q1
L( M1 ) = {a} L( M 2 ) = {a}
Based on slides by Costas Busch 48
Formal Definition of NFAs
M = (Q, , , q0 , F )
q0 : Initial state
F: Accepting states
Based on slides by Costas Busch 49
Transition Function
q1
x resulting states reached
q x
q2 by following one transition
x
with input symbol x
qk
(q0 , 1) = q1
0
q0 q1 0, 1 q
2
1
Based on slides by Costas Busch 51
States reachable from q1 scanning 0
(q1,0) = {q0 , q2 }
0
q0 q1 0, 1 q
2
1
Based on slides by Costas Busch 52
States reachable from q0 with one transition
scanning no input symbol
(q0 , ) = {q2 }
0
q0 q1 0, 1 q
2
1
Based on slides by Costas Busch 53
States reachable from q2 scanning 1
(q2 ,1) =
0
q0 q1 0, 1 q
2
1
Based on slides by Costas Busch 54
*
Extended Transition Function
Similar with but applied on strings
(q0 , a ) = q1
*
q4 q5
a a
q0 a q1 b q2 q3
Based on slides by Costas Busch 55
States reachable from q0 scanning aa
(q0 , aa ) = q4 , q5
*
q4 q5
a a
q0 a q1 b q2 q3
Based on slides by Costas Busch 56
States reachable from q0 scanning ab
(q0 , ab ) = q2 , q3 , q0
*
q4 q5
a a
q0 a q1 b q2 q3
Based on slides by Costas Busch 57
Special case:
q (q, )
*
with label w
qi w qj
w = 1 2 k
1 2 k
qi qj
qi
wm
q0 w
qk qk F
m
wm qj
(q0 , aa ) = q4 , q5
*
aa L(M )
F
Based on slides by Costas Busch 62
F = q0 ,q5
q4 q5
a a
q0 a q1 b q2 q3
(q0 , ab ) = q2 , q3 , q0
*
ab L(M )
F
Based on slides by Costas Busch 63
F = q0 ,q5
q4 q5
a a
q0 a q1 b q2 q3
Definition:
if L( M1 ) = L( M 2 )
NFA M1
L(M1 ) = {10} * 0
q0 q1
1
DFA M2 0,1
L(M 2 ) = {10} * 0
q0 q1 1 q2
1
0
Based on slides by Costas Busch 69
Theorem:
=
Languages
Regular
accepted
Languages
by NFAs
Languages
accepted
by DFAs
Languages
accepted Regular
Languages
by NFAs
AND
Languages
accepted Regular
Languages
by NFAs
Languages
accepted Regular
Languages
by NFAs
Languages
accepted Regular
Languages
by NFAs
Any NFA can be converted to an
equivalent DFA
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
Based on slides by Costas Busch 76
(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
Based on slides by Costas Busch 77
(q1 , b ) = {q0 }
*
b q0
a
DFA M b
q0 a
q1, q2
b
Based on slides by Costas Busch 78
NFA M a
q0 a q1 q2
b
a
DFA M b
q0 a
q1, q2
b
a, b trap state
Based on slides by Costas Busch 79
END OF CONSTRUCTION
NFA M a
q0 a q1 q2 q1 F
b
a
DFA M b
q0 a
q1, q2
q1, q2 F
b
a, b
Based on slides by Costas Busch 80
General Conversion Procedure
Input: an NFA M
step
NFA M
q0 a q1 q2
b
DFA M
q0
DFA M
q0 a
q1, q2
(q0 , a ) = q1, q2
Based on slides by Costas Busch 86
step
3. Repeat Step 2 for every state in DFA and
symbols in alphabet until no more states
can be added in the DFA
a
DFA M b
q0 a
q1, q2
b
a, b
Based on slides by Costas Busch 88
step
q0 a
q1, q2
q1, q2 F
b
a, b
Based on slides by Costas Busch 90
Lemma:
If we convert NFA M to DFA M
then the two automata are equivalent:
L( M ) = L( M )
Proof:
We need to show: L( M ) L( M )
AND
L( M ) L( M )
Based on slides by Costas Busch 91
First we show: L( M ) L( M )
w L(M ) w L(M )
q0 w qf
symbols
w = a1a2 ak
a1 a2 ak q
q0 f
symbol
qi
…… ai …… q
j
w = a1a2 ar
a1 a2 ar q
NFA M: q0 f
then
a1 a2 ar
DFA M:
{q0 , } {q f ,}
state
w L(M ) state
label label
Based on slides by Costas Busch 95
More generally, we will show that if in M:
(arbitrary prefix) v = a1a2 an nr
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 ,}
a1 a2
M:
ar
DFA
{q0 , } {q f ,}
w L(M )
Based on slides by Costas Busch 100
We have shown: L( M ) L( M )
END OF PROOF
Based on slides by Costas Busch 101
Follow-Up / Further Reading
• Read Chapter 1.2 of Sipser
• Read Chapter 2.2, 2.3, 2.4, and 2.5 of
Wilson