0% found this document useful (0 votes)
17 views5 pages

ToC - Sheet 3

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

ToC - Sheet 3

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

Helwan University First Term, Academic Year 2020/2021

Faculty of science M 416 - Theory of Computations


Math. Department Sheet3 - solution
For 4th year st of math

First: Choose the correct answer

1. (True or False ):Regular languages are closed under Concatenation


(a)True (e) False

2. (True or False ): Regular languages are closed under Kleene’s star


(a)True (e) False

3. (True or False ): Regular languages are closed under Complement


(a)True (e) False

Directions for Question 4 and 5: Consider the following NFA with E moves.

4. If the given NFA is converted to NFA without E -moves, which of the following denotes the set
of final states?
(a) {q2} (b) {q1, q2}
(c) { q0, q1, q2} (d) Can't be determined

5. Which of the following strings will not be accepted by the given NFA?
(a) 00 11 22 (b) 11 22
(c) 21 (d) 22

6. Which of the following regular expression corresponds to the language of all strings over the
alphabet {a, b} that do not end with ab?
(a) (a + b)* (aa + ba + bb)
(b) (a + b)* (aa + ba + bb) + a + b + ϵ
(c) b* ab* a
(d) b* aa b*

7. Consider the following reguiar expression:


R = (ab| abb)* bbab
Which of the following strings is NOT in the set
(a) abababb (b) ababbabbbab
(c) bbab (d) abbabbbab
Directions for Question 8, 9 regarding Regular Expression (RE)

8. Strings having exactly one occurrence of ab and ba


(a) (a + b)* (ab + ba) (a + b)*
(b) (ab)+ (a + b)* (ba)+
(c) Both ( a) and ( b)
(d) None of the above

9. Strings having at most one occurrence of ab or ba but not both


(a) a* b* + b* a* (b) b* ab + a* ba
(c) Both (a) and (b) (d) None of these

10. The given transition table is for the FSM that accepts a string if it ends with ' aa' .
Which is the final state?

S a b
Start q0 q2
q0 q1 q2

ql q1 q2

q2 q0 q2

(a) q0 (b) q1
(c) q2 (d) Can't be determined

Second : Answer the following


1) Describe in English, as briefly as possible, the language defined by each of these regular expressions:
(a) (b ∪ ba) (b ∪ a)* (ab ∪ b).
(b) (((a*b*)*ab) ∪ ((a*b*)*ba))(b ∪ a)*.

2) Write a regular expression to describe each of the following languages:


(a) {w ∈ {a, b}* : every a in w is immediately preceded and followed by b}.
(b) {w ∈ {a, b}* : w does not end in ba}.
(c) {w ∈ {0, 1}* : ∃y ∈ {0, 1}* (|xy| is even)}.
(d) {w ∈ {0, 1}* : w corresponds to the binary encoding, without leading 0’s, of natural numbers
that are evenly divisible by 4}.
(e) {w ∈ {0, 1}* : w corresponds to the binary encoding, without leading 0’s, of natural numbers
that are powers of 4}.
(f) {w ∈ {0-9}* : w corresponds to the decimal encoding, without leading 0’s, of an odd natural
number}
(g) {w ∈ {0, 1}* : w has 001 as a substring}.
(h) {w ∈ {0, 1}* : w does not have 001 as a substring}.
(i) w ∈ {a, b}* : w has bba as a substring}.
(j) {w ∈ {a, b}* : w has both aa and bb as substrings}.
(k) {w ∈ {a, b}* : w has both aa and aba as substrings}.
(l) {w ∈ {a, b}* : w contains at least two b’s that are not followed by an a}.
(m) {w ∈ {0, 1}* : w has at most one pair of consecutive 0’s and at most one pair of consecutive
1’s}.
(n) {w ∈ {0, 1}* : none of the prefixes of w ends in 0}.
(o) {w ∈ {a, b}* : #a(w) ≤ 3}.
(p) {w ∈ {a, b}* : w contains exactly two occurrences of the substring aa}.
(q) {w ∈ {a, b}* : w contains no more than two occurrences of the substring aa}.
(r) {w ∈ {a, b}* - L}, where L = {w ∈ {a, b}* : w contains bba as a substring}.
(s) {w ∈ {0, 1}* : every odd length string in L begins with 11}.
(t) {w ∈ {0-9}* : w represents the decimal encoding of an odd natural number without leading
0’s.
(u) L1 – L2, where L1 = a*b*c* and L2 = c*b*a*.
(v) The set of legal United States zipcodes.
(w) The set of strings that correspond to domestic telephone numbers in your country.

3) Simplify each of the following regular expressions:


(a) (a ∪ b)* (a ∪ ε) b*.
(b) (∅* ∪ b) b*.
(c) (a ∪ b)*a* ∪ b.
(d) ((a ∪ b)*)*.
(e) ((a ∪ b)+)*.
(f) a ( (a ∪ b)(b ∪ a) )* ∪ a ( (a ∪ b) a )* ∪ a ( (b ∪ a) b )*.

4) For each of the following expressions E, answer the following three questions and
prove your answer:
i) Is E a regular expression?
ii) If E is a regular expression, give a simpler regular expression.
iii) Does E describe a regular language?

a) ((a ∪ b) ∪ (ab))*.
b) (a+ anbn).
c) ((ab)* ∅).
d) (((ab) ∪ c)* ∩ (b ∪ c*)).
e) (∅* ∪ (bb*)).

5) Let L = {anbn : 0 ≤ n ≤ 4}.


a) Show a regular expression for L.
b) Show an FSM that accepts L.

6) let L = {w ∈ {1, 2}* : for all prefixes p of w, if |p| > 0 and |p| is even, then the last
character of p is 1}.
a) Write a regular expression for L.
b) Show an FSM that accepts L.

7) Use the algorithm presented in the proof of Kleene’s theorem to construct an


FSM to accept the languages generated by the following regular expressions:
a) (b(b ∪ ε)b)*.
b) bab ∪ a*.
8) Let L be the language accepted by the following finite state machine:

Indicate, for each of the following regular expressions, whether it correctly describes L:
a) (a ∪ ba)bb*a.
b) (ε ∪ b)a(bb*a)*.
c) ba∪ ab*a.
d) (a ∪ ba)(bb*a)*.

9) Consider the following FSM M:

The first printing of the book has two mistakes in this figure: The transition from q2 back to q0 should be
labeled a, and state q3 should not be accepting. We’ll give answers for the printed version (in which we’ll
simply ignore the unlabeled transition from q2 to q0) and the correct version.
a) Show a regular expression for L(M).
b) Describe L(M) in English.

10) Show a possibly nondeterministic FSM to accept the language defined by each
of the following regular expressions:
a) (((a ∪ ba) b ∪ aa)*.
b) (b ∪ ε)(ab)*(a ∪ ε).
c) (babb* ∪ a)*.
d) (ba ∪ ((a ∪ bb) a*b)).

11) Show a DFSM to accept the language defined by each of the following regular
expressions:
a) (aba ∪ aabaa)*
b) (ab)*(aa)

You might also like