33% found this document useful (3 votes)
3K views3 pages

Quiz-3 Solution

This document contains solutions to quiz questions on regular expressions. It is divided into 5 sections (A-E). The questions cover topics such as defining regular expressions for specific languages over alphabets like {a,b}, proving languages can be defined by regular expressions if finite, constructing regular expressions that match certain string properties, and describing languages associated with given regular expressions.

Uploaded by

Biya Hassan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
33% found this document useful (3 votes)
3K views3 pages

Quiz-3 Solution

This document contains solutions to quiz questions on regular expressions. It is divided into 5 sections (A-E). The questions cover topics such as defining regular expressions for specific languages over alphabets like {a,b}, proving languages can be defined by regular expressions if finite, constructing regular expressions that match certain string properties, and describing languages associated with given regular expressions.

Uploaded by

Biya Hassan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Quiz # 3

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)

(aa + bb + (ab + ba)(aa +bb)*(ba +ab) )* (b + (ab +ba)(bb + aa)* a )


(aa + bb + (ab + ba)(aa +bb)*(ba +ab) )* (ab +ba)(bb + aa)*

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.

You might also like