Flat-Es 2023 Soln
Flat-Es 2023 Soln
ANSWER 8 out of 10 questions. Fill in the blanks wherever asked for in the answer script
and not in the question paper!
Question 1 (a) Consider the DFA M whose state diagram is given in Figure 1.
(i) Give an informal description of the language L(M ) accepted by M . Justify the answer. [2]
(ii) Are there strings x ∈ L(M ) (say x ≥ 3) such that if the bits of x are flipped (0 changed to
1 and 1 changed to 0), the resulting string is also in L(M ). Why or why not? Is this true
for every x ∈ L(M )? [2+2]
Figure 1: DFA M .
(b) Consider the language L = {tu | t and u are strings over {0, 1} with the same number of 1’s}.
Explain and correct the error below:
Proof that L is not regular using the Pumping Lemma: Assume (toward a contradiction) that L
is regular. Then the Pumping Lemma applies to L. Let p be the pumping length of L. Choose
s to be the string 1p 0p 1p 0p , which is in L because t = 1p 0p and u = 1p 0p each have p 1’s. Since
this string is in L and has a length greater than or equal to p, the Pumping Lemma guarantees
s can be divided into parts s = xyz such that for any i ≥ 0, xy i z is in L, and that |y| > 0 and
|xy| ≤ p. Since the first p characters of s are all 1’s and we have |y| > 0 and |xy| ≤ p, we know
that y must be nonempty and made up of all 1’s. But if we let i = 2, we get a string xy i z that
1
Figure 2: Answer 1(a)
is not in L because repeating y twice adds 1’s to t but not to u, and strings in L are required
to have the same number of 1’s in t as in u. This is a contradiction. Therefore the assumption
is false, and L is not regular. [4]
2
P
Question 2 Consider the three languages in Figure 4. In each case, = {0, 1}. S is the start symbol for each
CFG.
Figure 5: Answer 2
3
P
Question 3 (a) Let P be a PDA defined as follows. Q = {q0 , q1 , q2 }, = {0, 1}, Γ = {R}, F = {q1 , q2 }.
δ(q0 , 0, ϵ) = {(q0 , R)}
δ(q0 , ϵ, ϵ) = {(q1 , ϵ)}
δ(q0 , 1, R) = {(q2 , ϵ)}
δ(q1 , ϵ, R) = {(q1 , ϵ)}
δ(q2 , 1, R) = {(q2 , ϵ)}
δ(q2 , ϵ, R) = {(q2 , ϵ)}
(i) Describe the language accepted by P using set-theoretic notations. [2]
(ii) Give the state diagram of P . [2]
(iii) Write down the traces of computations (all computation paths) of 001 in P using state
transition tables (Current State | Current String | Current Stack). [2]
(iv) Show that 0011 ∈ L(P ). [1]
4
Figure 10: Answer 3(b))
Question 4 (a) Draw a parse tree for the string f (f (x)) using the CFG below. The terminals are {f, x, (, )} and
V is the start symbol. [2]
V → x|f |F L
F → f(
L→V)
(b) Complete the following high level description of a Turing machine recognising the following
language.
L = {w | w ∈ {a, b, c}∗ and w has equal number of a’s, b’s, and c’s}
“On input w:
1. If w = , accept.
2. Scan the input and find the a. Replace it by X. If , reject.
3. Scan the input and find the b. Replace it by Y . If , reject.
4. Scan the input and find the c. Replace it by Z. If , reject.
5. Scan the input to check if any . If none, then . Otherwise .” [3]
5
(c) Prove/disprove that a language (L) is Turing-decidable if and only if some enumerator enumer-
ates the strings of this language in length increasing lexicographic order. Please do not write
an essay here! In the forward direction give a high-level stepwise description of the Turing
machine (if it exists) and in the backward direction give a high-level stepwise description of the
enumerator (if it exists). (Hint: The language for which the enumerator enumerates could be
either finite or infinite). [5]
6
Question 5 (a) Let L = {< M > |M is a DFA and there exists some string w such that both w and wR are in
L(M ).} Show that EDF A can be used to prove that L is decidable. [4]
(b) (i) The following body of statements tries to prove/disprove that decidable languages are closed
under intersection. Fill in the blanks and finally argue whether you have proved or
disproved it.
Let L1 and L2 be decidable languages decided by TMs M1 and M2 respectively. It should
be possible to construct the following TM for L1 ∩ L2 :
“On input w:
1. Run M1 on w. If M1 then .
2. Run M2 on w. If M2 then .
3. Otherwise .” [1.5+1]
(ii) The following body of statements tries to prove/disprove that decidable languages are closed
under concatenation. Fill in the blanks and finally argue whether you have proved or
disproved it.
Let L1 and L2 be decidable languages decided by TMs M1 and M2 respectively. It should
be possible to construct the following TM for L1 ◦ L2 :
“On input w:
1. For each x between 0 and |w|:
a. Let w1 be the symbols of w.
b. Let w2 be the w.
c. Run M1 on w1 . If M1 then continue with .
d. Run M2 on w2 . If M2 then continue with .
e. If M1 and M2 then .
2. .” [2.5+1]
7
Figure 16: Answer 5(b-ii)
S −→ AB
Question 6 (a) Consider the following CFG for some alphabet Σ = {a, b}:
A −→ BB | a
B −→ AB | b
Construct the CYK parsing table for the string aabbb in the following format.
A
ϕ A
S, B S, B B
A A A B
S, B S, B S, B A B
[6]
(b) Show that if G is a CFG in CNF then for any string w ∈ L(G) of length n ≥ 1, exactly 2n − 1
steps are required for any derivation of w. [4]
Ans: Note that with CNF grammar, every production will increase the string length by 1.
Hence, starting from S, we need n − 1 productions for generating a string of size n. Further,
generating each non-terminal needs one production rule. So, n number of productions are
required to produce the n terminals in the final string. Hence, in total 2n − 1 steps are required.
Question 7 For any two strings w, t ∈ {0, 1}∗ , let w ∼ t denote that the symbols of w are a permutation of the
symbols of t. In other words, w ∼ t if w and t have the same symbols in the same quantities, but
possibly in a different order. For example, 0011 ∼ 1010. For any string w, define SCRAM BLE(w) =
{t | t ∼ w}. For any language A, let
SCRAM BLE(A) = {t | t ∈ SCRAM BLE(w) for some w ∈ A}
(a) Using properties of regular languages, prove that SCRAM BLE((01)∗ ) is not regular. [2]
Ans: Assume that SCRAM BLE((01)∗ ) is regular. Then
SCRAM BLE((01)∗ ) ∩ (0∗ 1∗ ) = {0n 1n | n ≥ 0}
will also be regular, which is not true. Hence, SCRAM BLE((01)∗ ) is not regular.
(b) For Σ = {a, b, c}, show that SCRAM BLE((abc)∗ ) is not context free. [2]
Ans: Assume that SCRAM BLE((abc)∗ ) is context free. Then,
SCRAM BLE((abc)∗ ) ∩ (a∗ b∗ c∗ ) = {an bn cn | n ≥ 0}
will also be context free (as intersection of context free with regular is context free). However,
{an bn cn | n ≥ 0} is context sensitive (can be easily proved by Pumping Lemma for CFLs).
Hence, SCRAM BLE((abc)∗ ) is not context free.
8
(c) Prove that for Σ = {0, 1}, the SCRAMBLE of any regular language is always context-free.
Ans: This problem uses an interesting property of stack, which is ”generating permutations of
a given sequence”. Consider an input being fed to a system. The system nondeterministically
decides whether to push it to a stack, or pass it directly to output. When the system decides
to not pass the original input to output directly, it further decides whether to pop something
from stack and output or whether to not output anything at all. Take the string input 1100.
Possible output permutations are 1001, 0110, 0011,....... These can be generated by push (↓)
pop (↑) and pass → sequences like
→↓→→↑
↓↓→↑↑→
↓↓→→↑↑
For any regular language L, some DFA M will exist. We modify the machine M with a stack
and some new transition rules to create an NPDA as follows.
As long as input has not ended and stack is not empty, make choices from the following,
i. Push input to stack, do not make any state change in M ,
ii. Pop stack and with that popped element simulate M , push input in stack,
iii. Simulate M directly with input, no stack manipulation,
iv. Simulate M with popped stack symbol and do not process any input (ϵ-transitions).
Note that as long as some permutation of the original input is accepted by M , this NPDA will
accept. Hence, for any σ ∈ L, any permutation of σ when given as input to the NPDA will be
accepted (due to some branch of computation generating σ on-the-fly in the NPDA). [6]
Question 8 (a) Consider the alphabets ∆ = {a, b} and Σ = {0, 1}. Construct a DFA for L = (00 + 01 + 1)∗ .
Let h : ∆∗ 7→ Σ∗ be a homomorphism given by h(a) = 001, h(b) = 110. Construct the DFA for
h−1 (L). [3+3]
Ans:
(b) Prove using Pumping Lemma that {ai bj ci dj | i, j ≥ 0} is not a CFL. [4]
Ans: p p p p
Let p be the pumping length and consider z = a b c d . Since |z| > p, there are
u, v, w, x, y such that z = uvwxy, |vwx| ≤ p, |vx| > 0 and uv i wxi y ∈ L, ∀i ≥ 0. Since |vwx| ≤ p,
v, x cannot contain both a-s and c-s, nor can it contain both b-s and d-s. Further |vx| > 0. Now
uv 0 wx0 y = uwy ∈ / L, because it either contains fewer a-s than c-s, or fewer c-s than a-s, or fewer
b-s than d-s, or fewer d-s than b-s.
9
Question 9 (a) Prove that AT M = {M is a Turing Machine that accepts w} is not decidable. Explain the di-
agonalization in your argument. [6]
(b) Let A and B be two disjoint languages. We say that a language C separates A and B if A ⊆ C
and B ⊆ C. Let A and B be Turing-recognizable. Prove that A and B are separable by some
decidable language. [4]
Ans:
Question 10 (a) Let X = {⟨M, w⟩ | M is a single-tape TM that never modifies the portion of the tape that con-
tains the input w}. Show that X is undecidable. (Hint: Assume that X has some decider and
use it to build a decider for AT M ). [6]
Ans: We show that X is undecidable by reducing from AT M . Let R be a TM that decides X.
We use R to construct a TM S that decides AT M .
10
Note that MX is such a machine that writes something on its input (which is M, w) if M is a
machine that accepts w. Otherwise, i.e, if M rejects or loops on w, MX does not write anything
on its input. Hence, if R accepts, then M accepts w and very interestingly, if R rejects (it is
assumed as a decider), then M rejects/loops on w. So, S basically decides AT M . Note that
S always accepts/reject halts by design, as it is generating the description of MX ; it is never
running MX or trying to simulated M on w inside.
Since an AT M decider cannot exist, R does not exist. So, X must be undecidable.
(b) Let ALLDF A = {⟨A⟩ | A is a DFA and L(A) = Σ∗ }. Show that ALLDF A is decidable. [4]
Ans: Note that the equivalence problem of regular languages is decidable. Hence, the decider
X of ALLDF A works as follows.
X: On input A
1. Create an automaton B such that L(B) = Σ∗ . (B has one initial/accept state only with a
self-loop for all input symbols.
2. Call the decider EQDF A on (A, B). If it accepts, accept, otherwise reject.
11