Asimplemodelof

computation
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 2
• Deterministicfiniteautomata(DFA)
– HowaDFAworks
– HowtoconstructaDFA
• Non-deterministicfiniteautomata(NFA)
– HowanNFAworks
– HowtoconstructanNFA
• EquivalenceofDFAandNFA
• Closurepropertiesoftheclassoflanguages
acceptedbyFA
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 3
FiniteAutomata(FA)
CONTROL
UNIT
INPUT TAPE
TAPE
HEAD
Finite set of states
Move to the right one cell
at a time
Store input of the DFA
Can be of any length
Start state
Final state(s)
is in exactly one
state at a time
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 4
WhatdoesanFAdo?
• Readaninputstringfromtape
• Determineiftheinputstringisinalanguage
• Determineiftheanswerfortheproblemis
“YES”or“NO”forthegiveninputonthetape
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 5
HowdoesanFAwork?
• Atthebeginning,
– anFAisinthestartstate(initialstate)
– itstapeheadpointsatthefirstcell
• Foreachmove,FA
– readsthesymbolunderitstapehead
– changesitsstate(accordingtothetransitionfunction)to
thenextstatedeterminedbythesymbolreadfromthe
tapeanditscurrentstate
– moveitstapeheadtotherightonecell
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 6
WhendoesanFAstopworking?
• Whenitreadsallsymbolsonthetape
• Then,itgivesanansweriftheinputisinthe
specificlanguage:
– Answer“YES”ifitslaststateisafinalstate
– Answer“NO”ifitslaststateisnotafinalstate
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 7
ExampleofaDFA
q a o(q,a)
s 0 s
s 1 f
f 0 f
f 1 s
s
f
0 1
0
1
Transition diagram
Transition function
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 8
• a5-tuple(Q,E,o,s,F),where
– asetofstatesQisafiniteset
– analphabetEisafinite,non-emptyset
– astartstatesinQ
– asetoffinalstatesFcontainedinQ
– atransitionfunctionoisafunctionQ×E÷Q
• Seeformaldefinition
That’s why it’s called
a finite automaton.
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 9
HowanFAworks
s
f
0 1
0
1
Input: 001101
Input: 01001
0 0 1 1 0 1
0 1 0 0 1
ACCEPT
REJECT
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 10
Definition
LetM =(Q,E,o,s,F)beadeterministicfiniteautomaton.
AconfigurationofMisanelementofQ×E
-
configurations of M
(s, c), (s, 00),
(s, 01101), (f, c),
(f, 0011011001),
(f, 1111), (f, 011110)
s
f
0 1
0
1
Transition diagram of M
Unread input string
Current state
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 11
Definition
• LetM=(Q,E,o,s,F)beadeterministicfiniteautomaton,
and(q
0
,e
0
)and(q
1
,e
1
)betwoconfigurationsofM.
• Wesay(q
0
,e
0
)yields(q
1
,e
1
)inonestep,denotedby(q
0
,e
0
)

M
(q
1
,e
1
),ifo(q
0
, a)=q
1
,ande
0
=a e
1
,forsomea eE.
• Whenaconfigurationyieldsanotherconfiguration,thefirst
symbolofthestringisreadanddiscardedfromthe
configuration.
• Onceasymbolinaninputstringisread,itdoesnoteffect
howtheDFAworksinthefuture.
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 12
Example:yieldingnextconfiguration
(s, 001101)

M

(s, 01101)

M

(s, 1101)

M

(f, 101)

M

(s, 01)

M

(s, 1)

M

(f, c)
s
f
0 1
0
1
0 0 1 1 0 1
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 13
Yieldinzerostepormore
Definition
• LetM=(Q,E,o,s,F)beaDFA,and(q
0
,e
0
)and
(q
1
,e
1
)betwoconfigurationsofM.(q
0
,e
0
)yields
(q
1
,e
1
)inzerostepormore,denotedby(q
0
,e
0
)
(÷ *
M
(q
1
,e
1
),if
– q
0
= q
1
ande
0
=e
1
,or
– (q
0
,e
0
)(÷
M
(q
2
,e
2
)and(q
2
,e
2
)(÷*
M
(q
1
,e
1
)for
someq
2
ande
2
.
This definition is an inductive definition, and it is often
used to prove properties of DFA’s.
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 14
Example:Yieldinzerostepormore
(s, 001101)
(÷*
M

(f, 101)
(÷*
M

(s, 01)
(÷*
M

(f, c)
(÷*
M

(f, c)
s
f
0 1
0
1
(s, 01001)
(÷*
M

(f, 001)
(÷*
M

(f, 001)
(÷*
M

(f, 1)
(÷*
M

(s, c)
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 15
Definition
• LetM=(Q,E,o,s,F)beaDFA,andeeE*.
WesayMacceptseif(s, e)(÷*
M
(f, c),whenf
eF.Otherwise,wesayMrejectse.

(s, 001101)(÷*
M

(f, c) Maccepts001101
(s, 01001) (÷*
M

(s, c) Mrejects01001
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 16
LetM=(Q,E,o,s,F )beaDFA.Thelanguageacceptedby
M,denotedbyL(M )isthesetofstringsacceptedbyM.
Thatis,L(M)={eeE*|(s, e)(÷*
M
(f,c)forsomefeF }
Example:
• L(M) = {x e {0,1}* |thenumberof1’sinxisodd}.
s
f
0 1
0
1
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 17
s
0
1
1
1
1
1
1
1
0
0
0
0
0
0, 1
0
0, 1
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 18
• DeterminewhataDFAneedtomemorizeinorderto
recognizestringsinthelanguage.
– Hint:thepropertyofthestringsinthelanguage
• Determinehowmanystatesarerequiredtomemorize
whatwewant.
– finalstate(s)memorizesthepropertyofthestringsinthe
language.
• Findouthowthethingwememorizeischangedonce
thenextinputsymbolisread.
– Fromthischange,wegetthetransitionfunction.
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 19
• Consider L= {ee{0,1}*| e has both 00 and 11 as
substrings}.
• Step 1: decide what a DFA need to memorize
• Step 2: how many states do we need?
• Step 3: construct the transition diagram
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 20
s
0
1
1
1
1
1
1
1
0
0
0
0
0
0, 1
0
0, 1
Got
nothing
Got 0 as
substring
Got 00 as
substring
Got 11
and got 0
Got 00 and 11
as substrings
Got 1 as
substring
Got 11 as
substring
Got 00
and got 1
Got 11 and 00
as substrings
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 21
• Consider L= {ee{0,1}*| e represents a binary number divisible by
3}.
– L = {0, 00, 11, 000, 011, 110, 0000, 0011, 0110, 1001, 00000, ...}.
• Step 1: decide what a DFA need to memorize
– remembering that the portion of the string that has been read so far is
divisible by 3
• Step 2: how many states do we need?
– 2 states remembering that
• the string that has been read is divisible by 3
• the string that has been read is indivisible by 3.
– 3 states remembering that
• the string that has been read is divisible by 3
• the string that has been read - 1 is divisible by 3.
• the string that has been read - 2 is divisible by 3.
Choose this!!
Why?
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 22
• Reading a string w representing a number divisible
by 3.
– Next symbol is 0. w 0, which is 2*w, is also divisible by
3.
• If w=9 is divisible by 3, so is 2*w=18.
– Next symbol is 1. w 1, which is 2*w +1, may or may
not be divisible by 3.
• If 8 is indivisible by 3, so is 17.
• If 4 is indivisible by 3, but 9 is divisible.
• Using these two states is not sufficient.
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 23
• Eachstaterememberstheremainderofthe
numberdividedby3.
• Iftheportionofthestringthathasbeenreadso
far,sayw,representsthenumberwhose
remainderis0(or,1,or2),
– Ifthenextsymbolis0,whatistheremainderofw0?
– Ifthenextsymbolis1,whatistheremainderofw1?
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 24
Current
number
Current
remainder
Next
symbol
New
number
New
remainder
3n 0 0 6n 0
3n 0 1 6n+1 1
3n+1 1 0 6n+2 2
3n+1 1 1 6n+3 0
3n+2 2 0 6n+4 1
3n+2 2 1 6n+5 2
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 25
Current
number
Current
remainder
Next
symbol
New
number
New
remainder
3n 0 0 6n 0
3n 0 1 6n+1 1
3n+1 1 0 6n+2 2
3n+1 1 1 6n+3 0
3n+2 2 0 6n+4 1
3n+2 2 1 6n+5 2
Current
state
Next
state
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 26
Current
state
Next
symbol
Next
state
q
0
0 q
0
q
0
1 q
1
q
1
0 q
2
q
1
1 q
0
q
2
0 q
1
q
2
1 q
2
• M = ({q
0
, q
1
, q
2
}, {0, 1},
o, q
0
, {q
0
})
q
0
q
1
q
2
0
1
0
0
1
1
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 27
• SimilartoDFA
• Nondeterministicmove
– Onreadinganinputsymbol,theautomatoncanchooseto
makeatransitiontooneofselectedstates.

– Withoutreadinganysymbol,theautomatoncanchooseto
makeatransitiontooneofselectedstatesornot.
0
0
c
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 28
• a5-tuple(Q, E, o, s, F),where
– asetofstatesQisafiniteset
– analphabetEisafinite,non-emptyset
– astartstatesinQ
– asetoffinalstatesFcontainedinQ
– atransitionfunctionoisafunctionQ×(E{c})÷2
Q
• Seeformaldefinition
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 29
• AnNFAaccepting{we{0,1}
-
|wendswith11}
0,1
1 1
0
0 0
1
1
1
0
1
1
0
1 0
1
0
DFA
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 30
Definition
• LetM=(Q,E,o,s,F)beanon-deterministic
finiteautomaton,and(q
0
,e
0
)and(q
1
,e
1
)betwo
configurationsofM.
• Wesay(q
0
,e
0
)yields(q
1
,e
1
)inonestep,
denotedby(q
0
,e
0
)(÷
M
(q
1
,e
1
),ifq
1
e o (q
0
, a,),
ande
0
=a e
1
,forsomea e E {c}.
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 31
Definition
• LetM=(Q,E,o,s,F)beanNFA,and(q
0
,e
0
)
and(q
1
,e
1
)betwoconfigurationsofM.(q
0
,
e
0
)yields(q
1
,e
1
)inzerostepormore,
denotedby(q
0
,e
0
)(÷*
M
(q
1
,e
1
),if
– q
0
= q
1
ande
0
=e
1
,or
– (q
0
,e
0
)(÷
M
(q
2
,e
2
)and(q
2
,e
2
)(÷*
M
(q
1
,
e
1
)forsomeq
2
ande
2
.
Same as that for DFA
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 32
Definition
• LetM=(Q,E,o,s,F)beanNFA,andee
E*.WesayMacceptseif(s, e)(÷*
M
(f, c),
whenfeF.Otherwise,wesayMrejectse.
Same as the
definition for
a DFA
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 33
• LetM=(Q,E,o,s,F)beanNFA.
• ThelanguageacceptedbyM,denotedby
L(M)isthesetofstringsacceptedbyM.That
is,L(M)={eeE*|(s,e)(÷*
M
(f,c)forsome
feF}
Same as the
definition for
a DFA
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 34
(s,01111)(- (s,1111) (- (s,111)
(- (s,11) (- (s,1) (- (s,c)
(s,01111)(-(s,1111) (- (s, 111)
(- (s,11) (- (s,1) (- (q,c)
(s,01111)(-(s, 1111) (- (s, 111)
(- (s,11) (- (q,1) (- (f, c)
(s,01111)(-(s, 1111) (- (s, 111)
(- (q,11) (- (f,1)
(s,01111)(-(s, 1111) (- (q, 111)
(- (f,11)
0,1
1 1
s, 01111
s q f
s, 1111
s, 111 q, 111
s, 11
f, c
q, 1
q, 11
s, c
s, 1
q, c
f, 1
f, 11
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 35
• {w e {0,1}* | whaseither00
or11assubstring}

• {w e {0,1}* | whas00and
11assubstringsand00
comesbefore11}
0,1
0
0,1
0,1
1 1
0
c
c
0
1 1
0
c
0,1
0,1
0,1
0,1
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 36
M
d
andM
n
areequivalent÷L(M
d
) = L(M
n
).

DFAandNFAareequivalent÷
• ForanyDFAM
d
,thereexistsanNFAM
n
suchthat
M
d
andM
n
areequivalent.(part1)
• ForanyNFAM
n
,thereexistsaDFAM
d
suchthatM
d

andM
n
areequivalent.(part2)

Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 37
• ForanyDFAM
d
,thereexistsanNFAM
n
suchthat
M
d
andM
n
areequivalent.
Proof:LetM
d
beanyDFA.Wewanttoconstructan
NFAM
n
suchthatL(M
n
) = L(M
d
).
FromthedefinitionsofDFAandNFA,ifMisaDFA
thenitisalsoanNFA.
Then,weletM
n
= M
d
.
Thus,L(M
d
) = L(M
n
). 
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 38
• ForanyNFAM
n
,thereexistsaDFAM
d
suchthat
M
d
andM
n
areequivalent.
Proof:LetM
n
= (Q, E, o, s, F)beanyNFA.Wewantto
constructaDFAM
d
suchthatL(M
d
) = L(M
n
).
Firstdefinetheclosureofq,denotedbyE(q).
Second,constructaDFAM
d
=(2
Q
, E, o', E(s), F')
Finally,prove¬ eeE
-
- f e F (s,e) |-
*
Mn
(f, c) ÷
- f 'eF ' (E(s), e) |-
*
Md
(f ' , c). 
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 39
Eliminatingtransitionstomultiplestates
s q f
0,1
1 1
s s,q
1
s,q,f
1
0
0
1
0
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 40
Eliminatingempty-stringtransitions
s p q
r f
0
0
0
ε
,1
1
1 1
ε
ε
s p,q, r
r p,q,r,f
0
0,1
1
1
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 41
• LetM = (Q, E, o, s, F)beanNFA,andqeQ.
• Theclosureofq,denotedbyE(q),is
– thesetofstateswhichcanbereachedfromq
withoutreadinganysymbol.
– {peQ| (q, c) |-
M
*
(p, c)}
• IfanNFAisinastateq,itcanalsobeinany
stateintheclosureofqwithoutreadingany
inputsymbol.
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 42
s q f
a b c
c c
M=({s, q, f}, {a, b, c}, o, s, {f})
where o is defined below.
L(M)={a
i
b
j
c
k
| i, j, k > 0}
state closure
s q f s, q, f
q f q, f
f f
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 43
q
0
q
1
q
2
q
3
q
4
1 q
1
q
2
, q
3
q
3

2 q
2
, q
3
3
q (q,a,r) (q,b,r) (q,c,r)
q
0
q
2
q
1
q
1
q
0
,q
4
q
2
,

q
3
q
2
q
4
q
3
q
4
q
4
q
3
q
0
q
1
q
2
q
3
q
4
b
c
c
c
a
b
c
a
a
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 44
LetM
n
= (Q, E, o, s, F)beanyNFA.Weconstructa
DFAM
d
=(2
Q
, E, o', E(s), F'),where:
– o'(q',a) =

{reE(p)| p e o(q,a) }and
– F' = {f _ Q | f · F = C})
qeq'
q
p r
a
a
ε
ε
ε
DFA
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 45
E(q
0
)

E(q
1
) E(q
2
) E(q
3
) E(q
4
)
q
0
, q
1
,
q
2
, q
3

q
1
, q
2
,
q
3

q
2
q
3
q
3
,q
4
q
0
q
1
q
2
q
3
q
4
b
c
c
c
a
b
c
a
a
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 46
q
0
,q
1
,q
2
,q
3
q
0
,q
1
,q
2
,q
3
,q
4
q
2
,q
3
,q
4
q
3
,q
4

C
a
b
b
a
a
b
b
a
a,b
E(q
0
)

E(q
1
) E(q
2
)E(q
3
) E(q
4
)
q
0
, q
1
,
q
2
, q
3

q
1
,
q
2
, q
3

q
2
q
3
q
3
,q
4
o (q,a,r) (q,b,r) (q,c,r)
q
0
q
2
q
1
q
1
q
0
q
4
q
2
q
3
q
2
q
4
q
3
q
4
q
4
q
3
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 47
LetM
n
= (Q, E, o, s, F)beanyNFA,andM
d
= (2
Q
, E, o',
E(s), F')beaDFA,where
– o'(q', a) = {reE(p)| peo(q,a)}and
– F' = {f _ Q | f · F = C}
Prove¬ eeE
-
, - feF (s,e) |-
*
Mn
(f, c) ÷ - f 'eF ' (E(s), e)
|-
*
Md
(f', c)andfef'byinduction.
Proveamoregeneralstatement¬ eeE
-
, ¬ p, qeQ
(p,e) |-
*
Mn
(q, c) ÷ (E(p), e) |-
*
Md
(q', c) and qeq'.
qeq'
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 48
PartI:
ForanystringeinΣ*,andstatesqandrinQ,
thereexistsR _ Qsuchthat
(q, e) ,÷*
Mn
(r, ε) ÷ (E(q), e) ,÷*
Md
(R, ε)and
reR.
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 49
Basis:
LetebeastringinΣ*,qandrbestatesinQ,and(q, e)
,÷*
Mn
(r, ε)in0step.
Because(q, e) ,÷*
Mn
(r, ε)in0step,weknow(1)q=r,
and(2)e=ε.
Then,(E(q), e) = (E(r), ε).
Thus,(E(q), e) ,÷*
Md
(E(r), ε).
Thatis,thereexistsR=E(r)suchthatr e Rand(E(q),e)
,÷*
Md
(R, ε).
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 50
Inductionhypothesis:
Foranynon-negativeintegerk,stringeinΣ*,and
statesq andrinQ,thereexistsR _ Q:
(q, e) ,÷*
Mn
(r, ε)inksteps->(E(q), e) ,÷*
Md
(R, ε)and
reR.
Inductionstep:
Prove,foranynon-negativeintegerk,stringeinΣ*,
andstatesqandrinQ,thereexistsR _ Q:
(q, e) ,÷*
Mn
(r, ε)ink+1steps->(E(q), e) ,÷*
Md
(R, ε)
andreR.
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 51
LetebeastringinΣ*,qandrbestatesinQ,
and(q, e) ,÷*
Mn
(r, ε)ink+1steps.

Because(q, e) ,÷*
Mn
(r, ε)ink+1stepsandk>0,
thereexistsastatepinQandastringoeΣ*
suchthat(q, e) ,÷*
Mn
(p, a)inkstepsand(p, a)

Mn
(r, ε)forsomea eΣ{ε}.
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 52
Fromtheinductionhypothesisand(q, e) ,÷*
Mn
(p, a)in
ksteps,weknowthatthereexistsP_Qsuchthat
(E(q), e) ,÷*
Md
(P, a) and peP.
Since(p, a) ,÷
Mn
(r, ε), reo(p, a).
Fromthedefinitionofo'ofM
d
, E(o(p, a)) _ o'(P, a)
becausepeP.
Becausereo(p, a)andE(o(p, a)) _ o'(P, a), reo'(P, a).
Then,forR=o'(P, a),(P, a) ,÷*
Md
(R, ε) and reR.
Thus,(E(q), e) ,÷*
Md
(P, a) ,÷*
Md
(R, ε) and reR.
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 53
Part II:
For any string e in Σ*, and states q and r in Q, there exists R _ Q
such that reR and
(E(q), e) ,÷*
Md
(R, ε) -> (q, e) ,÷*
Mn
(r, ε).
E(q)
R
q
r
reR
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 54
Basis:
LetebeastringinΣ*,qandrbestatesinQ, Rbea
subsetofQsuchthatr e Rand(E(q), e) ,÷*
Md
(R, ε)
in0step.
Because(E(q),e) ,÷*
Md
(R, ε)in0step,E(q)=Rande=ε.
FromthedefinitionofE, o'(q, ε)=RbecauseE(q)=R.
Then,foranyreR, (q, e) ,÷*
Mn
(r, ε).
Thatis,thereexistsR=E(q)suchthatr e Rand(q, e)
,÷*
Mn
(r, ε).
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 55
Inductionhypothesis:
Foranynon-negativeintegerk,stringeinΣ*,andstatesq
andrinQ,thereexistsR _ QsuchthatreRand:
(E(q), e) ,÷*
Md
(R, ε)ink steps->(q, e) ,÷*
Mn
(r, ε).
Inductionstep:
Prove,foranynon-negativeintegerk,stringeinΣ*,and
statesqandrinQ,thereexistsR _ QsuchthatreR:
(E(q),e),÷*
Md
(R, ε)ink+1steps->(q, e) ,÷*
Mn
(r, ε).
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 56
LetebeastringinΣ*,qandrbestatesinQ,and(E(q), e) ,÷*
Md

(R, ε)ink+1steps.
Because(E(q), e) ,÷*
Md
(R, ε)ink+1stepsandk>0,thereexists
Pe2
Q
(i.e.P_Q)andastringoeΣ*suchthate=oa,(E(q), o)
,÷*
Md
(P,ε)inkstepsand(P, a) ,÷
Md
(R, ε)forsomeaeΣ.
E(q)
R
q
r
reR
P
k+1 steps
a
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 57
Fromtheinductionhypothesisand(E(q), o) ,÷*
Md
(P, ε)ink
steps,weknowthatthereexistspePsuchthat(q, o),÷
*
Mn
(p,ε)
(i.e. (q, oa) ,÷*
Mn
(p, a) ).
Since(P, a) ,÷
Md
(R, ε),thereexistsreRsuchthatr= o(p, a).
Then,forsomereR,(p, a) ,÷*
Mn
(r, ε).
Thus,(q, e) ,÷*
Mn
(p, a) ,÷*
Mn
(r, ε)forsomereR.
E(q)
R
q
r reR
P
p
peP
k+1 steps
a
a
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 58
ClosureProperties
• TheclassoflanguagesacceptedbyFA’sis
closedundertheoperations
– Union
– Concatenation
– Complementation
– Kleene’sstar
– Intersection

Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 59
Theclassoflanguagesaccepted
byFAisclosedunderunion.
Proof:
LetM
A
= (Q
A
, Σ, o
A
, s
A
, F
A
)and
M
B
= (Q
B
, Σ, o
B
, s
B
, F
B
)beanyFA.
WeconstructanNFAM =
(Q, Σ, o, s, F)suchthat
– Q = Q
A

Q
B
{s}
– o = o
A

o
A
{(s, ε, {s
A
, s
B
})}
– F = F
A
F
B

s
A

s
B

WeprovethatL(M) = L(M
A
)L(M
B
).
s
ε
ε
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 60
ToproveL(M) = L(M
A
) L(M
B
),weprove:
I. ForanystringeeΣ*eeL(M
A
) or eeL(M
B
) ÷ eeL(M)&
II. ForanystringeeΣ*eeL(M
A
) and eeL(M
B
). ÷ eeL(M)
ForI,consider(a)eeL(M
A
)or(b)eeL(M
B
).
For(a),leteeL(M
A
).
FromthedefinitionofstringsacceptedbyanFA,thereisa
statef
A
inF
A
suchthat(s
A
,e)|-*
MA
(f
A
,ε).
Becauseo
A
co,(s
A
, e) |-*
M
(f
A
, ε) also.
Becauses
A
eo(s,ε), (s, e) |-
M
(s
A
, e).
Thus,(s, e) |-
M
(s
A
, e) |-*
M
(f
A
, ε).
Becausef
A
e F, eeL(M).
Similarlyfor(b).
s
s
A

s
B

ε
ε
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 61
For(II),leteeL(M
A
)L(M
B
).
Because(s, ε, {s
A
, s
B
})eo,either(s,e) |-
M
(s
A
,e)or(s, e) |-
M
(s
B
, e)only.
BecauseeeL(M
A
),thereexistsnof
A
inF
A
suchthat(s
A
,e) |-*
MA
(f
A
,ε).
BecauseeeL(M
B
),thereexistsnof
B
inF
B
suchthat(s
B
, e) |-*
MB
(f
B
, ε).
SincethereisnotransitionbetweenstatesinQ
A
andQ
B
inM,there
existsnostatefinF=F
A
F
B
suchthat(s, e) |-
M
(s
A
, e) |-*
M
(f
A
, ε)
or(s, e) |-
M
(s
B
, e) |-*
M
(f
B
, ε).
Thatis,eeL(M).
Thus,L(M) = L(M
A
)L(M
B
).
s
s
A

s
B

ε
ε
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 62
ε
ε
ε
s
A

M
A
s
B

M
B
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 63
s
A

M
A
DFA only
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 64

s
A
f
A
s

f

c c
c
c
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 65
TheclassoflanguagesacceptedbyFAisclosedunderintersection.
Proof:LetL
1
andL
2
belanguagesacceptedbyFA.
L
1
·L
2
=(L
1
L
2
)
Bytheclosurepropertyundercomplementation,thereareFA
acceptingL
1
andL
2
.
Bytheclosurepropertyunderunion,thereisanFAacceptingL
1

L
2
.
Bytheclosurepropertyundercomplementation,thereisanFA
accepting(L
1
L
2
).
Thus,theclassoflanguagesacceptedbyFAisclosedunder
intersection.
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 66
DFAacceptingtheintersectionoftwo
languages
LetM
A
= (Q
A
, Σ, o
A
, s
A
, F
A
)and
M
B
= (Q
B
, Σ, o
B
, s
B
, F
B
)beanyFA.
WeconstructanNFAM = (Q, Σ, o, s, F)such
that
– Q = Q
A
× Q
B

– o = o
A
×

o
A
(i.e.o((q
A
,q
B
),a) = o
A
(q
A
,a)×o
B
(q
B
,a))
– s = (s
A
, s
B
)
– F = F
A
× F
B

Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 67
q
0
q
1
q
2
0
1
0
0
1
1
0,1
1 1
p
0
p
1
p
2
p
0
,q
1
p
0
,q
0
p
0
,q
2
0
1
0
0
1
1
p
1
,q
1
1
p
1
,q
0
1
p
1
,q
2
1
p
2
,q
0
1
p
2
,q
1
1
p
2
,q
2
1
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 68
Basic
 ExplainhowDFA/NFAwork
(configuration,yieldnext
configuration)
 Findthelanguageacceptedby
DFA/NFA
 ConstructDFA/NFAacceptinga
givenlanguage
 Findclosureofastate
 ConvertanNFAintoaDFA
 ProvealanguageacceptedbyFA
 ConstructFAfromotherFA’s
Advanced
 ProveDFA/NFAacceptinga
language
 ProvepropertiesofDFA/NFA
 Configurationchange
 Undersomemodification
 etc.
 Provesomepropertiesof
languagesacceptedby
DFA/NFA
 Undersomemodification
 Surprise!

Outline
• Deterministic finite automata (DFA)
– How a DFA works
– How to construct a DFA

• Non-deterministic finite automata (NFA)
– How an NFA works
– How to construct an NFA

• Equivalence of DFA and NFA • Closure properties of the class of languages accepted by FA
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 2

Finite Automata (FA)
Finite set of states is in exactly one state at a time Start state Final state(s)
TAPE HEAD
Move to the right one cell at a time

CONTROL UNIT

INPUT TAPE
Store input of the DFA Can be of any length
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata

3

What does an FA do? • Read an input string from tape • Determine if the input string is in a language • Determine if the answer for the problem is “YES” or “NO” for the given input on the tape Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 4 .

How does an FA work? • At the beginning. FA – reads the symbol under its tape head – changes its state (according to the transition function) to the next state determined by the symbol read from the tape and its current state – move its tape head to the right one cell Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 5 . – an FA is in the start state (initial state) – its tape head points at the first cell • For each move.

it gives an answer if the input is in the specific language: – Answer “YES” if its last state is a final state – Answer “NO” if its last state is not a final state Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 6 .When does an FA stop working? • When it reads all symbols on the tape • Then.

a) 0 1 0 s s f f 0 1 0 1 2301379 s f f s s 1 f Transition diagram Transition function Jaruloj Chongstitvatana Chapter 2 Finite Automata 7 .Example of a DFA q a (q.

s. – an alphabet  is a finite. . where That’s why it’s called – a set of states Q is a finite set – a start state s in Q – a set of final states F contained in Q – a transition function  is a function Q    Q a finite automaton. non-empty set • See formal definition Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 8 . F).How to define a DFA • a 5-tuple (Q. .

How an FA works 0 1 0 s 1 Input: 001101 f 0 0 1 1 0 1 Input: 01001 ACCEPT 0 1 0 0 1 2301379 REJECT Jaruloj Chongstitvatana Chapter 2 Finite Automata 9 .

1111). F ) be a deterministic finite automaton.Configurations Definition Let M =(Q. ). ). s. (f. (s. (f. (f. . 01101). A configuration of M is an element of Q   Current state Unread input string 0 1 0 configurations of M (s. 00). (s. 0011011001). . 011110) Jaruloj Chongstitvatana 2301379 s 1 f Transition diagram of M Chapter 2 Finite Automata 10 . (f.

0) yields (q1. and (q0. and 0=a 1. the first symbol of the string is read and discarded from the configuration. 1). 0) and (q1. it does not effect how the DFA works in the future. 1) be two configurations of M. F ) be a deterministic finite automaton.Yielding next configuration Definition • Let M = (Q. Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 11 . • When a configuration yields another configuration. 1) in one step. a) = q1. if (q0. denoted by (q0. s. • We say (q0. for some a . . • Once a symbol in an input string is read. . 0) M (q1.

) 001101 Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 12 . 101) M (s. 01101) M (s. 001101) M (s. 1101) M (f. 1) M (f. 01) M (s.Example: yielding next configuration 0 1 0 s 1 f (s.

Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 13 . s. 1). 2) and (q2. denoted by (q0. 2) *M (q1. 0) *M (q1. if – q0= q1 and 0 = 1. F) be a DFA. (q0. 1) for some q2 and 2. 0) and (q1. . 0) yields (q1. or – (q0. and (q0. and it is often used to prove properties of DFA’s. This definition is an inductive definition. .Yield in zero step or more Definition • Let M = (Q. 1) be two configurations of M. 1) in zero step or more. 0) M (q2.

001101) *M (f.Example: Yield in zero step or more 0 1 0 s 1 (s. ) Jaruloj Chongstitvatana . 01) *M (f. ) 2301379 Chapter 2 Finite Automata 14 *M (f. 001) *M (f. 001) *M (f. ) f (s. 01001) *M (f. 1) *M (s. 101) *M (s.

when f  F. )  M accepts 001101 (s. and   *. (s. F) be a DFA. ) *M (f.Accepting a string Definition • Let M = (Q. we say M rejects . )  M rejects 01001 Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 15 . ). 01001) *M (s. . We say M accepts  if (s. . s. 001101) *M (f. Otherwise.

denoted by L(M ) is the set of strings accepted by M.Language accepted by a DFA Let M = (Q. 0 1 0 s 1 Jaruloj Chongstitvatana 2301379 f Chapter 2 Finite Automata 16 . ) for some f  F } Example: • L(M) = {x  {0. L(M) = {*|(s. That is. The language accepted by M. ) *M (f. s. F ) be a DFA. . .1}* | the number of 1’s in x is odd}.

1 Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 17 . 1 s 1 0 1 1 1 1 0 0 0.Example 0 0 0 1 1 0 0.

we get the transition function. – From this change. • Find out how the thing we memorize is changed once the next input symbol is read. – final state(s) memorizes the property of the strings in the language. Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 18 . – Hint: the property of the strings in the language • Determine how many states are required to memorize what we want.How to construct a DFA • Determine what a DFA need to memorize in order to recognize strings in the language.

Step 1: decide what a DFA need to memorize Step 2: how many states do we need? • Step 3: construct the transition diagram Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 19 .1}*| has both 00 and 11 as substrings}.Constructing a DFA: Example • • • Consider L= {{0.

Example Got 00 as substring Got 0 as substring 0 0 0 1 1 Got 00 and got 1 0 0. 1 Got 00 and 11 as substrings s Got nothing Got 1 as substring 1 0 1 1 1 1 0 Got 11 and got 0 Chapter 2 Finite Automata 0. 1 0 Got 11 and 00 as substrings 20 Got 11 as substring 2301379 Jaruloj Chongstitvatana .

. 110. 011. • Step 1: decide what a DFA need to memorize – • Step 2: how many states do we need? – Choose this!! Why? – 3 states remembering that • the string that has been read is divisible by 3 • the string that has been read .}. 11.Constructing a DFA: Example • Consider L= {{0. 00.1 is divisible by 3.2 is divisible by 3. 0110. 00000. 1001. . 0011. 0000. – L = {0. remembering that the portion of the string that has been read so far is divisible by 3 2 states remembering that • the string that has been read is divisible by 3 • the string that has been read is indivisible by 3. Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 21 .1}*|  represents a binary number divisible by 3}. • the string that has been read . 000..

so is 17. – Next symbol is 1. which is 2*w +1. • If w=9 is divisible by 3. but 9 is divisible. so is 2*w=18.Using 2 states • Reading a string w representing a number divisible by 3. • If 4 is indivisible by 3. is also divisible by 3. which is 2*w. w 1. may or may not be divisible by 3. 2301379 Chapter 2 Finite Automata 22 Jaruloj Chongstitvatana . – Next symbol is 0. • Using these two states is not sufficient. w 0. • If 8 is indivisible by 3.

If the portion of the string that has been read so far. what is the remainder of w 1? Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 23 . 1.Using 3 states • • Each state remembers the remainder of the number divided by 3. represents the number whose remainder is 0 (or. what is the remainder of w 0? – If the next symbol is 1. say w. or 2). – If the next symbol is 0.

How remainder changes Current number 3n 3n 3n+1 3n+1 Current remainder 0 0 1 1 Next symbol 0 1 0 1 New number 6n 6n+1 6n+2 6n+3 New remainder 0 1 2 0 3n+2 3n+2 2 2 0 1 6n+4 6n+5 1 2 Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 24 .

Transition table Current number 3n 3n 3n+1 3n+1 Current Current state remainder 0 0 1 1 Next symbol 0 1 0 1 New number 6n 6n+1 6n+2 6n+3 New Next state remainder 0 1 2 0 3n+2 3n+2 2 2 0 1 6n+4 6n+5 1 2 Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 25 .

q2}. . {q0}) 0 q0 q1 q1 q2 q2 1 0 1 0 1 2301379 q1 q2 q0 q1 q2 q0 1 1 1 0 q1 0 q2 Jaruloj Chongstitvatana Chapter 2 Finite Automata 26 . q0. 1}.Example DFA Current state Next symbol 0 Next state q0 q0 • M = ({q0. q1. {0.

0 0 – Without reading any symbol. the automaton can choose to make a transition to one of selected states or not.Nondeterministic Finite Automata • Similar to DFA • Nondeterministic move – On reading an input symbol. the automaton can choose to make a transition to one of selected states.  Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 27 .

. .How to define an NFA • a 5-tuple (Q. where – a set of states Q is a finite set – an alphabet  is a finite. non-empty set – a start state s in Q – a set of final states F contained in Q – a transition function  is a function Q({})2Q • See formal definition Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 28 . F). s.

Example of NFA • An NFA accepting {w{0.1 1 Jaruloj Chongstitvatana 2301379 DFA 1 0 0 1 1 0 1 1 1 Chapter 2 Finite Automata 29 .1} |w ends with 11} 0 1 0 1 0 0 0.

. and (q0. . 0) and (q1. a. F) be a non-deterministic finite automaton. if q1  (q0. s. and 0=a 1. 0) M (q1. 1) in one step.Yielding next configuration Definition • Let M = (Q.). denoted by (q0. 1) be two configurations of M. Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 30 . 0) yields (q1. • We say (q0. for some a   {}. 1).

1) be two configurations of M. 1) in zero step or more. . 0) yields (q1. 2) *M (q1. F) be an NFA. denoted by (q0. 0) *M (q1. 2) and (q2. 0) M (q2. if – q0= q1 and 0 = 1. 1) for some q2 and 2. (q0. and (q0. . 0) and (q1.Yield in zero step or more Definition • Let M = (Q. Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 31 . or Same as that for DFA – (q0. 1). s.

. We say M accepts  if (s. we say M rejects . . ). F) be an NFA. when f  F. ) *M (f. and   *. Same as the definition for a DFA Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 32 . s.Accepting a string Definition • Let M = (Q. Otherwise.

) for some fF} Same as the definition for a DFA Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 33 . • The language accepted by M.) *M (f. F) be an NFA. L(M) = {*| (s. .Language accepted by an NFA • Let M = (Q. s. That is. denoted by L(M) is the set of strings accepted by M. .

) (s.(f.(s.(q. 1111) .(f.(s. 11 s.(s.01111) .01111) .  Chapter 2 Finite Automata 34 . 1111 s.11) .(s. 1 f.1 s 1 q 1 f s.1) . 1 s.11) Jaruloj Chongstitvatana 2301379 0.11) .(s. 11 f.1) (s.(s.(q.(s.(s.(s.1) .(s.(f. 1 q.) (s.01111) . 11 q.01111) .(s. 1111) . 111) .11) .111) .(s.01111) . ) (s.1111) .(s.How NFA’s work (s. 111 s.(s.(q. 111) .11) .1) . 1111) . 111 q. 111) . 111) .  f.  q.1111) . 01111 s.(q.(s.

1}* | w has either 00 or 11 as substring}  1 1 0.1 0 0.1  0 0 0.Other examples of NFA 0.1 0 0.1 Jaruloj Chongstitvatana 2301379 0.1  1 1 • {w  {0.1 • {w  {0.1 Chapter 2 Finite Automata 35 .1}* | w has 00 and 11 as substrings and 00 comes before 11} 0.

(part 1) • For any NFA Mn.DFA and NFA are equivalent Md and Mn are equivalent  L(Md) = L(Mn). (part 2) Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 36 . there exists an NFA Mn such that Md and Mn are equivalent. there exists a DFA Md such that Md and Mn are equivalent. DFA and NFA are equivalent  • For any DFA Md.

Thus. From the definitions of DFA and NFA. Jaruloj Chongstitvatana 2301379  Chapter 2 Finite Automata 37 .Part 1 of the equivalence proof • For any DFA Md. Proof: Let Md be any DFA. L(Md) = L(Mn). We want to construct an NFA Mn such that L(Mn) = L(Md). there exists an NFA Mn such that Md and Mn are equivalent. Then. if M is a DFA then it is also an NFA. we let Mn = Md.

 Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 38 . prove    f  F (s.Part 2 of the equivalence proof • For any NFA Mn. E(s). '. Second. denoted by E(q).) |-*Mn (f. construct a DFA Md=(2Q. ) |-*Md (f ' . there exists a DFA Md such that Md and Mn are equivalent. First define the closure of q. F) be any NFA. . )   f 'F ' (E(s). Proof: Let Mn = (Q. . F') Finally. . ). We want to construct a DFA Md such that L(Md) = L(Mn). s.

q.Eliminating transitions to multiple states s 0.1 1 q 1 f 0 1 s 0 1 s.q 0 1 s.f Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 39 .

q.Eliminating empty-string transitions s 1 0 p ε r s ε q 0 1 ε 1 f 1 0 p. r 0 .1 0.1 r Jaruloj Chongstitvatana 2301379 1 p.f 40 Chapter 2 Finite Automata .q.r.

) |-M* (p.Closure of state q • Let M = (Q. )} • If an NFA is in a state q. – {pQ| (q. F) be an NFA. • The closure of q. and qQ. . it can also be in any state in the closure of q without reading any input symbol. denoted by E(q). is – the set of states which can be reached from q without reading any symbol. Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 41 . s. .

Example of closure M=({s. b. f}. f q f f q. {a. j. s. k  0} Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 42 . {f}) where  is defined below. q. . q. f f s q f L(M)={ai bj ck | i. a b  c  state s q f closure s. c}.

r) (q. q3 q3   a a  2 q2 .r) q2 q4 q1 q2.Another example of closure q0 a q1  q3 q0 q1 q2 q3 q4 1 q1 b q2 ..r) (q.b. q3 3 q q0 q1 q0 .a.q4 q2 q3 q4 q4 q3 43 q2 b q4 (q. q3 Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata .

'. where : – '(q'. We construct a DFA Md =(2Q. .Constructing the equivalent DFA Let Mn = (Q. E(s). s. F) be any NFA. . .a) } and qq' – F' = {f  Q | f  F  }) a q p ε ε r DFA a ε Chapter 2 Finite Automata 44 Jaruloj Chongstitvatana 2301379 .a) =  {rE(p)| p  (q. F').

q3 q1.Example of DFA construction q0 a q1  q3   a a  b q2 b q4 E(q0) E(q1) E(q2) E(q3) E(q4) q0. q2 q3 q3 q3. q2.q4 Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 45 . q2. q1.

.q3 a q0.q4 b a q0.Example of DFA construction E(q0) E(q1) E(q2) E(q3) E(q4) q0.b q3.r) q2 q4 q1 q2 q3 q4 q3 2301379 b  Chapter 2 Finite Automata 46 .b.a.q4 b a q2.q3. q1.q2. q3  q0 q1 q2 q3 q4 Jaruloj Chongstitvatana q3 q3. q2 q2.r) q0 q4 (q. q1.q1.q3.q4 (q.q1.q2.r) (q.q4 a b a. q3 q2.

'. s. Prove a more general statement  . . )   f 'F ' (E(s). F') be a DFA. ) and qq'. F) be any NFA. E(s).Prove property of  and ' Let Mn = (Q. ) |-*Md (f'.) |-*Mn (q. and Md = (2Q.a)} and qq' – F' = {f  Q | f  F  } Prove  . . ) |-*Md (q'.  p. Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 47 . )  (E(p).  fF (s. a) =  {rE(p)| p(q. where – '(q'. ) and ff' by induction. qQ (p.) |-*Mn (f. .

) *Mn (r. ) *Md (R. and states q and r in Q. ε)  (E(q). ε) and rR. Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 48 .Proof Part I: For any string  in Σ*. there exists R  Q such that (q.

Then. ε) . ) = (E(r). ) *Mn (r. ε). ε) in 0 step. (E(q). and (q.Proof Basis: Let  be a string in Σ*. (E(q). ε). That is. and (2) = ε. Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 49 . Thus. ε) in 0 step. Because (q. ) *Md (E(r). we know (1) q=r . q and r be states in Q. there exists R=E(r) such that r  R and (E(q). ) *Mn (r.) *Md (R.

) *Md (R. ε) and rR. and states q and r in Q. string  in Σ*. ε) and rR. ) *Md (R. there exists R  Q: (q. for any non-negative integer k. Induction step: Prove. and states q and r in Q. ) *Mn (r. string  in Σ*. ε) in k steps -> (E(q). ε) in k+1 steps -> (E(q). Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 50 . there exists R  Q: (q.Proof Induction hypothesis: For any non-negative integer k. ) *Mn (r.

and (q. ) *Mn (r. ) *Mn (r.Proof Let  be a string in Σ*. a) in k steps and (p. a) Mn (r. ε) in k+1 steps and k0. q and r be states in Q. Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 51 . ε) in k+1 steps. there exists a state p in Q and a string Σ* such that (q. ε) for some a Σ{ε}. ) *Mn (p. Because (q.

a) Mn (r. a) *Md (R. r(p. a). E((p. r(P. a). a) and pP. ε) and rR. a))  (P. we know that there exists PQ such that (E(q). Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 52 . From the definition of  of Md. Then. ) *Md (P. ) *Md (P. Since (p. ) *Mn (p. ε) and rR. Because r(p. a) in k steps. for R=(P. a). Thus. a))  (P. a) *Md (R. a) and E((p.Proof From the induction hypothesis and (q. a) because pP. (E(q). (P. a). ε).

there exists R  Q such that rR and (E(q). ) *Mn (r. ε). ε) -> (q.Proof Part II: For any string  in Σ*. E(q) R rR q r Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 53 . and states q and r in Q. ) *Md (R.

Proof
Basis:

Let  be a string in Σ*, q and r be states in Q, R be a subset of Q such that r  R and (E(q), ) *Md (R, ε) in 0 step. Because (E(q),) *Md (R, ε) in 0 step, E(q)=R and =ε.
From the definition of E, (q, ε)=R because E(q)=R. Then, for any rR, (q, ) *Mn (r, ε). That is, there exists R=E(q) such that r  R and (q, ) *Mn (r, ε).
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 54

Proof
Induction hypothesis:

For any non-negative integer k, string  in Σ*, and states q and r in Q, there exists R  Q such that rR and:
(E(q), ) *Md(R, ε) in k steps ->(q, ) *Mn(r, ε).

Induction step:
Prove, for any non-negative integer k, string  in Σ*, and states q and r in Q, there exists R  Q such that rR:

(E(q),)*Md(R, ε) in k+1 steps ->(q, ) *Mn(r, ε).

Jaruloj Chongstitvatana

2301379

Chapter 2 Finite Automata

55

Proof
Let  be a string in Σ*, q and r be states in Q, and (E(q), ) *Md (R, ε) in k+1 steps. Because (E(q), ) *Md (R, ε) in k+1 steps and k0, there exists P2Q (i.e. PQ) and a string Σ* such that =a, (E(q), ) *Md (P,ε) in k steps and (P, a) Md (R, ε) for some aΣ.

E(q)

P

a

R

k+1 steps

q
Jaruloj Chongstitvatana 2301379

r
Chapter 2 Finite Automata

rR
56

Thus. a).ε) (i.Proof From the induction hypothesis and (E(q). a) *Mn (p. ε) for some rR. (p. ε) in k steps. )*Mn(p. ε). (q. a) *Mn (r. a) ). a) *Mn (r. there exists rR such that r= (p. Since (P. ) *Md (P. for some rR. we know that there exists pP such that (q.e. Then. ) *Mn (p. E(q) q Jaruloj Chongstitvatana 2301379 P a R r k+1 steps pP a p rR 57 Chapter 2 Finite Automata . a) Md (R. ε). (q.

Closure Properties • The class of languages accepted by FA’s is closed under the operations – Union – Concatenation – Complementation – Kleene’s star – Intersection Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 58 .

Closure Property under Union The class of languages accepted by FA is closed under union. FA) and ε MB = (QB. sA. FB) be any FA. F) such that sB – Q = QA  QB  {s} –  = A  A  {(s. Proof: sA Let MA = (QA. {sA. s. . sB. Σ. Σ. B. s We construct an NFA M = ε (Q. Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 59 . sB})} – F = F A  FB We prove that L(M) = L(MA)L(MB). A. Σ. ε.

(s. ). (s. ε). ) |-M (sA. ε sB Similarly for (b). s Because fA F.  L(M) For I. L(M). From the definition of strings accepted by an FA. there is a state fA in FA such that (sA. For any string Σ* L(MA) and L(MB). consider (a) L(MA) or (b) L(MB).ε). For (a). Because A. (sA. ε). ε) also. ) |-*MA (fA. let L(MA). sA Because sA(s. For any string Σ* L(MA) or L(MB)  L(M) & II. ) |-*M (fA. Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 60 .Proof To prove L(M) = L(MA) L(MB). ) |-M (sA. ε Thus. we prove: I. ) |-*M (fA.

) |-M (sB. L(M) = L(MA)L(MB).) |-M (sA. Because L(MB). ) |-*M (fA. ) |-*M (fB. ) |-M (sB.Proof For (II). L(M). sB}). ) |-M (sA. there exists no fB in FB such that (sB. ) |-*MB (fB. either (s. there exists no fA in FA such that (sA. ε). Because (s. {sA.ε).) |-*MA (fA. That is.) or (s. ε. ) only. there exists no state f in F=FAFB such that (s. ε s sA ε sB Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 61 . ε). ε) or (s. let L(MA)L(MB). Since there is no transition between states in QA and QB in M. Because L(MA). Thus.

Closure under concatenation ε sA MA ε ε sB MB Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 62 .

Closure under complementation sA MA DFA only Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 63 .

Closure under Kleene’s star  s  sA fA  f  Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 64 .

the class of languages accepted by FA is closed under intersection. L1  L2 = (L1 L2) By the closure property under complementation. there is an FA acceptingL1 L2. By the closure property under complementation. Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 65 . there is an FA accepting(L1 L2). there are FA acceptingL1 andL2.Closure under intersection The class of languages accepted by FA is closed under intersection. Thus. Proof: Let L1 and L2 be languages accepted by FA. By the closure property under union.

sA. B. Σ.DFA accepting the intersection of two languages Let MA = (QA. Σ.e.a)) – s = (sA.a)B(qB. FA) and MB = (QB.a) = A(qA. ((qA. F) such that – Q = Q A  QB –  = A  A (i. We construct an NFA M = (Q. FB) be any FA. s.qB). . Σ. sB) – F = F A  FB Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 66 . A. sB.

q1 1 p0.q1 Chapter 2 Finite Automata p2.q2 1 p2 p2.q0 0 1 p1.Example 0 0 q0 1 1 1 0 1 1 p0.q2 67 Jaruloj Chongstitvatana 2301379 .q0 1 0.q0 p1.q2 1 p2.1 p0 1 p1 1 p1.q1 0 1 1 q1 0 q2 p0.

yield next configuration)  Find the language accepted by DFA/NFA  Construct DFA/NFA accepting a given language  Find closure of a state  Convert an NFA into a DFA  Prove a language accepted by FA  Construct FA from other FA’s Jaruloj Chongstitvatana 2301379 Advanced  Prove DFA/NFA accepting a language  Prove properties of DFA/NFA  Configuration change  Under some modification  etc.  Prove some properties of languages accepted by DFA/NFA  Under some modification  Surprise! Chapter 2 Finite Automata 68 .Check list Basic  Explain how DFA/NFA work (configuration.

Sign up to vote on this title
UsefulNot useful