Professional Documents
Culture Documents
Assgn2 Sols
Assgn2 Sols
R = 0∗ + 1∗
S = 01∗ + 10∗ + 1∗ 0 + (0∗ 1)∗
1
3. For each of the DFA’s A, B, C below, use the state elimination technique to obtain an equivalent
regular expression.
A a b B a b C a b c
→ q0 q1 q2 → q0 q1 q2 → q1 q6 q2 q4
q1 q1 q2 q1 q0 q2 q2 q3 q6 q6
q2 q3 q4 ⋆q2 q1 q0 q3 q4 q5 q6
⋆q3 q5 q5 q4 q2 q6 q5
⋆q4 q5 q5 ⋆ q5 q6 q6 q6
q5 q5 q5 q6 q6 q6 q6
Solution:
DFA A as a transition diagram with transitions labelled by regex’s (trap state q5 omitted):
q3
a
q2 b q4
b
b
q0 a q1
start
q3
q0 aa∗ b + b q2 b q4
Now remove q2 :
q3
(a+ b + b)a
start q0
(a+ b + b)b
q4
2
DFA B as a transition diagram with transition labelled by regex’s
q1
a b
a a
b
start q0 q2
b
eliminate state q1 :
ab + b
start q0 q2
aa + b
aa ab
3
DFA C as a transition diagram with transitions labelled by regex’s (after eliminating trap
state q6 ):
q2 a q3
start q1 a b
a
q4 c q5
Eliminate state q2
q1 ba q3
start
c aa b
a
q4 c q5
Eliminate state q3
start q1
bab
c + baa
q4 c + aab q5
aaa
Eliminate state q4
4
4. Convert the following regular expressions to -NFA’s.
0 0 0 q
start
q 1 1 1 p
0 0 1
p 1 1 1
5
(b) (01 + 10)∗ + (00 + 11)∗ + (1 + 10 + 100)∗
Solution:
0 1
1 0
0 0
p
start
1 1
1
1 0
1 0 0
6
5. Using the method of Theorem 3.14 to prove of disprove each of the following statements about
regular expressions.
(a) R(S + T ) = RS + RT .
Solution:
Identity is true. We consider a(b + c) and ab + ac
L(a(b + c)) = {a}({b} ∪ {c}) = {a}{b, c} = {ab, ac} = ab + ac
(b) (R + S)∗ = (R∗ S ∗ )∗
Solution:
Identity is true. We consider (a + b)∗ and (a∗ b∗ )∗
If w ∈ L((a + b)∗ ), then
w = x1 x2 . . . x k ,
where each xi ∈ {a, b} and k ≥ 0. Consider u = y1 y2 . . . yk , where yi = a1 b0 if xi = a, and
yi = a0 b1 if xi = b. Clearly u = w and u ∈ L(a∗ b∗ )∗
To see inclusion in the other direction, note that L((a + b)∗ ) = {a, b}∗ (= the set of all
strings over {a, , b}). Consequently L((a∗ b∗ )∗ ) ⊆ L((a + b)∗ )
(c) (R + S)∗ = R∗ + S ∗ .
Solution:
Identity is false. We consider (a + b)∗ and a∗ + b∗
We have for instance ababab ∈ L((a + b)∗ ), but ababab ∉ L(a∗ + b∗ ).
(d) (RS + R)∗ RS = (RR∗ S)∗ .
Solution:
Identity is false. We consider (ab + a)∗ ab and (aa∗ b)∗ .
We have for instance ∈ L((aa∗ b)∗ ), but ∉ L((ab + a)∗ ab).
7
6. For each of the following languages apply the Pumping Lemma to show that the language is
not regular.
In all cases start with the following:
Suppose to the contrary that L is regular
⇒ ∃ DFA A, s.t. L(A) = L. Let p be the number of states in A.
⇒ ∀w ∈ L(A), if ∣w∣ ≥ p, then w = xyz, where ∣xy∣ ≤ p, ∣y∣ = k ≥ 1, and xy i z ∈ L(A) for all i ≥ 0.
(a) The set of all binary strings with an equal number of occurrences of substrings 01 and
10 where overlapping substrings are not allowed. For instance 01010 is not accepted, but
011010001 is accepted.
Solution:
Solution that assumes non-ovelapping substrings:
Choose
w = 0101 . . . 01 00 1010 . . . 10
´¹¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¸ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¶ ´¹¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¸ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¶
p p
Then
xz = . . . 01010 . . . 00 1010 . . . 10
´¹¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹¸¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¶ ´¹¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¸ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¶
p−k p
w = aa . . . a aa . . . a
´¹¹ ¹ ¹ ¸
p
¹ ¹ ¹ ¹ ¶ ´¹¹ ¹ ¹ ¸
p
¹¹¹¹¶
2 2
Then
xz = aa . . . a aa . . . a
´¹¹ ¹ ¹ ¸ ¹ ¹ ¹ ¹ ¶ ´¹¹ ¹ ¹ ¸
p
¹¹¹¹¶
m 2
8
(c) {an bm ak ∶ n = m or m = k}.
Solution: Choose
w = aa . . . a bb . . . b
´¹¹ ¹ ¹ ¸ ¹ ¹ ¹ ¹ ¶ ´¹¹ ¹ ¸¹ ¹ ¹¶
p p
Then
xz = aa . . . a bb . . . b
´¹¹ ¹ ¹ ¸ ¹ ¹ ¹ ¹ ¶ ´¹¹ ¹ ¸¹ ¹ ¹¶
p−k p
9
7. (a) Construct NFA’s A and B, such that L(A) = L(ab∗ a∗ ), and L(B) = L(a∗ b∗ a).
Then use these NFA’s to construct an NFA C, such that L(C) = L(A) ∩ L(B).
b a
Solution:
q0 a q1 a q2
NFA A: start
a b
p0 p1 a p2
NFA B: start
NFA C: a
start (q0 , p0 ) (q0 , p1 ) (q0 , p2 )
b
a a a
a
(q1 , p0 ) (q1 , p1 ) (q1 , p2 )
a a a a
a
a (q2 , p0 ) (q2 , p1 ) (q2 , p2 )
(b) Suppose h is the homomorphism from {0, 1, 2} to {a, b}∗ defined by h(0) = a, h(1) = b, and
h(2) = ba.
i. What is the string h(21120)?
Solution: h(21120) = h(2).h(1).h(1).h(2).h(0) = babbbaa
ii. What is the language h(L(0 + 1∗ 2))?
Solution: h(L(0 + 1⋆ 2)) = L(h(1 + 1⋆ 2)) = L(h(1) + (h(1))⋆ h(2)) = L(b + (b⋆ ba))
iii. Let L = {ba}. What is the language h−1 (L)?
Solution: h−1 (L) = {10, 2}.
10
8. Draw the table of distinguishabilities for the DFA below (i.e., run the TF algorithm), and then
construct the minimum state equivalent DFA.
0 1
→ A B E
B C F
*C D H
D E H
E F I
*F G B
G H B
H I C
*I A E
Solution:
1
0,1
start {A, D, G} {B, E, H} {C, F, I}
0,1
11