Professional Documents
Culture Documents
COS201 Chapter 4 Solution PDF
COS201 Chapter 4 Solution PDF
ws/Unisa
Cohen chapter 4
1. Let r1, r2, and r3 be three regular expressions. Show that the language associated with (r1
+ r2)r3 is the same as the language associated with r1r3 + r2r3. Show that r1(r2 + r3) is
equivalent to r1r2 + r1r3. This will be the same as providing a ‘distributive law’ for regular
expressions.
2. Construct a regular expression for all words in which a appears tripled, if at all. This means
that every clump of a’s contains 3 or 6 or 9 or 12… a’s.
3. Construct a regular expression for all words that contain at least one of the strings s1, s2,
s3, or s4.
4. Construct a regular expression for all words that contain exactly two b’s or exactly three b’s,
not more.
(i)
(a + b)*(aa + bb)
(ii)
(a + b)*(ab + ba) + a + b + /\
Note: Provide for strings containing zero or one letter too!
6. Construct a regular expression for all strings that have exactly one double letter in them.
7. Construct a regular expression for all strings in which the letter b is never tripled. This
means that no word contains the substring bbb.
8. Construct a regular expression for all words in which a is tripled or b is tripled, but not both.
This means each word contains the substring aaa or the substring bbb but not both.
‘words in which a is tripled’ means there is at least one triple, and possibly more.
(i)
b*a*
This contains only b’s or only a’s, or b’s followed by a’s or /\.
(ii)
‘words that do not have both substrings…’ means that words may have one or the other - just
not both (i.e. not abba or bbaabb).
So put a + between two regular expressions defining a) all words excluding bba, and b) all
words excluding abb.
Together they form a regular expression that excludes both substrings simultaneously.
a*(baa*)*b* + b*(a*ab)*a*
LHS: If there’s a double b, it’s not followed by an a.
RHS: If there’s a double b, it’s not preceded by an a.
10. Construct a regular expression for all strings in which the total number of a’s is divisible by
3 no matter how they are distributed, such as aabaabbaba.
(b*ab*ab*ab*)*
(i)
a*(b(bb)*aa*)*(/\ + b(bb)*)
The compulsory a after some number of odd b’s is there because odd + odd = even, so it is
needed to separate these odd clumps.
(ii)
EVEN-EVEN = [aa + bb + (ab + ba)(aa + bb)*(ab + ba)]*
Divide the language into 2 groups:
a) Words that start with b (followed by even a’s and even b’s)
b) Words that start with a (followed by odd a’s and odd b’s)
(iii)
EVEN-EVEN(ab + ba)EVEN-EVEN
The smallest string is ab or ba.
Even letters can be added to the left, right, or both.