CS375 Automata 2 PDF
CS375 Automata 2 PDF
circles
6. Regular Languages & Finite Automata
- Finite Automata
Example.
Either one is acceptable
A={a, b}
9/12/2020 University of Kentucky 5
6. Regular Languages & Finite Automata
- Finite Automata
The execution of DFA for input string w ∈ A* begins at
the start state and follows a path whose edges
concatenate to w.
The DFA accepts w if the path ends in a final state.
Otherwise the DFA rejects w.
The language of a DFA is the set of accepted strings.
accepts {}
a
accepts {a}
9/12/2020 University of Kentucky 9
6. Regular Languages & Finite Automata
- Finite Automata
Specifically, say A = {a, b}, then
1 accepts
a, b
a, b
1 2 accepts {}
a, b
a
1 2 accepts {a}
b a, b
3
9/12/2020 a, b
University of Kentucky 10
6. Regular Languages & Finite Automata
- Finite Automata
Theorem (Kleene) The class of regular languages is
exactly the same as the class of languages accepted
by DFAs.
Proof. (conti.)
b a, b b
a, b
accepts {a} a, b accepts {b}
a, b
a
then a, b
b
a, b
9/12/2020 University of Kentucky 12
accepts {a, b}
6. Regular Languages & Finite Automata
- Finite Automata
For instance, if 𝐿1 = {a} and 𝐿2 = {b}
a, b
a a
b a, b b
a, b
accepts {a} a, b accepts {b}
a b
then a
b
a, b
9/12/2020 University of Kentucky 13
accepts {ab}
a, b
6. Regular Languages & Finite Automata
- Finite Automata
For instance, if 𝐿1 = {a} and 𝐿2 = {b}
a, b
a a
b a, b b
a, b
accepts {a} a, b accepts {b}
a, b
then a, b
b b
a a
9/12/2020 University of Kentucky accepts {aa} 14
6. Regular Languages & Finite Automata
- Finite Automata
For instance, if 𝐿1 = {a} and 𝐿2 = {b}
a, b
a a
b a, b b
a, b
accepts {a} a, b accepts {b}
a, b
a, b
or b b b
a a a
9/12/2020 University of Kentucky
accepts {aaa}
15
6. Regular Languages & Finite Automata
- Finite Automata
Example. Find a DFA for each language over the alphabet {a,b}.
n
(a) ∅. (b) {Λ}. (c) { (ab) | n ∈ N}, which has regular
expression (ab)*.
Solution:
a, b
a, b
a, b
a, b
Question:
Would this DFA work?
aa is accepted by this
DFA, but …
9/12/2020 University of Kentucky 19
6. Regular Languages & Finite Automata
- Finite Automata
c c
b
b b
a a
start start
c c c c
a, b, c a, b, c
c c
a,b a,b
b
b a,b b a
a a, a a,
b, b,
start start
c c
c c c c
c c
a, b a, b
b
b b
a a
start start
a, b a
c c c c
a, a, a, a,
b, b, b, b,
c c c c
9/12/2020 University of Kentucky 23
To make each of these FA’s a DFA, you either
create a new state or use a non-final state as
the sink of all the remaining edges of the FA.
c In addition to
a*bc* and ac,
does it recognize
b
anything else?
b
a
a
start Yes, such as
c c aac, aaac, …
b
b b
a a
start
c c c
n≥3
b
b b a
a a
start How to make
c c c this FA a real
DFA?
c One option:
a,b
b
b b
a
a a
start a real DFA now
a,b,c c c c
a,b,c a,b,c
9/12/2020 University of Kentucky 28
6. Regular Languages & Finite Automata
- Finite Automata
Table Representation of a DFA
DFA over A can be represented by a transition function
T : States × A → States,
where T(i, a) is the state reached from state i along the edge
labeled a, and we mark the start and final states.
Example:
{( a + ba) bb}
a,b
any combination a
9/12/2020 of a* and (ba)* University of Kentucky 31
6. Regular Languages & Finite Automata
- Finite Automata
Example (conti). Find a DFA to recognize (a + ba)*bb(a + ab)*.
A solution:
any combination
of a* and (ab)* a,b a
a,b
any combination
of a* and (ab)*
m r
d o g
o
d,g,m,r d,g,m,o,r
d,m,r
g,m,o,r
d,g,o
m r
d,g,m,o
d,g,m,o,r
9/12/2020 University of Kentucky 36
Intuitive examples
Actually, the NFA can also be defined as follow:
d o g
o
A = { d, g, m, o, r}
o
m r
a, b, ab,
DFA for the language of a + aa*b + a*b. aab, aaab,
a …
a b a, b
Start
9/12/2020 University of Kentucky 38
b a, b
DFA and NFA are equivalent concept.
a c d
Ʌ Ʌ e
0 1 2
b d f
Extended
9/12/2020 University of Kentucky 40
state of 0
Edges a, b, c, d, e, f, g are edges of the
extended state of 0.
Each edge of the extended state of 0 can be
used by state 0 through some Ʌ-edges.
So essentially state 0 has 7 edges to use
even though there are only 2 real edges
emitted from state 0.
a c e
Ʌ Ʌ f
0 1 2
Extended d g
9/12/2020
b University of Kentucky 41
state of 0
For an NFA, only edges really needed for its
function have to be designed.
We don’t
need to
design any
edges for
state 2.
9/12/2020 University of Kentucky 42
Why do we need “multiple edges with the
same letter”?
b
b b
a a a
start
a b ab aab aaab
9/12/2020 University of Kentucky 44
6. Regular Languages & Finite Automata
- Finite Automata
Table representation of NFA
An NFA over A can be represented by a function
T : States × A ∪ {Λ} → power(States),
where T(i, a) is the set of states reached from state i along the
edge(s) labeled a, and we mark the start and final states.
Example:
0
Questions. Find an NFA for each of the languages over {a, b}.
{a , b , (ab)}
a,b
=
9/12/2020 University of Kentucky
? 46
6. Regular Languages & Finite Automata
- Finite Automata
Example. Find an NFA to recognize (a + ba)*bb(a + ab)*.
A solution:
{bb}
{( a + ba) bb}
any combination
of a* and (ba)*
9/12/2020
any combination University of Kentucky 47
of a* and (ab)*
6. Regular Languages & Finite Automata
- Finite Automata
Example (conti). Find an NFA to recognize (a + ba)*bb(a + ab)*.
A solution:
But not
{( a + ba ) bb (aa b)*}
Ʌ Given Ʌ
s FA f
A A+ BC*D
A
i j
B k D
A
i j Put Φ here if
BC*D there was not
a direct edge
between i and
j originally
A + BC*D
9/12/2020 i University of Kentucky j 54
6. Regular Languages & Finite Automata
- Finite Automata
Example. Transform the following NFA into a regular expression.
a*a(ba*a)*
0 b
6. Regular Languages & Finite Automata
- Finite Automata
Example. Transform the following NFA into a regular expression.
0 a
a 1
9/12/2020 University of Kentucky 56
0 b
6. Regular Languages & Finite Automata
- Finite Automata
Example. Transform the following NFA into a regular expression.
a
Ʌ a Ʌ
s 0 1 f
b a
9/12/2020
1 University of Kentucky 58
Or, eliminate state 1 first, the
following way:
a
Ʌ a Ʌ
s 0 1 f
b a
aɅ*Ʌ
1
a
Ʌ a
s 0 f
aɅ*b ab
ab 0 ab 0
0 a+ab 0
a + ab
Ʌ a
s 0 f
9/12/2020 University of Kentucky 60
Or, eliminate state 1 first, the
following way:
a + ab
Ʌ a
s 0 f
Ʌ(a+ab)*a
s f
(a+ab)*a
9/12/2020
s
University of Kentucky
f 61
6. Regular Languages & Finite Automata
- Finite Automata
Example. Transform the following NFA into a regular expression.
a
Ʌ a Ʌ
s 0 1 f
a b
0
9/12/2020 University of Kentucky 65
a
Or, eliminate state 0 first, the
following way:
a
Ʌ a Ʌ
s 0 1 f
a b
Ʌa*a
0
a*a Ʌ
s 1 f
ba*a
9/12/2020
ba*a University of Kentucky 66
Or, eliminate state 0 first, the
following way:
a*a Ʌ
s 1 f
ba*a
a*a(ba*a)*Ʌ
s f
a*a(ba*a)*
9/12/2020
sUniversity of Kentucky f 67
6. Regular Languages & Finite Automata
- Finite Automata
Note. The two regular expressions obtained in the previous
example are equal, i.e., a*a( ba* a)* = (a + ab)*a.
Proof I.
( a + ab )* a ( R + S )* = R* (S R* )*
= [ a* ( (ab) a* )* ] a · is associative
= a* [ ( ( a b ) a* )* a ] · is associative
= a* [ ( a ( b a* ) )* a ] (R S )* R = R (S R )*
= a* [ a (( ba* ) a )* ] · is associative
9/12/2020 University of Kentucky 68
= a* a (ba* a)*
6. Regular Languages & Finite Automata
- Finite Automata
Note. The two regular expressions obtained in the previous
example are equal, i.e., a*a(ba*a)* = (a + ab)*a.
Proof II.
a* a ( ba*a )* = a*[a(( ba* ) a)*] · is associative
= a*[( a (ba*) )*a ] R(SR)* = (RS)*R
= a*[ ( (ab)a* )* a] · is associative
= [a* ((ab) a*)* ] a · is associative
= (a + ab)*a R*(SR*)* = (R + S)*
QED.