Download presentation
Presentation is loading. Please wait.
Published byAgus Hendra Pranata Modified over 6 years ago
1
CS 350 โ Fall 2018 gilray.org/classes/fall2018/cs350/
Deterministic finite automata (DFA) & Non-deterministic finite automata (NFA) CS 350 โ Fall 2018 gilray.org/classes/fall2018/cs350/
2
DFA transition diagram
๐ฟ={hello} h e l o q0 q1 q2 q3 l q4 q5 DFA transition diagram
3
Formally, each DFA is a 5-tuple:
A set of final states Formally, each DFA is a 5-tuple: (๐,ฮฃ,๐ฟ, ๐ 0 ,๐น) A starting state A finite set of states {qโฆ} A transition function An alphabet
4
Formally, each DFA is a 5-tuple:
(๐,ฮฃ,๐ฟ, ๐ 0 ,๐น) ๐ฟโ(๐รฮฃโ๐) ๐นโ๐ ๐ 0 โ๐
5
(๐,ฮฃ,๐ฟ, ๐ 0 ,๐น),where ๐={ ๐ 0 ,โฆ, ๐ 5 } ฮฃ={a,b,โฆ,z} ๐น={ ๐ 5 }
l l o q0 q1 q2 q3 q4 q5 (๐,ฮฃ,๐ฟ, ๐ 0 ,๐น),where ๐={ ๐ 0 ,โฆ, ๐ 5 } ฮฃ={a,b,โฆ,z} ๐ฟ={( ๐ 0 ,h, ๐ 1 ),( ๐ 1 ,e, ๐ 2 ), ( ๐ 2 ,l, ๐ 3 ),( ๐ 3 ,l, ๐ 4 ),( ๐ 4 ,o, ๐ 5 )} ๐น={ ๐ 5 }
6
h e l o q0 q1 q2 q3 l q4 q5 ๐ฟ h l e o โฆ โฆ ๐ 0 ๐ 1 DFA transition table ๐ 1 ๐ 2 ๐ 2 ๐ 3 ๐ 3 ๐ 4 ๐ 4 ๐ 5 ๐ 5 ๐ฟ={( ๐ 0 ,h, ๐ 1 ),( ๐ 1 ,e, ๐ 2 ), ( ๐ 2 ,l, ๐ 3 ),( ๐ 3 ,l, ๐ 4 ),( ๐ 4 ,o, ๐ 5 )}
7
Extended transition function
h e l q3 l o q0 q1 q2 q4 q5 Extended transition function ๐ฟ ฬ ={( ๐ 0 ,h, ๐ 1 ),( ๐ 1 ,e, ๐ 2 ), ( ๐ 2 ,l, ๐ 3 ),( ๐ 3 ,l, ๐ 4 ),( ๐ 4 ,o, ๐ 5 ), ( ๐ 0 ,he, ๐ 2 ),( ๐ 1 ,el, ๐ 3 ),( ๐ 2 ,ll, ๐ 4 ),( ๐ 3 ,lo, ๐ 5 ), ( ๐ 0 ,hel, ๐ 3 ),( ๐ 1 ,ell, ๐ 4 ),( ๐ 2 ,llo, ๐ 5 ), ( ๐ 0 ,hell, ๐ 4 ),( ๐ 1 ,ello, ๐ 5 ),( ๐ 0 ,hello, ๐ 5 )} ๐ฟ={( ๐ 0 ,h, ๐ 1 ),( ๐ 1 ,e, ๐ 2 ), ( ๐ 2 ,l, ๐ 3 ),( ๐ 3 ,l, ๐ 4 ),( ๐ 4 ,o, ๐ 5 )}
8
Computing the extended transition function as a least fixed point
๐ฟ ฬ ,where ๐ ๐ฟ,๐ ( ๐ฟ ฬ )= ๐ฟ ฬ ๐ ๐ฟ,๐ ( ๐ฟ ฬ )={( ๐ ๐ , ๐ 0 ๐ 1 , ๐ ๐ )|( ๐ ๐ , ๐ 0 , ๐ ๐ )โ๐ฟโง( ๐ ๐ , ๐ 1 , ๐ ๐ )โ ๐ฟ ฬ } โช{( ๐ ๐ ,๐, ๐ ๐ )| ๐ ๐ โ๐}
9
Computing the extended transition function as a least fixed point
๐ ๐ฟ,๐ ( ๐ฟ ฬ )={( ๐ ๐ , ๐ 0 ๐ 1 , ๐ ๐ )|( ๐ ๐ , ๐ 0 , ๐ ๐ )โ๐ฟโง( ๐ ๐ , ๐ 1 , ๐ ๐ )โ ๐ฟ ฬ } โช{( ๐ ๐ ,๐, ๐ ๐ )| ๐ ๐ โ๐} โ( a โ ) ๐ฟ a ๐ 0 ๐ 0 a q0
10
Computing the extended transition function as a least fixed point
๐ ๐ฟ,๐ ( ๐ฟ ฬ )={( ๐ ๐ , ๐ 0 ๐ 1 , ๐ ๐ )|( ๐ ๐ , ๐ 0 , ๐ ๐ )โ๐ฟโง( ๐ ๐ , ๐ 1 , ๐ ๐ )โ ๐ฟ ฬ } โช{( ๐ ๐ ,๐, ๐ ๐ )| ๐ ๐ โ๐} โ( a โ ) ๐ฟ ฬ ๐ a ๐ 0 ๐ 0 ๐ 0 a q0
11
Computing the extended transition function as a least fixed point
๐ ๐ฟ,๐ ( ๐ฟ ฬ )={( ๐ ๐ , ๐ 0 ๐ 1 , ๐ ๐ )|( ๐ ๐ , ๐ 0 , ๐ ๐ )โ๐ฟโง( ๐ ๐ , ๐ 1 , ๐ ๐ )โ ๐ฟ ฬ } โช{( ๐ ๐ ,๐, ๐ ๐ )| ๐ ๐ โ๐} โ( a โ ) ๐ฟ ฬ ๐ a aa aaa ๐ 0 ๐ 0 ๐ 0 ๐ 0 ๐ 0 a q0
12
โ(๐,ฮฃ,๐ฟ, ๐ 0 ,๐น)={๐ |( ๐ 0 ,๐ , ๐ ๐ )โ ๐ฟ ฬ โง ๐ ๐ โ๐น}
The Language L of a DFA: and ๐ฟ ฬ (๐,ฮฃ,๐ฟ, ๐ 0 ,๐น) โ(๐,ฮฃ,๐ฟ, ๐ 0 ,๐น)={๐ |( ๐ 0 ,๐ , ๐ ๐ )โ ๐ฟ ฬ โง ๐ ๐ โ๐น} where ๐ฟ ฬ is the least fixed point ๐ฟ ฬ = ๐ ๐ฟ,๐ ( ๐ฟ ฬ )
13
L is the language L((a|b)*cc(a|b)*).
Try an example: L is the language L((a|b)*cc(a|b)*).
14
L is the language L((a|b)*cc(a|b)*).
Try an example: L is the language L((a|b)*cc(a|b)*). c c q0 q1 q2 a,b a,b
15
L is the language L((a|b)*bab).
Try an example: L is the language L((a|b)*bab).
16
L is the language L((a|b)*bab).
Try an example: L is the language L((a|b)*bab). b b b a b q0 q1 q2 q3 a a a
17
Try an example: L is the language, over {a,b}, of strings
with an even number of aโs and of bโs.
18
Try an example: L is the language, over {a,b}, of strings
with an even number of aโs and of bโs. a q0 q2 a b b b b q1 a q3 a
19
There are an even number of aโs There are an odd number of aโs
q0 q2 a b b b b q1 a q3 a
20
a a b b b b a a There are an even number of bโs
q0 q2 a b b b b q1 a q3 a There are an odd number of bs
21
So this is just the DFAs for (aa). and for (bb). composed
So this is just the DFAs for (aa)* and for (bb)* composed. Can this idea be generalized? a (E,E) (O,E) a b b b b (E,O) a (O,O) a
22
๐น โฉ ={( ๐ 0๐น , ๐ 1๐น )| ๐ 0๐น โ ๐น 0 โง ๐ 1๐น โ ๐น 1 }
โ( ๐ 0 ,ฮฃ, ๐ฟ 0 , ๐ 00 , ๐น 0 )โฉโ( ๐ 1 ,ฮฃ, ๐ฟ 1 , ๐ 10 , ๐น 1 ) =โ( ๐ โฉ ,ฮฃ, ๐ฟ โฉ , ๐ โฉ , ๐น โฉ ) ๐ โฉ = ๐ 0 ร ๐ 1 ๐ฟ โฉ ={(( ๐ 0 , ๐ 1 ),๐ ,( ๐ 0 โฒ , ๐ 1 โฒ )) |( ๐ 0 ,๐ , ๐ 0 โฒ )โ ๐ฟ 0 ๐ โฉ =( ๐ 00 , ๐ 10 ) โง( ๐ 1 ,๐ , ๐ 1 โฒ )โ ๐ฟ 1 } ๐น โฉ ={( ๐ 0๐น , ๐ 1๐น )| ๐ 0๐น โ ๐น 0 โง ๐ 1๐น โ ๐น 1 }
23
Try an example: L is the language, over {0,1}, of strings
with an even number of 0s and two 1s.
24
Try an example: L is the language, over {0,1}, of strings
with an even number of 0s and two 1s. 1 1 q0 q1 q2 q0 q1 1 1
25
Try an example: L is the language, over {0,1}, of strings
with an even number of 0s and two 1s. 1 1 q0,q0 q0,q1 q0,q2 1 1 q1,q0 q1,q1 q1,q2
26
is the complement of language (a|b)*bab
Try an example: is the complement of language (a|b)*bab ๐ฟ
27
(Recall that this is how we defined L as a DFA.)
Try an example: is the complement of language (a|b)*bab ๐ฟ b b b a b q0 q1 q2 q3 a a a (Recall that this is how we defined L as a DFA.)
28
is the complement of language (a|b)*bab
Try an example: is the complement of language (a|b)*bab ๐ฟ b b b a b q0 q1 q2 q3 a a a
29
(Recall that this is how we defined {a} as a DFA.)
Try an example: is the complement of language a ๐ฟ a q0 q1 (Recall that this is how we defined {a} as a DFA.)
30
is the complement of language a
Try an example: is the complement of language a ๐ฟ a a q0 q1 q2 a
31
๐ โฒ =๐โช{ ๐ dead } ๐น โฒ = ๐ โฒ โ๐น ๐ฟ โฒ =๐ฟโช{( ๐ dead ,๐ , ๐ dead )|๐ โฮฃ}
The complement ofโ(๐,ฮฃ,๐ฟ, ๐ 0 ,๐น)isโ( ๐ โฒ ,ฮฃ, ๐ฟ โฒ , ๐ 0 , ๐น โฒ ) ๐ โฒ =๐โช{ ๐ dead } ๐น โฒ = ๐ โฒ โ๐น ๐ฟ โฒ =๐ฟโช{( ๐ dead ,๐ , ๐ dead )|๐ โฮฃ} โช{(๐,๐ , ๐ dead )|๐ โฮฃโง๐โ๐โง(๐,๐ , ๐ โฒ )โ๐ฟ}
32
Non-deterministic finite automata (NFA)
33
Models of regular languages
โConverts toโ GNFA โConverts toโ RE DFA โMinimizes toโ NFA โConverts toโ โConverts toโ
34
L is the language L((a|b)*bab).
Try an example: L is the language L((a|b)*bab). b a b q0 q1 q2 q3 a,b
35
b a b a,b Letโs run this nondeterministically on the string babab and
track what paths we can take: b a b q0 q1 q2 q3 a,b
36
/ Letโs run this nondeterministically on the string babab and track what paths we can take: b a b q0 q1 q2 q3 a,b
37
/ / Letโs run this nondeterministically on the string babab and track what paths we can take: b a b q0 q1 q2 q3 a,b
38
/ / / Letโs run this nondeterministically on the string babab and track what paths we can take: b a b q0 q1 q2 q3 a,b
39
/ / / / Letโs run this nondeterministically on the string babab and track what paths we can take: b a b q0 q1 q2 q3 a,b
40
If any possible path would accept, then the NFA accepts.
/ / / / / Letโs run this nondeterministically on the string babab and track what paths we can take: If any possible path would accept, then the NFA accepts. b a b q0 q1 q2 q3 a,b
41
Formally, each NFA is also a 5-tuple:
A set of final states Formally, each NFA is also a 5-tuple: (๐,ฮฃ,๐ฟ, ๐ 0 ,๐น) A starting state A finite set of states {q0,โฆ} A transition relation An alphabet
42
๐ฟ:๐รฮฃร๐ A transition relation
43
๐ฟ:๐รฮฃร๐ ๐ฟ:๐รฮฃโ๐ซ(๐) A transition relation
44
b ๐ฟ a ๐ 0 ๐ 1 ๐ 2 ๐ 3 NFA transition table { ๐ 0 } { ๐ 0 , ๐ 1 }
q0 q1 q2 q3 a,b NFA transition table b ๐ฟ a ๐ 0 { ๐ 0 } { ๐ 0 , ๐ 1 } ๐ 1 { ๐ 2 } ๐ 2 { ๐ 3 } ๐ 3
45
NFA extended transition table
q0 q1 q2 q3 NFA extended transition table a,b ๐ฟ ฬ b ab ba bab a aa ๐ 0 { ๐ 0 } { ๐ 0 , ๐ 1 } { ๐ 0 } { ๐ 0 , ๐ 1 } { ๐ 0 , ๐ 2 } { ๐ 0 , ๐ 3 } ๐ 1 { ๐ 2 } { ๐ 3 } โฆ ๐ 2 { ๐ 3 } ๐ 3
46
This is exactly the same as for a DFA, except now a relation.
Computing an NFAโs extended transition relation as a least fixed point This is exactly the same as for a DFA, except now a relation. ๐ฟ ฬ ,where ๐ ๐ฟ,๐ ( ๐ฟ ฬ )= ๐ฟ ฬ ๐ ๐ฟ,๐ ( ๐ฟ ฬ )={( ๐ ๐ , ๐ 0 ๐ 1 , ๐ ๐ )|( ๐ ๐ , ๐ 0 , ๐ ๐ )โ๐ฟโง( ๐ ๐ , ๐ 1 , ๐ ๐ )โ ๐ฟ ฬ } โช{( ๐ ๐ ,๐, ๐ ๐ )| ๐ ๐ โ๐}
47
The Language L of an NFA:
and ๐ฟ ฬ (๐,ฮฃ,๐ฟ, ๐ 0 ,๐น) ๐ฟ={๐ |( ๐ฟ ฬ ( ๐ 0 ,๐ )โฉ๐น)โร}
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.