Finite Automata
Finite Automata
1(0+1)*1
12. String starts and ends with same character.
0(0+1)*0 or a(a+b)*a
1(0+1)*1 b(a+b)*b
13. All string of a and b starting with a
a(a/b)*
14. String of 0 and 1 ends with 00.
(0+1)*00
15. String ends with abb.
(a+b)*abb
16. String starts with 1 and ends with 0.
1(0+1)*0
17. All binary string with at least 3 characters and 3rd character should be zero.
(0+1)(0+1)0(0+1)*
18. Language which consist of exactly two b’s over the set ∑={a,b}
a*ba*ba*
19. ∑={a,b} such that 3rd character from right end of the string is always a.
(a+b)*a(a+b)(a+b)
20. Any no. of a followed by any no. of b followed by any no. of c.
a*b*c*
21. String should contain at least 3 one.
(0+1)*1(0+1)*1(0+1)*1(0+1)*
22. String should contain exactly two 1’s
0*10*10*
23. Length of string should be at least 1 and at most 3.
(0+1) + (0+1) (0+1) + (0+1) (0+1) (0+1)
24. No.of zero should be multiple of 3
(1*01*01*01*)*
25. ∑={a,b,c} where a should be multiple of 3.
((b+c)*a (b+c)*a (b+c)*a (b+c)*)*
26. Even no. of 0.
(1*01*01*)*
27. Odd no. of 1.
0*(10*10*)*10*
28. String should have odd length.
(0+1)((0+1)(0+1))*
29. String should have even length.
((0+1)(0+1))*
30. String start with 0 and has odd length.
0((0+1)(0+1))*
31. String start with 1 and has even length.
1(0+1)((0+1)(0+1))*
32. Even no of 1
Dixita Kagathara, CE Department | 2160704 – Theory of Computation 2
Unit 2 – Regular Languages & Finite Automata
(0*10*10*)*
33. String of length 6 or less
(0+1+^)6
34. String ending with 1 and not contain 00.
(1+01)+
35. All string begins or ends with 00 or 11.
(00+11)(0+1)*+(0+1)*(00+11)
36. Language of all string containing both 11 and 00 as substring.
((0+1)*00(0+1)*11(0+1)*)+ ((0+1)*11(0+1)*00(0+1)*)
37. Language of C identifier.
(_+L)(_+L+D)*
a b c
q q1 q2 q3
δ(δ*( δ*(q,a),b),c)
δ(δ(δ* (q,^a),b),c)
δ(δ(δ(δ*(q,^),a),b),c)
δ(δ(δ(q,a),b),c)
δ(δ(q1,b),c)
δ(q2,c)
q3
1 C
0
A 0 B 1
1
1 0 D
0 C
1
1 0
A B 0
0 1 D
0,1
1
0 D
0
0 0 0 0
1
1
A B
1
1
1
Fig 2.5 Finite Automata for {00}*{11}*
5. (a+b)*baaa
b
a B
a
b
b
A C
b
b
a
a
a
E D
on themselves.
0, 1 0, 1 0,1 0, 1
q0 q1 q2 q3 q4
A B 0
C
0 1
P Q R
0
1 1
AR CR
Fig 2.10 Finite Automata for L1-L2
L1 U L2 0
1 BQ 1 CQ
1
0
AP 0 0 1 CP
1
1
1
AR CR
0 1 1
AP 0 CP
1
1
AR CR
Fig. 2.12 Finite Automata for L1∩ L2
1 0
P Q R
1
0
AP BP CP
1 0
1
1 1
AQ 1 BQ CQ
0
1
0
AR 0 BR CR
L1 ∩ L2
0 0
AP BP CP
1 0
1
1
AQ BQ 1 CQ
0 1
0
1
AR 0 BR CR
1
Fig. 2.17 Finite Automata
L2
1
0,1
0 0
A B C
AA BA CA
0
AB BB CB
1
0
0,1
AC BC CC
L1 ∩ L2
1
0,1
AA 0 BB 0
CC
1
Fig. 2.20 Finite Automata for L1∩L2
0,1
1 0,1 0,1
q0 q1 q2 q3
r∈δ*{ q0,1}
= U δ( r,1)
r∈{ q0, q1}
= δ{ q0,1}U δ( q1,1)
= { q0, q1}U{q2}
= { q 0, q 1, q 2}
= U δ( r,1)
r∈( q0)
= δ( q0,1)
= {q0, q1}
= δ(q0,1)U δ(q1,1)
= {q0, q1, q2}
For x ∈ Ʃ* and p ∈δ*( p, x) is the set of all states q ∈ Q such that there is a sequence of
transition corresponding to x by which M moves from p to q.
^ W
q0
^ ^
0 0
t u v
1
0
δ*(q0,^) = ^({q0})
= { q0,p,t}
1 b 4
a a
3
b a a
b
4 3
a
C
0 0
1
0
^ ^ D
A B
δ*(B,^) = {B,D}
δ*(B,0) = ^ ( U δ(r,0))
r∈δ*( B,^)
=^( U δ(r,0))
r∈δ(B,D)
= ^(δ(B,0)U δ(D,0))
= ^{ C,D}
= {C,D}
δ*(B,1) =^( U δ(r,1))
r∈δ*( B,˄)
=^( U δ(r,1))
r∈(B,D)
= ^(δ(B,1)U δ(D,1))
=Ø
δ*(C,˄) = {C}
δ*(C,0) =^( U δ(r,0))
r∈δ*( C,˄)
=^( U δ(r,0))
r∈(C)
= ^(δ(C,0))
=Ø
δ*(C,1) =^( U δ(r,1))
r∈δ*( C,˄)
=^( U δ(r,1))
r∈(C)
= ^(δ(C,1))
= ^{B}
= {B,D}
δ*(D,˄) = {D}
δ*(D,0) =^( U δ(r,0))
r∈δ*( D,^)
=^( U δ(r,0))
r∈(D)
= ^(δ(D,0))
= {D}
δ*(D,1) =^( U δ(r,1))
r∈δ*( D,^)
=^( U δ(r,1))
r∈(D)
= ^(δ(D,1))
=Ø
C
0 1
0
1 0
0
0 0
A B D
A
0
0
1
ABCD BD
0
0
1
1 CD
A
1 0
Ø D
1
0,1 0
Fig. 1.27 Finite Automata
1
0
0
^ B 1
A E
^
0
D
1
δ*(B,^) = {B}
δ*(B,0) =^( U δ(r,0))
r∈δ*( B,^)
=^( U δ(r,0))
r∈δ (B)
= ^(δ(B,0))
= ^{ C}
= { C}
δ*(B,1) =^( U δ(r,1))
r∈δ*( B,^)
= ^( U δ(r,1))
r∈(B)
= ^(δ(B,1))
= {E}
δ*(C,^) = {C}
δ*(C,0) =^( U δ(r,0))
r∈δ*( C,^)
=^( U δ(r,0))
r∈(C)
= ^(δ(C,0))
=Ø
δ*(C,1) =^( U δ(r,1))
r∈δ*( C,^)
=^( U δ(r,1))
r∈(C)
= ^(δ(C,1))
= ^{B}
={B}
δ*(D,^)= {D}
δ*(D,0) =^( U δ(r,0))
r∈δ*( D,^)
=^( U δ(r,0))
r∈(D)
= ^(δ(D,0))
= ^ {E}
= {E}
δ*(D,1) =^( U δ(r,1))
r∈δ*( D,^)
=^( U δ(r,1))
r∈(D)
= ^(δ(D,1))
= {D}
δ*(E,^) ={E}
δ*(E,0) =Ø
δ*(E,1) =Ø
0 1
0
0 0 B 1
0,1
A E
0,1
0
D
δ({C},0) =Ø
δ({C},1) = {B}
1 0
ABCDE BDE CE
0
0
1 0,1
0 1
A Ø C 1
1
0 0,1 0
DE B
E
1
1 0
D
1
W a W
Ø {^} {a}
Dixita Kagathara, CE Department | 2160704 – Theory of Computation 23
Unit 2 – Regular Languages & Finite Automata
f1
q1
f1’
^
qu
f2
^ q2
’
f2
f1 f2
^
qc=q1 q2
f1’ ^ f2’
q1
^ 1
qk
^ f1 f1’
where xi ∈ L1 for each i, Mk can move from qk to q1 by a ˄-transition; for each i, Mk moves
from q1 to an element fi of A1 by a sequence of transition corresponding to xi; and for each i,
Mk then moves from fi back to qk by a ˄-transition.
It follows that (˄x1˄) (˄x2˄)…… (˄xm˄)=x is accepted by Mk. On the other hand, if x is
accepted by Mk, there is a sequence of transition corresponding to x that begins and ends at
qk. Since the only transition from qk is a ˄-transition to q1, and the only transition to qk are ˄-
transition from elements of A1, x can be decomposed in the form
x= (^x1˄) (˄x2˄)…… (˄xm˄)
Where, for each i, there is a sequence of transition corresponding to xi from q1 to an element
of A1. Therefore, x∈ L1*.
Since we have constructed an NFA-˄ recognizing L in each of the three cases, the proof is
complete.
0 ^ 0
^
^
1
^
^ ^ 1 ^ 0
2. (0 + 1)* (10+01)* 11
^
0
^
^
1
^
^ ^
1 ^ 0
^
^
^
0 ^ 1
^
^
^
1 ^ 1
3. (0 + 1)* (10+110)* 1
^
0
^
^
1
^
^ 1 ^ 0
^
^
^
1 ^ 1 ^
^
0
0
0
A,0 B,1
a b
A,0 B,0 C,1
a
b
1 1
X,C Y,C Z,B
0 1
0 0
W,A
AA
4. Construct a moore machine that takes binary number as an i/p and produces residue
modulo ‘3’ as an output.
0 1 ∆
q0 q0 q1 0
q1 q2 q0 1
q2 q1 q2 2
Table 2.7transition Table
0 1
1 0
q0,0 q1,1 q2,2
1 0
Fig. 2.41 Moore M/c to produces residue modulo ‘3’
transition.
q0 : Is the initial state of Me and q0 ∈ Q.
B
0/n
A 1/n
0/n
1/n
C
1/y
Fig. 2.43 Mealy M/c for (0+1)*(00+11)
3. Design a mealy machine where Ʃ={0, 1, 2} print residue modulo 5 of input treated as
ternary (base 3).
1/4
0/0 0/3
2/0 1/2
2/2 1/3
2/1
2/4
0/2
1/0
S-2: Recursively interacting over the pairs of state for any transition for
δ(p,x) = r
δ(q,x) = s
and for x ∈ ε. If r and s are distinguishable make p and q as distinguish.
S-3: If any iteration over all possible state pairs one fails to find a new pair of states that are
distinguishable terminate.
S-4: All the states that are not distinguished are equivalence.
a 4
2 b
a a
b 5
1
a
b
b a
6 b
3
b a
7
b
δ(2,a)=4 δ(2,b)=5
Consider pair (1,3)
δ(1,a)=2 δ(1,b)=3
δ(3,a)=6 δ(3,b)=7
pair (2,6) is distinguish, so It’s a distinguished pair.
Consider pair (1,4)
δ(1,a)=2 δ(1,b)=3
δ(4,a)=4 δ(4,b)=5
Consider pair (1,5)
δ(1,a)=2 δ(1,b)=3
δ(5,a)=6 δ(5,b)=7
pair (2,6) is distinguish, so It’s a distinguished pair.
Consider pair (1,7)
δ(1,a)=2 δ(1,b)=3
δ(7,a)=6 δ(7,b)=7
pair (2,6) is distinguish, so It’s a distinguished pair.
Consider pair (2,3)
δ(2,a)=4 δ(2,b)=5
δ3(,a)=6 δ(3,b)=7
pair (4,6) is distinguish, so It’s a distinguished pair.
Consider pair (2,4)
δ(2,a)=4 δ(2,b)=5
δ(4,a)=4 δ(4,b)=5
Consider pair (2,5)
δ(2,a)=4 δ(2,b)=5
δ(5,a)=6 δ(5,b)=7
pair (4,6) is distinguish, so It’s a distinguished pair.
Consider pair (2,7)
δ(2,a)=4 δ(2,b)=5
δ(7,a)=6 δ(7,b)=7
pair (4,6) is distinguish, so It’s a distinguished pair.
Consider pair (3,4)
δ(3,a)=6 δ(3,b)=7
δ(4,a)=4 δ(4,b)=5
pair (6,4) is distinguish, so (3,4) is distinguish.
Consider pair (3,5)
δ(3,a)=6 δ(3,b)=7
δ(5,a)=6 δ(5,b)=7
Consider pair (3,7)
δ(3,a)=6 δ(3,b)=7
δ(7,a)=6 δ(7,b)=7
Consider pair (4,5)
δ(4,a)=4 δ(4,b)=5
Dixita Kagathara, CE Department | 2160704 – Theory of Computation 33
Unit 2 – Regular Languages & Finite Automata
δ(5,a)=6 δ(5,b)=7
pair (6,4) is distinguish, so (4,5) is distinguish.
Consider pair (4,7)
δ(4,a)=4 δ(4,b)=5
δ(7,a)=6 δ(7,b)=7
pair (6,4) is distinguish, so (4,7) is distinguish.
Consider pair (5,7)
δ(5,a)=6 δ(5,b)=7
δ(7,a)=6 δ(7,b)=7
a b
b a
124 357 6
b
a
Fig. 2.46 Minimized Finite Automata
Application: (Explain the application of the Pumping Lemma to show a Language is Regular or Not)
The pumping lemma is extremely useful in proving that certain sets are non-regular. The general
methodology followed during its applications is :
Select a string z in the language L.
Break the string z into x, y and z in accordance with the above conditions imposed by the
pumping lemma.
Now check if there is any contradiction to the pumping lemma for any value of i.
34. Use the pumping lemma to show that following language is not
regular: L = {ww|w ϵ {0,1}*}
Step 1: Let us assume that L is regular and L is accepted by an FA with n states.
Step 2: Let us chose the string
ῳ=anb anb
ῳ ῳ
| ῳ|=2n+2>=n
Let us write w as xyz with
|y|>0
And |xy|<=n
Since |xy|<=n, x must be of the form as.
Since |xy|<=n, y must be of the form ar | r>0
Now ῳ=anbanb= as ar an-s-rbanb
x y z
i
Step 3: Let us check whether x y z for i=2 belongs to L.
Xy2z= as a2r an-s-rbanb= an+rbanb
Since, r>0, an+rbanb is not of the form ῳῳ as the number of a’s in the first half is n+r and
second half is n. Therefore, xy2z L. Hence by contrdiction we can say language is not
regular.
35. Prove that the language L = {0n: n is a prime number} is not
regular.
Step 1: Let us assume that L is regular and L is accepted by an FA with n states.
Step 2: Let us chose the string
ῳ=ap ,where p is prime and p>n
| ῳ|= | ap| = p>=n
Let us write w as xyz with
|y|>0
And |xy|<=n
Since |xy|<=n, x must be of the form as.
We assume that y= am for m>0.
Step 3: Length of x yi z can be written as given below.
Xyiz= |xyz|+|yi-1|=p+(i-1)m
As |y|=| am |=m
Let us check whether P(i-1) m is prime for every i.
For i=p+1, p+(i-1)m= P+ Pm =P(1+m)
So xyp+1z L. Hence by contrdiction we can say language is not regular.
36. Use Pumping Lemma to show that following language is not
regular. L = { wwR / w ε {0,1}* }
Step 1: Let us assume that L is regular and L is accepted by an FA with n states.
Step 2: Let us chose the string
ῳ=anb ban
ῳ ῳR
| ῳ|=2n+2>=n
Let us write w as xyz with
|y|>0
And |xy|<=n
Since |xy|<=n, x must be of the form as.
Since |xy|<=n, y must be of the form ar | r>0
Now ῳ=anbban= as ar an-s-rbban
x y z
Dixita Kagathara, CE Department | 2160704 – Theory of Computation 35
Unit 2 – Regular Languages & Finite Automata