CS-273
THEORY OF
AUTOMATA
(WEEK-3)
LECTURE-5 & 6
FINITE AUTOMATA
Lecturer
Hira Faisal
[email protected]
Note
It may be noted that to indicate the initial state,
an arrow head can also be placed before that
state and that the final state with double circle,
as shown below. It is also to be noted that while
expressing an FA by its transition diagram, the
labels of states are not necessary.
a, b
a, b
2
Example
Σ = {a,b}
States: x, y, where x is both initial and final
state.
Transitions:
1.At state x reading a or b go to state y.
2.At state y reading a or b go to state x.
3
Example Continued …
These transitions can be expressed by the
following transition table
Old States New States
Reading Reading
a b
x± y y
y x x
4
Example Continued …
It may be noted that the previous transition
table may be depicted by the following
transition diagram.
a, b
x y
a, b
5
Example Continued …
The previous transition diagram is an FA
accepting the language of strings, defined over
Σ={a, b} of even length. It may be noted
that this language may be expressed by the
regular expression
((a+ b) (a + b))*
6
TASK
Build an FA for the language L of strings,
defined over Σ={a, b}, of odd length.
7
Solution of Task
a,b
– +
a,b
8
Example: Consider the language L of strings,
defined over Σ={a, b}, starting with b.
9
The language L may be expressed by RE
b(a + b)* , may be accepted by the following FA
a,b
––
b +
a,b
a
1
10
Example:
Consider the language L of strings, defined
over Σ={a, b}, ending in a. The language L
may be expressed by RE
(a+b)*a
This language may be accepted by the following
FA
11
Example Continued …
b a a
– +
There may be another FA corresponding to the
given language.
12
Example continued …
a
a
–– +
a b
b
13
Note
It may be noted that corresponding to a given
language there may be more than one FA
accepting that language, but for a given FA
there is a unique language accepted by that FA.
14
Note
It is to be noted that given the languages L1 and
L2 ,where
L1 = The language of strings, defined over
Σ={a, b}, beginning with a
L2 = The language of strings, defined over
Σ={a, b}, not beginning with b
The does not belong to L1 while it does belong to
L2 . This fact may be depicted by the
corresponding transition diagrams of L1 and L2.
15
FA 1 Corresponding to L1
a,b
––
a +
b a,b
The language L1 may be expressed by the regular
expression a(a + b)*
16
FA 2 Corresponding to L2
a,b
a
+
a,b
b
The language L2 may be expressed by the
regular expression a (a + b)* + Λ
17
Example
Consider the Language L of Strings of length two or
more, defined over Σ = {a, b}, beginning with and
ending in same letters.
The language L may be expressed by the following
regular expression
a (a + b)* a + b (a + b)* b
It is to be noted that if the condition on the length of
string is not imposed in the above language then the
strings a and b will then belong to the language.
This language L may be accepted by the following FA
18
Example Continued …
b a a
+
a b
–
a b b
b
+
a
19
Task
Build an FA accepting the Language L of Strings,
defined over Σ = {a, b}, beginning with and
ending in same letters.
20
TASK
Build an FA for the language L of strings,
defined over Σ={a, b}, of odd length.
Solution:The language L may be
expressed by RE (a+b)
((a+b)(a+b))* or ((a+b)
(a+b))*(a+b)
This language may be accepted by the
following FA
21
Solution continued …
a,b
1 – 2+
a,b
22
Task
Build an FA accepting the Language L of Strings,
defined over Σ = {a, b}, beginning with and
ending in same letters.
Solution:The language L may be expressed by
the following regular expression
(a+b)+a(a + b)*a + b(a + b)*b
This language L may be accepted by the
following FA
23
Solution continued …
a b a
a
b
a
2+ 4 6+
b
1– b a b
b
b
a
3+ 5 7+
a
24
Example
Consider the Language L of Strings , defined
over Σ = {a, b}, beginning with and ending
in different letters.
The language L may be expressed by the
following regular expression
a (a + b)* b + b (a + b)* a
This language may be accepted by the following
FA
25
Example Continued …
a b b
2 4+
a a
1–
b a
a
b
3 5+
b
26
Example
Consider the Language L , defined over Σ=
{a, b} of all strings including Λ, The
language L may be accepted by the following FA
a,b
a,b
1 2+
The language L may also be accepted by the
following FA
27
Example Continued …
a,b
The language L may be expressed by the
following regular expression
(a + b)*
28
Example
Consider the Language L , defined over Σ = {a,
b} of all non empty strings. The language L may
be accepted by the following FA
a,b
a,b
– +
The above language may be expressed by the
following regular expression (a + b)+
29
Example
Consider the following FA, defined over Σ = {a,
b}
a,b
a,b
– +
It is to be noted that the above FA does not accept
any string. Even it does not accept the null string.
As there is no path starting from initial state and
ending in final state.
30
Equivalent FAs
It is to be noted that two FAs are said to
be equivalent, if they accept the same
language, as shown in the following FAs.
31
Equivalent FAs Continued …
a,b
FA1 –
a,b
+
a,b
FA2 a,b
1 – 2
a,b a,b
a,b
FA3 1– 2 3
+
32
Note (Equivalent FAs)
FA1 has already been discussed, while in FA2,
there is no final state and in FA3, there is a final
state but FA3 is disconnected as the states 2 and
3 are disconnected.
It may also be noted that the language of
strings accepted by FA1, FA2 and FA3 is denoted
by the empty set i.e.
{ } OR Ø
33
Example
Consider the Language L of strings ,
defined over Σ = {a, b}, containing
double a.
The language L may be expressed by the
following regular expression
(a+b)* (aa) (a+b)*.
This language may be accepted by the
following FA
34
Example Continued …
b a,b
a
a
1- 2 3+
b
35
Example
Consider the language L of strings, defined over
Σ={0, 1}, having double 0’s or double 1’s, The
language L may be expressed by the regular
expression (0+1)* (00
+ 11) (0+1)*
This language may be accepted by the following FA
36
Example Continued …
0 0
0,1
- 0 1 +
1
1
y
37
Example
Consider the language L of strings, defined over
Σ={a, b}, having triple a’s or triple b’s.
The language L may be expressed by RE
(a+b)* (aaa + bbb) (a+b)*
This language may be accepted by the following
FA
38
Example Continued …
2 a
4
a
a
b a,b
1–– a b 6+
b a
b
3 b 5
39
Example
Consider the EVEN-EVEN language, defined
over Σ={a, b}. As discussed earlier that
EVEN-EVEN language can be expressed by
the regular expression (aa+bb+(ab+ba)
(aa+bb)*(ab+ba))*
EVEN-EVEN language may be accepted by the
following FA
40
Example Continued …
1 3
b
a a a a
2 4
b
41
Summing Up
Language of strings beginning with and
ending in different letters, Accepting all
strings, accepting non-empty strings,
accepting no string, containing double a’s,
having double 0’s or double 1’s, containing
triple a’s or triple b’s, EVEN-EVEN
42