This document contains the details of an end-semester examination for an undergraduate course on Theory of Computation. The exam consists of 10 multiple choice and justification questions (Part 1) and 2 longer proof questions (Parts 2 and 3). Part 1 asks students to determine whether statements about formal language classes are true or false and provide justifications. Part 2 asks students to prove that a particular language defined using pushdown automata is not context-free. Part 3 asks students to design an algorithm to show that a language involving matching strings is recursive.
End semexam | Theory of Computation | Akash Anand | MTH 401A | IIT Kanpur
1. MTH 401: Theory of Computation April 22, 2014
Department of Mathematics and Statistics Time: 180 minutes
Indian Institute of Technology - Kanpur Maximum Score: 40
End-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 language {0, 1}∗
is countable. [1]
True. Clearly,
{0, 1}∗
=
∞
n=0
{w ∈ {0, 1}∗
: |w| = n},
is a countable union of finite sets, and therefore, countable.
(b) The regular expression 0∗
(100 + 010 + 001)0∗
generates the language {w | w ∈
{0, 1}∗
and w contains at least two 0s and at most one 1}. [1]
False. Clearly, a string generated by the given regular expression always contains
exactly one 1.
(c) If a language is accepted by a non-deterministic finite state machine, then it is
clearly context-free. [1]
True. A language that is accepted by a non-deterministic FSM is regular, and
all regular languages are context-free.
(d) If L1L2 is regular then L1 and L2 are both regular. [1]
False. L1 = L(0∗
) and L2 = {0p
| p is a prome}. Clearly, L1L2 = L(0∗
){ , 0, 00}
is regular whereas L2 is not regular.
(e) If L∗
= ∅, then L = ∅. [1]
False. An equivalent statement is: if L = ∅, then L∗
= ∅. Clearly false, as ∈ L∗
even when L = ∅.
(f) If a and b are letters in an alphabet, then (a∗
b∗
)∗
= (a + b)∗
. [1]
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)∗
).
(g) The language given by {w ∈ {0, 1}∗
| n0(w) = n1(w)}, where na(w) denotes the
number of occurrences of the symbol a in w, is a context free language. [1]
True. {w ∈ {0, 1}∗
| n0(w) = 2n1(w)} = L(G) where G = ({0, 1}, {S}, S, {S →
0S0S1 | 0S1S0 | 1S0S0}).
2. 2
(h) Let L be a language over the alphabet {0, 1}. If L∗
is regular, then L is also
regular. [1]
False. Let L = {0, 1} ∪ {0n
1n
| n ≥ 0}. Then L∗
= {0, 1}∗
is clearly regular
where as L is not regular.
(i) The set of Turing machines over a given alphabet that do not accept any even
length palindrome is decidable. [1]
False. By Rice’s Theorem.
(j) If L1 is Recursive and L2 is PSPACE-complete then there is a reduction from
L1 to L2. [1]
False. For example, any recursive language in EXP that is not in PSPACE can
not be reduced to a PSAPCE-complete language.
2. Let P be the set of all pushdown machines and e : P → {0, 1}∗
be a given function.
Let L = {w ∈ Σ∗
| w ∈ L(w)}, where L(w) = L(P) if w = e(P). Note that L(w) = ∅
if w ∈ e(P). Show that L is not a context free language. [10]
Solution: Suppose L is context free. Then, there is a pushdown machine P0 such that
L = L(P0). Let w0 = e(P0). If w0 ∈ L = L(P0) = L(w0), then, by definition of L,
w0 ∈ L. A contradiction. Similarly, if w0 ∈ L = L(P0) = L(w0), then, by definition of
L, w0 ∈ L. Again a contradiction. Thus, L is not context free.
3. Let Σ = {a}. Suppose L0 = {(x1, y1), (x2, y2), . . . , (xn, yn) | xi, yi ∈ Σ∗
} be a language
over the alphabet Σ0 = Σ ∪ {(} ∪ {)} ∪ {, } and
LPCP = {(x1, y1), . . . , (xn, yn) ∈ L0 |
there exists (i1, . . . , im) with 0 ≤ il ≤ n such that xi1 · · · xim = yi1 · · · yim }.
Show that LPCP is recursive. [10]
Solution: In order to show that LPCP is recursive, we need to provide a membership
algorithm. Note that every p = (x1, y1), (x2, y2), . . . , (xn, yn) ∈ L0 is of the form
p = (al1
, am1
), (al2
, am2
), . . . , (aln
, amn
) for some l1, l2, . . . , ln and m1, m2, . . . , mn.
Thus, given any p = (al1
, am1
), (al2
, am2
), . . . , (aln
, amn
) ∈ L0, the following algorithm
decides its membership to LPCP :
Step 1: For each i = 1 to n, compute di = li − mi.
Step 2: If for all i0 ∈ {1, 2, . . . , n}, di > 0, then p ∈ LPCP .
Step 3: Else if for all i0 ∈ {1, 2, . . . , n}, di < 0, then p ∈ LPCP .
Step 4: Else if the is an i0 ∈ {1, 2, . . . , n} such that di0 = 0, then p ∈ LPCP as xi0 = yi0 .
3. 3
Step 5: Else there is an i1 ∈ {1, 2, . . . , n} such that di1 > 0 and i2 ∈ {1, 2, . . . , n} such
that di2 < 0. Then, p ∈ LPCP as xi1 . . . xi1
(−di2
) times
xi2 . . . xi2
(di1
) times
= a−di2
li1
+di1
li2 = a−di2
(di1
+mi1
)+di1
(di2
+mi2
)
=
a−di2
mi1
+di1
mi2 = yi1 . . . yi1
(−di2
) times
yi2 . . . yi2
(di1
) times
.
4. Recall that, given two languages L1 and L2, their right quotient, denoted by L1/L2,
is defined as {w ∈ Σ∗
: ∃x ∈ L2 such that wx ∈ L1}. Suppose Σ = {0, 1, 2, 3}. Let
L1 = L(G1) and L2 = L(G2) where
G1 = (Σ, {S}, S, {S → 12
30 | 03
31 | 01232 | 12
S0 | 03
S1 | 012S2})
and
G2 = (Σ, {S}, S, {S → 030 | 131 | 232 | 0S0 | 1S1 | 2S2}).
Show that L1/L2 is not a context free language. [10]
Hint: Observe what elements can belong to the set L1/L2 to argue why it can not be
context free.
Solution: Let L = L1/L2. Each string z in L is obtained from words z1 in L1 and z2
in L2 satisfying z1 = zz2. Since each string in L1 or L2 contains the symbol 3 exactly
once, the terminal substrings starting from 3 in z1 and in z2 are the same. If the string
30 (or 31) is a substring of z1, then 12
30 (or 03
31) occurs in z1 and 030 (or 131) occurs
in z2. Either case contradicts the equation z1 = zz2. Thus the only letter which can
occur immediately to the right of 3 in z1 is 2. Therefore z1 must contain 01232 as a
substring and z2 must contain 232 as a substring. Hence the shortest strings which can
occur as z1, z2 are 01232 and 232. Thus 01 is in L. In z1 we see that 232 is preceded
by 1. Then any longer word for z2 must contain 12321, and the corresponding z1
must contain 03
012321. Therefore 04
is in L. This line of reasoning can be continued
inductively to provide a means of enumerating all the elements of L. We find that L
consists of the sequence
01, 04
, 12
03
, 14
02
, 16
0, 18
, 03
17
, 06
16
, . . . , 024
, . . .
where to pass from one string xi in the sequence to the next xi+1, we use the following
rule:
• If xi = yi0, then xi+1 = 12
yi.
• If xi = yi1, then xi+1 = 03
yi.
In particular, 0n
∈ L if and only if n = 4(6)k
for k ≥ 0.
Now, if L is a CFL, then there exists a pumping lemma constant N. Choose a k0
large enough such that n0 = 4(6)k0
> N. Clearly z = 0n0
∈ L with |z| > N. Now,
irrespective of how we split z into five pieces, u, v, w, x, y with x = uvwxy, |uwy| ≤ N,
|vx| = l > 0, uvi
wxi
y = 0n0+(i−1)l
∈ L for some i ≥ 0, a contradiction. Thus, L is not
a CFL.