You are on page 1of 4

COLLEGE OF ENGINEERING PUNE

An Autonomous Institute of Government of Maharashtra

(CT 11003) Theory of Computer Science


Class: S. Y. Computer Engineering
Problem Set on Finite Automata and Regular Expressions
Gauri Shah

Q1. Give regular expressions for the following languages:


(a) = {0, 1}. L = {w|w has an even number of zeroes} : (01? 0 + 1)?
(b) = {a, b}. L = {w|w ends in double letters} : (a + b)? (aa + bb)
(c) = {a, b}. L = {w|w does not end in double letters} :  + a + b + (a + b)? (ab + ba)
(d) = {a, b}. L = {w| the total number of as in w is divisible by 3} : (b + ab? ab? a)?
(e) = {d, e, f }. L = {w|w can be any string except the empty string} : (d + e + f )(d + e + f )?
(f) = {0, 1}. L = {w|w has 1 in every odd position} : 1((0 + 1)1)?
(g) = {0, 1}. L = {w|w has at least two 0s and at most one 1} :
0? (00(1 + ) + 0(1 + )0 + (1 + )00)0?
Q2. Describe clearly and succinctly in plain English, the languages defined by the following regular expressions over the alphabet {0, 1}:
(a) 1(0 + 1)? 0: Strings that begin with a 1 and end with a 0.
(b) (0 + 1)? (0? 10? 10? )(0 + 1)? : Strings that contain at least two 1s.
(c) ? 0101? : Strings that contain the substring 0101.
(d)  + 0 + 1 + 00 + 01 + 10 + 000 + 001 + 010 + 011 + 100 + 101 + 110 + (0 + 1)4 : All strings of length
less than or equal to 4 except 11 and 111.
Q3. List any two strings that belong and any two strings that do not belong to the following languages
over the alphabet {a, b}:

Regular Expression
aba bab
( a)b
(a ba bb)?
? a ? b ? a ?

Belongs
aba, bab
b, ab
a, ba, bb
aabaa, aba

Q4. Draw the state diagram for the following transition table:

q1
q2
?q3
q4
q5

u
q1
q1
q2
q3
q4

Page 1 of 4

d
q2
q3
q4
q5
q5

Does Not Belong


aaa, bbb
a, ba
, b
bb, aa

u
u
q2

d
d

q3

start

q1

d
d

q4

q5
u

Q5. Construct DFAs for the following languages defined on the binary alphabet {0, 1}:
(a) L = {w|w does not contain 110}
0,1
0

start

1
1

DEAD

0
(b) L = {w|w contains at least two 0s and at most one 1}
The following two DFAs accepts strings with at least two 0s and at most one 1 respectively.
Then we can combine them to construct a new DFA that accepts L.
1

start

start

0,1

0,1

0
1

Combining the two DFAs, we get the following transition table for a new DFA that accepts
strings with at least two 0s and at most one 1.

AD
AE
AF
BD
BE
BF
? CD
? CE
CF

0
BD
BE
BF
CD
CE
CF
CD
CE
CF

Page 2 of 4

1
AE
AF
AF
BE
BF
BF
CE
CF
CF

CD

0
1

0
BD

CE

0
start

AD

0,1

BE

CF

AE

0
BF

0
1

AF

1
Notice that AF and BF are redundant dead states because once we have seen more than one 1,
we do not need to keep track of the number of 0s seen. We can directly have arrows labeled 1
going from AE and BE to CF. Which is the DFA we get from the idea I discussed in class. This
DFA as shown below is smaller with only 7 states.
State
AD
AE
BD
BE
CD
CE
CF

Num of 0s seen
0
0
1
1
2+
2+
Dont care

Num of 1s seen
0
1
0
1
0
1
2

CD

0
1

0
BD

CE

0
start

AD

0,1
1

BE

CF

1
AE

Q6. Construct -NFAs for the following languages defined over the binary alphabet {0, 1}:

Page 3 of 4

(a) L1 L2 where L1 is the language of all strings that contain 0101 as a substring, and L2 is the
language of all strings that do not contain 110.
0+1

0+1
0


start

0+1

1
H

0
(b) L1 L2 where L1 is the language of all strings with at least three 1s, and L2 is the language of
all strings of length at most three.
0

start

0
1

0+1

0
1

0+1


0+1

0+1

(c) L?1 where L1 is the language of all strings with 1 at every odd position.
0+1+
start

C
0

0+1

Page 4 of 4

0+1

0+1

You might also like