Mid semexam | Theory of Computation | Akash Anand | MTH 401A | IIT Kanpur
1. MTH 401: Theory of Computation September 17, 2016
Department of Mathematics and Statistics Time: 120 minutes
Indian Institute of Technology - Kanpur Maximum Score: 30
Mid-semester Examination
1. Indicate whether following statements are true or false. Justify your answer (to justify
a claim that a statement is true, an (informal) proof is required; to justify a claim
that a statement is false, a single counterexample is sufficient.) Note that no credit
will be given to a correct guess without any explanation or followed by an
incorrect justification.
(a) The union of a context free language with a regular language is a context free
language. [1]
Solution: True. Regular languages are context free and context free languages
are closed under union.
(b) The regular sets are closed under countable unions. [1]
Solution: False. The sets Rn = {0n
1n
} are regular for all n ∈ N but n∈N Rn =
{0n
1n
: n ≥ 0} is not regular.
(c) Let L1, L2 ⊆ Σ∗
. If either L1 or L2 is not regular then L1L2 is not regular. [1]
Solution: False. L1 = L(0∗
) and L2 = {0p
| p is a prime}. Clearly, L1L2 =
L(0∗
) { , 0, 00} is regular whereas L2 is not regular.
(d) Let L ⊆ Σ∗
. If L∗
= ∅, then L = ∅. [1]
Solution: False. An equivalent statement is: if L = ∅, then L∗
= ∅. Clearly
false, as ∈ L∗
even when L = ∅.
(e) If a and b are letters in an alphabet, then L((a∗
b∗
)∗
) = L((a + b)∗
). [1]
Solution: True. w ∈ L((a∗
b∗
)∗
) ⇐⇒ there are integers m1, . . . , mk ≥ 0, and
n1, . . . , nk ≥ 0 for some k ≥ 0 such that w = an1
bm1
. . . ank bmk ⇐⇒ w ∈ L((a +
b)∗
).
2. 2
2. Let Σ be an alphabet.
(a) For any string w ∈ Σ∗
, define formally the reversal of a string w, denoted by
wR
. [2]
Solution: A definition using induction of the length of the string is given as
follows:
i. If w is a string of length 0, then wR
= w = ε (the empty string).
ii. If w is a string of length n + 1 > 0, then w = ua for some u ∈ Σ∗
, a ∈ Σ and
wR
= auR
.
(b) For any strings w, x ∈ Σ∗
, prove that (wx)R
= xR
wR
. [3]
Solution: Proof by induction on the length of x:
Basic Step: |x| = 0. Then x = ε, and (wx)R
= wR
= εwR
= εR
wR
= xR
wR
.
Induction Hypothesis: If |x| ≤ n, then (wx)R
= xR
wR
.
Induction Step: Let |x| = n + 1. Then w = ua for some u ∈ Σ∗
and a ∈ Σ such
that |u| = n.
(wx)R
= (w(ua))R
= ((wu)a)R
= a(wu)R
(by the definition of the reversal)
= auR
wR
(by the induction hypothesis)
= (ua)R
)wR
(by the definition of the reversal)
= xR
wR
.
3. Show that the set {w ∈ {a}∗
: |w| = p for some prime p} is not regular. [6]
Solution: Let n > 0 and w = aq
where q > n is a prime. Consider any x, y, z ∈ {a}∗
such that w = xyz with |xy| ≤ n and |y| > 0. Then, y = ak
for some 1 ≤ k ≤ n < q.
Now, for i = q − k, we have
xyi
z = xyq−k
z = a(q−k)k+(q−k)
= a(q−k)(k+1)
.
Clearly, (q − k)(k + 1) is not a prime and consequently xyq−k
y ∈ L := {w ∈ {a}∗
:
|w| = p for some prime p}. Thus, L is not regular.
4. Convert the deterministic finite state machine shown below
3. 3
into a machine with minimal number of states. (Show all work. No partial cred-
its.) [7]
Solution: States A, E, are equivalent, states D, F are equivalent and states B, H
are equivalent. Collapsing them together and redrawing the given finite state machine
gives us the representation shown below.
5. L = {ai
bj
ck
d | i, j, k, ≥ 0, i + j ≤ k}.
(a) Write a CFG G with L(G) = L. [3]
4. 4
Solution: By setting k = i + j + m, m ≥ 0, we see that
L = {ai
bj
cm
cj
ci
d | i, j, m, ≥ 0}.
Now it is easy to write a CFG G = ({0, 1}, {S, A, B, C, D}, S, P) with productions
in P are given by :
S −→ AD
A −→ aAc | B
B −→ bBc | C
C −→ cC |
D −→ dD |
and see that L(G) = L.
(b) Design a pushdown machine M with L(M) = L. [3]
Solution: One way to construct a pushdown machine would be to start from
scratch and design a machine that will accept L. But since we already have a
CFG for L, it is easier to use CFG-to-PDM conversion procedure to construct the
following PDM, M = ({0, 1}, {q}, {0, 1, S, A, B}, q, S, δ, {}) that accepts strings
by emptying the stack and where δ is given by :
δ(q, 0, 0) = {(q, )}
δ(q, 1, 1) = {(q, )}
δ(q, , S) = {(q, AD)}
δ(q, , A) = {(q, aAc), (q, B)}
δ(q, , B) = {(q, bBc), (q, C)}
δ(q, , C) = {(q, cC), (q, )}
δ(q, , D) = {(q, dD), (q, )}.
(c) Is the machine you designed in (b) a deterministic pushdown machine? [1]
Solution: No. There are multiple actions for δ(q, , A), and others.