Solution

advertisement
Name Surname:
ID:
Duration: 110 mins
CENG 304 MIDTERM I
1.
Consider the following FA:
a) Describe in English the language L accepted by the
b) Use your description in part (a), write a regular expression for the language L.
Solution:
Second state is initial
(a) The above FA accepts the language L of all odd length words over {a, b} that end with an a.
(b) A regular expression for the language L is
(aa + ab + ba + bb)*a
OR
First state is initial
(a+b) (b(a+b))*a((a+b)a)* (Even length strings that end with a.)
2. Show whether or not the following two regular expressions define the same language:
(a + b)*ba(a + b)* + ab* and (a + b)(a + b)*
Solution:
First, note that (a+b)(a+b)* represents all possible non-empty words of a's and b's.
The regular expression (a + b)*ba(a + b)* represents all the words containing the substring ba. Compared
with all possible non-empty words of a's and b's, there are three types of words missing:
(i) words of all a's,
(ii) words of all b's, and
(iii) words in which all a's precedes all b's. However, not all of these can be generated by ab*. For example,
the word aabb is not in the language defined by (a + b)*ba(a + b)* + ab*, but it is in the language defined by
(a + b)(a + b)*.
Hence, these two regular expressions do NOT defined the same language.
3.
Solve the followings:
a. Let S = {ab; bbg and let T = {ab, bb, bbbb}. Show that S* = T*.
Solution:
a) S
T, so S*
T*. bbbb is the only word in T but not in S. However, bb 2 S, so bbbb 2 S* and T*
S*. Hence, S* = T*.
4.
Solve the followings:
a. Build an FA with three states that accepts all strings over the alphabet § = {a, b}
An FA with three states that accepts all strings:
5.
An FA with four states was sitting unguarded one night when vandals came and stole an edge labeled a.
What resulted was a TG that accepted exactly the language b*. In the morning the FA was repaired, but
the next night vandals stole an edge labeled b and what resulted was a TG that accepted a*. The FA was
again repaired, but this time the vandals stole two edges, one labeled a and one labeled b, and the
resultant TG accepted the language a* + b*.
a. What was the original FA?
b. Clearly identify the stolen edges (e.g., which edge was stolen on night 1? On night 2? and
which two edges were stolen on night 3?).
The original FA was as follows:
The edge labeled a connecting state 1 and state 2 was stolen on night 1.
The edge labeled b connecting state 1 and state 4 was stolen on night 2.
The edge labeled a connecting state 4 and state 3, and the edge labeled b connecting state 2 and state 3 were
the two edges stolen on night 3.
Download