0% found this document useful (0 votes)
8 views

Theory Lab#2

The document discusses regular languages and regular expressions. It covers operations on regular languages like union and concatenation. It also covers describing languages from regular expressions and grammars, converting between regular expressions and grammars, describing languages in English from regular expressions, and determining if pairs of regular expressions are equivalent.

Uploaded by

m.a7med82002
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Theory Lab#2

The document discusses regular languages and regular expressions. It covers operations on regular languages like union and concatenation. It also covers describing languages from regular expressions and grammars, converting between regular expressions and grammars, describing languages in English from regular expressions, and determining if pairs of regular expressions are equivalent.

Uploaded by

m.a7med82002
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Cairo University

Faculty of Computers & Artificial Intelligence


Theory of Computations

Lab#2

Section#1: Operations on Regular Languages:


Example: L1 = {a, bc}, L2 = {x, yz}
1. L1 U L2 (Union)
2. L1 ∩ L2 (intersection)
3. L1 L2 (concatenation)
4. L1 * (star)

➞ Solution :
1. L1 U L2 = {a, bc, x, yz}
2. ∅
3. L1 L2 = {ax, ayz, bcx, bcyz}
4. L1 * = {λ, a, bc, aa, bcbc, abc, ….}
Section#2: Describe the language, given a RE:
1. (a+bc) *
2. (a+b) . a*
3. (a+b)*a(a+b)*
➞ Solution :
1. {λ, a, bc, aa, abc, bca, …}
2. {a, aa, aaa,..., b, ba, baa,...}
Language will start with a single a or b, then zero or more (𝑎)𝑠

3. {a, ab, aab, bab, abb …..}


Language with have at least one a

Section#3: Describe the language, given a


grammar G:
1. G =({S}, {a, b}, S, P) Where P S-> aSb
S -> Λ

2. G =({S, X}, {a, b, c}, S, P) Where P S-> aSb | X


X -> cX | Λ

3. G =({S}, {a}, S, P) Where P S-> aS | a

➞ Solution :
𝑛 𝑛
1. L(G) = {𝑎 𝑏 : n>= 0}
𝑛 𝑚 𝑛
2. L(G) = {𝑎 𝑐 𝑏 : n>=0 and m>=0}
𝑛
3. L(G) = {𝑎 : n>0}
Section#4: Convert to RE:
When Σ ={a, b}
1. all words starts with “a” followed by any number of b’s
2. all words starts with “a” followed by one or more b’s
3. the language that contains nothing and contains words where any “a”
must be followed by one or more b’s
4. all words where a’s (if any) followed by b’s (if any) .
5. all words with length three and find their count
6. all words with exactly two a's
7. all words with at least two a's
When Σ = {a, b, c}
8. all words where single “a '' or “c” comes in the start then an odd
number of b’s.
9. all words where a single “a '' or “c” comes in the start then an odd
number of b’s in case of “a'' and zero or even number of b’s in case of
c.
10. all words where one or more “a” or one or more “c” comes in the
start then one or more b’s.
When Σ ={0, 1}
11. all strings with no two consecutive 0’s
12. all strings with at least two consecutive 0’s
➞ Solution :

1. ab* = {a, ab, abb, abbb…..}


2. abb* = {ab, abb, abbb…..}
3. (b+ab)* = {Λ, ab, abb, abababb, ….. b, bbb…}
4. a*b* = {Λ, a, b, aa, ab, bb, aaa, abb, abbb, bbb, …..}
5. (a+b) (a+b) (a+b) = {aaa, aab, aba, abb, baa, bab, bba, bbb}
3
Count = 2 = 8
6. b*a b* a b* = {aa, aab, baba, and bbbabbbab …..}
7. b*a b* a (a + b)* = {abbbabb, aaaaa, bbbabbbbabab…..}
8. (a+c)b(bb)* = {ab, cb, abbb, cbbb…..}
9. ab(bb)*+c(bb)* = {ab, c, abbb, cbb, abbbbb…..}
10. (aa*+cc*) bb* = {ab, cb, aabb, cbbb …..}
11. (1+01)* (0+λ)
12. (0+1)* 00 (0+1)*
Section#5: Describe in English the languages
represented by the following RE:
1. baa + abbb + bababa
2. ((a+b)a)*
3. (a + b)*a(Λ + bbbb)
4. (a + b)*(aa + bb)(a + b)*

➞ Solution :
1. Accepts any of the three strings
2. Any word ends with a , Λ is included (empty word)
3. Any word has at least one “a” and ends with “a” or “bbbb”
4. Any word has the substring “aa” or “bb”
Section#6: State whether each pair of regular
expressions are equivalent or not:
1. (a+b*)* and (a+b)*
2. a*b* and (ab)*
3. bb*aa* and b*a*
4. (a+b)*b(a+b)*a(a+b)* and bb*aa*

➞ Solution :
1. True
2. False, abab from (ab)* can’t be generated from a*b*
3. False, aaa from b*a* can’t be generated from bb*aa*
4. False, aba from (a+b)*b(a+b)*a(a+b)* can’t be generated from bb*aa*

You might also like