Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Assgn1 Sols

Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

Concordia University

Theoretical Computer Science


Solution to Assignment 1
Winter 2015

1. The reversal of a string w, denoted by wR , is the string “spelled backwards”.


For example (cat)R = tac. Reversal is defined inductively as follows:

ϵR = ϵ, (wa)R = a(wR ).

(Here a is a symbol in the alphabet Σ, and w is a string in Σ∗ .)


Let u, v ∈ Σ∗ . Prove that
(uv)R = v R uR .
Hint: Use induction on |v|.

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.

(a) L1 = {w ∈ Σ∗ : w = uuR u, for some u ∈ Σ2 }


Solution:
w = aaaaaa ∈ L1 , since u = aa ⇒ w = uuR u
w = aa ∈/ L1 , since @u ∈ Σ2 such that w = aa = uuR u

(b) L2 = {w ∈ Σ∗ : ww = www}
Solution:
w = ϵ ∈ L2 , since ww = ϵ = www
w = aa ∈/ L2 , since ww = aaaa ̸= aaaaaa = www

(c) L3 = {w ∈ Σ∗ : uvw = wvu, for some u, v ∈ Σ∗ }.


Solution:
w = ab ∈ L3 , since u = ab, v = aba ⇒ uvw = ababaab = wvu.
L3 = Σ∗ , since for any w, we can choose u = w and v = ϵ.

(d) L4 = {w ∈ Σ∗ : www = uu, for some u ∈ Σ∗ }.


Solution:
w = aa ∈ L4 , since u = aaa ⇒ www = aaaaaa = uu.
w=a∈ / L4 , since www = aaa and @u such that uu = aaa.
3. Construct a DFA for each of the following languages.

(a) {w ∈ {a, b}∗ : bb appears at most once as a substring of w}


a, b
q5

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, ..., 4&6, ..., 9 5


q4
0, ..3&5, .., 9 4
0, 1, 2&4, ..., 9 0, ..3&5, .., 9 3
0, 1&3, ..., 9 q3
0&2, ..., 9 2
1, .., 9 0, 1, 2&4, ..., 9
q2 1
0
0, 1&3, ..., 9
q1

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 }

7. Let Σ = {0, 1}. Design ϵ-NFA’s for the following languages.

(a) The set of string that consists of either 01 repeated one or more times or

q2
0 1

010 repeated one or more times. q1 q3


ϵ ϵ
q0 q7
ϵ 0
ϵ
q4 q5 q6
0 1
(b) The set of strings such that at least one of the last ten positions is a 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

You might also like