Quiz-3 Solution
Quiz-3 Solution
Section(A-C)
1. 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.
Solution:
(aaa + b)*
2. Prove that: If L is a finite language (a language with only finitely many words), then L can be
defined by a regular expression.
Solution:
Consider L= { ab,ba,aa,bb}, a finite language consisting of four words only.
We can write a regular expression for L as:
ab+ba+aa+bb.
3. Construct a regular expression defining the following language over the alphabet I = {a, b}.
i.
All strings that have an even number of a's and an odd number of b's.
ii.
All strings that have an odd number of a's and an odd number of b's.
Solution:
i)
ii)
4. Define (in english phrases) rules that represent this regular expression:
(a+b)* ab(a+b)* + b*a*
Solution:
1. is in language
2. All the strings of this language must contain substring ab OR some bs followed by some
number of as.
Quiz # 3
Section(B-D)
1. Define a regular expression that denotes all the words with at least three a's?
Solution:
b* a b* a b* a (a +b )*
2. Construct a regular expression defining the following language over the alphabet I = {a, b}.
a) All strings in which any b's that occur are found in clumps of an odd number at a
time, such as abaabbbab.
Solution:
(a*b(bb)* a+)*
3. Describe (in English phrases) the languages associated with the following regular expressions.
i. ((a + b)a)*
Solution:
1. is in the language.
2. All the words must end with a.
3. The language does not contains bb means no consective bs can come together. b is always
followed by an a.
OR
4. All the words with even lengths in which b is separated by some as and a occupies all even
positions.
4. Find a regular expression corresponding to the language L defined recursively as follows:
Rule 1:
is in L and a is in L .
Rule 2: If x is in L , then aabx is in L and bbx is in L .
Rule 3: Nothing is in L unless it can be obtained from the above two clauses.
Solution:
(aab + bb)*(a + )
Quiz # 3
Section(E)
1. Define a regular expression of all words in which:
i.
ii.
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.
All words that contain exactly three b's in total.
Solution:
i)
(a + ba + bba)* (bb+ b + ) aaa (a + ba + bba)* (bb+ b + ) +
(b + ab + aab)* (aa+ a + ) bbb (b + ab + aab)* (aa+ a + )
ii)
a* b a* b a* b a*
2. Let us reconsider the regular expression (a + b)*a(a + b)*b(a + b)*. Show that this is equivalent
to (a + b)*ab(a + b)* in the sense that they define the same language.
Solution:
Let (a + b)0 a(a + b)0 b(a + b)0 = ab
And (a + b)0 ab(a + b)0 = ab
This shows both regular expressions must contain substring ab. Any number of as or bs can
occur before or after ab.
3. Define a regular expression of all words in which a appears doubled, if at all. This means that
every clump of a's contains 2 or 4 or 6 or 8... a's.
Solution:
(aa+b)*
4. Describe (in English phrases) the languages associated with the following regular expressions.
a. (a* + b)* and (a + b)*
(a* + b )*
1. is in the language
2. The language contains all the strings containing a or b.
(a + b)*
1. is in the language
2. The language contains all the strings containing a or b.