Assgn1 Sols
Assgn1 Sols
Assgn1 Sols
ϵR = ϵ, (wa)R = a(wR ).
Solution:
By induction on length of v,
Basis: if |v| = 0 then v = ϵ, and (uv)R = (uϵ)R = (u)R = uR = ϵuR = ϵR uR .
IH: If |v| = n we have (uv)R = v R uR
IS: Now we show that if |v| = n + 1 then the claim in the inductive hypothesis
is also true.
|v| = n + 1 ⇒ v = xa, where |x| = n and a ∈ Σ.
Then (uv)R = (uxa)R = a(ux)R = a(xR uR ) = (axR )uR = (xa)R uR = v R uR .
2. Let Σ = {a, b}. For each of the languages below, give an example of a string in
the language, and a string not in the language.
(b) L2 = {w ∈ Σ∗ : ww = www}
Solution:
w = ϵ ∈ L2 , since ww = ϵ = www
w = aa ∈/ L2 , since ww = aaaa ̸= aaaaaa = www
a b
b b a
q1 q2 q3 q4
a b
a
a, b
q4
(b) {w ∈ {a, b}∗ : bab is not a substring of w}
a b b
b a
q1 q2 q3
a
(c) The set of strings that either begin or end (or both) with ab.
a b
q1 q2 q3
b a a, b
a
q4 q5
b
b a
a
b q6
(d) {w ∈ {a, b}∗ : w contains an odd number of a′ s and ends in at least two b′ s}
b
q
a a
a a
b
p r s
b
b
a b
→q p q
Give your DFA’s as transition diagrams. p q r
r q s
∗s q s
4. Let L = {w ∈ {0, 1}∗ : w has an odd no. of 1’s }, and let A be the DFA with
tabular representation:
A 0 1
→p p q
⋆q q p
Prove that L = L(A). Hint: Do the L(A) ⊆ L part of the proof by induction
on the the length of the string processed by A. You need a mutual induction
with a claim for state p and a claim for state q.
Solution:
To prove w ∈ L(A) ⇒ w ∈ L we use an induction on length of w. We claim
that
(1) If δ̂(p, w) = p, then w has even number of 1’s.
(2) If δ̂(p, w) = q, then w has odd number of 1’s.
Basis: |w| = 0 then w = ϵ, so obviously (1) is true. Also, it is clear that
δ̂(p, ϵ) = p ̸= q, so (2) is vacuously true.
IH: (1) and (2) are true for any string w of length n.
IS: Now prove (1) and (2) for w = xa, where |x| = n and a ∈ Σ.
(1): If δ̂(p, xa) = p then δ̂(p, x) is p and a = 0 or q and a = 1, as can be seen
from the transition diagram of A.
If δ̂(p, x) = p then by the IH (1), the string x has even number of 1’s. Therefore
w = x0 which has even number of 1’s.
If δ̂(p, x) = q then by the IH (2), the string x has odd number of 1’s, so w = x1
has even number of 1’s.
(2): If δ̂(p, xa) = q then δ̂(p, x) is p and a = 1 or q and a = 0, as can be seen
from the transition diagram of A.
If δ̂(p, x) = p then by the IH (1), the string x has even number of 1’s. Therefore
w = x1 which has odd number of 1’s.
If δ̂(p, x) = q then by the IH (2), the string x has odd number of 1’s, so w = x0
has odd number of 1’s. This completes induction.
For the other direction, we have:
w ̸∈ L(A) ⇒ δ̂(p, w) = p
⇒ w has even number of 1’s
⇒ w ̸∈ L
So it never ends in a final state with an even number of 1’s. Therefore, this
direction is also proved, that is L ⊆ L(A).
5. Construct an NFA for each of the following languages.
(a) The set of strings over {0, 1, . . . , 9}, such that the final digit has not ap-
0, ..., 8
q9
0, .., 7&9
q8
0, ..., 6&8, 9
9
q7 8
0, ..., 8 0, ..., 5&7, ..., 9
0, .., 7&9 7
0, ..., 6&8, 9 q6
0, ..., 5&7,peared
..., before
9 6
0, ..., 9
0, ..., 4&6, ..., 9
qs q5 qf
0&2, ..., 9
q0
1, .., 9
(b) The set of strings over {0, 1}, such that there are two 0’s separated by a
number of positions that is a multiple of 4. Note that 0 is an allowable
multiple of 4.
0, 1 0, 1
0 0
q0 q1 q2
0, 1
0, 1
q4 q3
0, 1 0, 1
q3
6. Let Σ = {a, b}.
(a) Construct an NFA that accepts the strings in Σ∗ where at least one of the
last two symbols is an a.
a, b
a a, b
q0 q1 q2
a, b a
q3
(b) Convert your NFA to a DFA using the subset construction. Give the DFA
b b
A B E
b b
a
a b
a
C
a D
a
both in tabular form and as a transition diagram.
a b
→A C B
B D C
C D E
∗D D E
∗E D B
A = {q0 }
B = {q0 , q2 }
C = {q0 , q1 , q2 }
D = {q0 , q1 , q2 , q3 }
E = {q0 , q2 , q3 }
(a) The set of string that consists of either 01 repeated one or more times or
q2
0 1
0, 1
A
0, 1 1
L 1 B
0, 1 0, 1
M 1 C
0, 1 0, 1
N 1 D
0, 1 0, 1
O 1 E
0, 1 0.1
P 1 F
0, 1 0, 1
Q 1 G
0, 1 0, 1
R 1 H
0, 1 0, 1
S 1 I
0, 1 0, 1
T 1 J
0, 1
K