You are on page 1of 2

Tutorial Sheet

Write a regular expression for each of the following sets of binary strings. Use only the basic
operations.

1. 0 or 11 or 101
2. only 0s

Answers: 0 | 11 | 101, 0*

 Write a regular expression for each of the following sets of binary strings. Use only the basic
operations.

1. all binary strings


2. all binary strings except empty string
3. begins with 1, ends with 1
4. ends with 00
5. contains at least three 1s

Answers: (0|1)*, (0|1)(0|1)*, 1 | 1(0|1)*1, (0|1)*00, (0|1)*1(0|1)*1(0|1)*1(0|1)* or 0*10*10*1(0|


1)*.

 Write a regular expression to describe inputs over the alphabet {a, b, c} that are in sorted
order. Answer: a*b*c*.
 Write a regular expression for each of the following sets of binary strings. Use only the basic
operations.

1. contains at least three consecutive 1s


2. contains the substring 110
3. contains the substring 1101100
4. doesn't contain the substring 110

Answers: (0|1)*111(0|1)*, (0|1)*110(0|1)*, (0|1)*1101100(0|1)*, (0|10)*1*. The last one is by far


the trickiest.

 Write a regular expression for binary strings with at least two 0s but not consecutive 0s.
 Write a regular expression for each of the following sets of binary strings. Use only the basic
operations.

1. has at least 3 characters, and the third character is 0


2. number of 0s is a multiple of 3
3. starts and ends with the same character
4. odd length
5. starts with 0 and has odd length, or starts with 1 and has even length
6. length is at least 1 and at most 3
Answers: (0|1)(0|1)0(0|1)*,   1* | (1*01*01*01*)*,   1(0|1)*1 | 0(0|1)*0 | 0 | 1,   (0|1)((0|1)(0|1))*,
0((0|1)(0|1))* | 1(0|1)((0|1)(0|1))*,   (0|1) | (0|1)(0|1) | (0|1)(0|1)(0|1).

You might also like