Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 2

Compiler Design Spring 2010 (CSE344)

Practice Questions on Regular Expressions


Instructor: Asma Sanam Larik
1. Write a regular expression for each of the following sets of binary strings.
Use only the basic operations.
a.
b. all binary strings except empty string _______________________
c. begins with 1 and ends with a 1 ____________________________
d. ends with 00 ___________________________________________
e. contains at least three 1s _________________________________
2. Write a regular expression to describe inputs over the alphabet {a, b, c}
a. that are in sorted order _________________________________
b. containing at least one a and at least one b__________________
3. Write a regular expression for each of the following sets of binary strings.
Use only the basic operations.
a.
b. contains the substring 110 _____________________________
c. doesn't contain the substring 110 ________________________
d. whose tenth symbol from the right is 1_____________________
e. not containing 101 as a substring
2. Write a regular expression for each of the following sets of binary strings.
Use only the basic operations.
a.
b.
c.
d.
e.

number of 0s is a multiple of 3 _____________________________


has at least 3 characters, and the third character is 0 ___________
starts and ends with the same character _____________________
length is at least 1 and at most 3 ___________________________

2. Write a Regular Expression for the following language


a. L= { an bm | n>=4, m<=3}
b. L= { an bm | (n +m) is even }

Compiler Design Spring 2010 (CSE344)


Practice Questions on Regular Expressions
c. L={w {0,1}* | w has at least one pair of consecutive zeros}
d. L={w {0,1}* | w has no pair of consecutive zeros}
3. What is the language denoted by the following RE
a. R= (a+b)*(a+bb)
__________________________________________________
b. R= (aa)* (bb)*b
__________________________________________________
Answers:
1)

2)

a. (0+1)(0+1)*
b. 1(0+1)*1
c. (0+1)*00
d.
(0+1)*1(0+1)*1(0+1)*1(0+1)*

3)

a. a*b*c*
b. (a+b+c)*a(a+b+c)*b(a+b+c)* +
(a+b+c)* b(a+b+c)*a(a+b+c)*

4)
a.
b.
c.
d.

(0+1)*110(0+1)*
(0+10)*1*
(0+1)*1(0+1)9
(0*1*00)* 0*1*

5)
a. a4 a*+ a4 a*b + a4 a*b2 + a4 a*b3 =
a4 a*(+b+b2 + b3 )
b. (aa)* (bb)* + (aa)* a (bb)* b
c. (0+1)* 00 (0+1)*
d. (1* 011*)*0+ 1*0

a. (0+1)(0+1)0(0+1)*
b. 1* + (1*01*01*01*)+
c. 1(0+1)*1 + 0(0+1)*0 +0 + 1
d. (0+1) + (0+1)(0+1) + (0+1)(0+1)(0+1)

6)
a. set of strings terminated by a or bb
b. even number of as followed by odd
number of bs

You might also like