Basic TOC 2022 - Solution of CFL - TM & Backside Test
Basic TOC 2022 - Solution of CFL - TM & Backside Test
Q5. Which of the following language is/are NCFL but not DCFL?
L1 = {wywR : the length of y is even}, Σ = {a, b}.
L2 = {w : w has the same number of a‟s b‟s and c‟s together}, Σ = {a, b, c}.
L3 = {aibjck:i> j or j > k, where i, j, k ≥ 0}, Σ = {a, b, c}.
L4 = {xy : |x| = |y| and x ≠ y}, Σ = {a, b}.
(A) L3 only (B) L1 and L2 only
(C) L2 and L4 only (D) L1, L3 and L4 only
Answer: D
Solution:
i) L1: We don‟t know where wR starts, So, it is NCFL.
ii) L2: It is not a CFL as two equalities can‟t be ensured.
iii) L3: It is point of indeterminism that whether to ensure i>j or j>k. So, it is NCFL.
iv) L4: We know that complement of {ww| w ∈ 𝑎, 𝑏 * is NCFL.
(ii) push 1 on stack now if 0 arrives then push 0 on stack and then 1 arrives then pop 0
from stack. Again if 0 arrives then push 0 on stack and 1 arrives then pop zero from
stack. Now if 0 arrives then pop 1 from stack. So CFL.
iii)exact match of string is not possible with single stack so not CFL.
iv) ensuring more than one equality is not possible so not a CFL.
v) ensuring more than one equality is not possible so not a CFL.
vi) ensuring more than one not equality is not possible so not a CFL.
NDPDA, because here w is started from which position we don‟t know about it if it
push at right time then it is accepted by Ndpda.So it is accepted by ndpda, so it is non-
deterministic context free language.Answer: C
Q15. [MSQ]
Which of the following language is/are context free?
(A) L1= {anbj| n = j2}
(B) L2 = {an| n is multiple of a prime}
(C) L3 = {wwwRwR| w{a}*}
(D) L4 = {ajanbjbn | n = j and n, j >= 0}
Answer: b, c, d
Solution:
(a) 𝐿1 = 𝑎𝑛 𝑏 𝑗 | 𝑛 = 𝑗 2 . The relation {𝑛 = 𝑗 2 } cannot be ensure by one stack. So, it is
not CFL.
(b) 𝐿2 = 𝑎𝑛 | 𝑛 𝑖𝑠 𝑚𝑢𝑙𝑡𝑖𝑝𝑙𝑒 𝑜𝑓 𝑎 𝑝𝑟𝑖𝑚𝑒 = 𝑎 𝑎 + + 𝜆.
Because every number is multiple any prime number except 1.
(c) 𝐿3 = 𝑎𝑎 ∗ = 𝑟𝑒𝑔𝑢𝑙𝑎𝑟. So, it is CFL.
(d) L4 = {𝑎 𝑗 𝑎𝑛 𝑏 𝑗 𝑏𝑛 | n = j and n, j >= 0} = 𝑎𝑛+𝑗 𝑏𝑛+𝑗 |𝑛 , 𝑗 ≥ 0 = 𝑎𝑛 𝑏𝑛 | 𝑛 ≥ 0 .
So, it is CFL.
Q16. [MSQ]
Which of the following language is/are DCFL?
(A) L = {wxcxR | w {a, b, c}* and x {a, b}* }
(B) L = {xcxRw| w {a, b, c}* and x {a, b}* }
(C) L = {xwxR| w {a, b, c}* and x {a, b}* }
(D) L = {xcxRw| w, x {a, b}*}
Answer: b, c, d
Solution:
Q20. Let L language collection of strings over {0, 1} containing ten more 0 than 1. These
language is
(A) Regular
(B) Context free but not regular
(C) Recursive but not contexts free
(D) Recursively enumerable but not recursive
Answer: B
Solution:
to ensure #0(w) = #1(w) + 10 we need one stack. So, it is NCFL but not regular.
1. If 0 arrives then push 0 on stack and after that pop when 1 arrives.
2. If 1 arrives then push 1 on stack and after that pop when 0 arrives.
When stack is empty then we will start to push the data.
(Like equal number of 0‟s and 1‟s)
At last stack must have 10 zeros.
(iii) L={uawb | u, w {a,b}* and |u| = |w|}If 0 then push u and if input a then change
state.and if input w then pop u (string) from stack top , and b then again change state.
(iv) It is also context free.
(v) It is also context free.In this if input is a than push a, and if input is b, then push 3 b
corresponding to one b, and if input is c, then pop 2 b corresponding to one c and if
input is d and top of stack contain a then pop a, and if stack is empty a then more d is
on input, then accept .
Answer: B
Q28. Consider the following language L = {w#z: w is a substring of z and w, z {a, b}*}.
Which of the Following is true about L?
(A) Regular
(B) Context-free but not regular
(C) Context-sensitive but not context-free
(D) Recursively enumerable but not context-sensitive.
Solution:
wz
if w is abb
abb#abbba
Here we can‟t ensure because we need to check from starting, but top of the stack
contain last string so we can‟t ensure it by pda.
So it is context sensitive not CFL.
Answer: C
Solution:
L1 = {w : w is palindrome & w {a, b}*}NCFL
L2= {wwR # w} not CFL
two stacks are required.
Answer:D
Q35. Which of the following languages on 𝛴 = {a, b} is/are not context- free?
(i) L = {aibj| i and j are both prime}
(ii) L = {aibj | i is prime or j is prime}
(iii) L = {aibj | i is prime but j is not prime}
(iv) L = {aibj | neither i is prime nor j is prime}
(A) i, ii only
(B)iii, iv only
(C)ii, iv only
(D) All the above
Solution:
(i) L = {aibj| i and j are both prime}
It is not possible to ensure i and j both are prime by single stack.
Even, only i is prime is not ensured by PDA.
All are not CFL.
Answer:D
Q47. Here is a parse tree that is derived from some unknown grammar G.
Q48. The parse tree below represents a rightmost derivation according to the grammar
S → ABS|AB|aA, A → aS|a, B → bA
Answer: B
(iii) G is unambiguous grammar because there is no string for which there is two or
more derivation.
Answer: C
For the next two questions:
Consider the following grammar G
S → 0A | 1B | λ
A → 0AA | 1S | 1
B → 1BB | 0S | 0
Let L (G) is the language accepted by G.
Q54. Which of the following statements is/are true about G?
(i) G is Type 2.
(ii) G is ambiguous.
(iii) 0011010110 L (G) and 1111100101000 L (G).
(A) i& ii only
(B)ii & iii only
(C) i only
(D)All are true
(iii)
For string 0011010110 For string 1111100101000
S→0A S→1B
S→00AA S→11BB
S→001SA S→111BBB
S→0011BA S→1111BBBB
S→001101S S→11111BBBBB
S→0011010A S→1111100SBBB
S→00110101S S→11111001BBBB
S→001101011B S→111110010SBBB
S→0011010110 S→11111001010000
0011010110L(G) So, 1111100101000L(G) .
So option (iii) is false.
Answer: A
Q55. The language generated by G is
(A) The set of all the strings that don‟t contain substring 00.
(B) The set of all the strings that contains equal numbers of zero‟s followed by equal
number of one‟s or equal numbers of one‟s followed by equal number of zero‟s
i.e. L(G) ={0n1n|n>0} {0n1n| n>0}
(C) The set of all the strings which have equal number of zero‟s and one‟s.
(D)None of these
Solution:
It generates all the string with equal number of zero‟s and one‟s.
It generate string {01, 10, 0011, 1100, 001101}
Answer: C
Solution:
(i) G is ambiguous grammar.
for string ab there is two derivation.
So it is ambiguous grammar.
(ii) G produce all string with equal number‟s of as and bs” False.
Because it doesn‟t generate a string of the form aabb.
(iii) (ab + ba)* it generates (ab+ba)*, but it accepted by DPDA.
So it is ambiguous.
Answer: D
S 0A0 | 1A1 ⟹ 0 0 + 1 ∗ 0 + 10 0 + 1 ∗ 1
Q61. Let V = {S}, = {a, b}. Which of the following grammars is such that the language
Generated by it is {wwr: w{a, b}*}.
(A) G1 = (V, , R1, S), where R1 = {(S→aSa), (S→bSb), (S→)}
(B)G2 = (V, , R2, S), where R2={(S→aSa), (S→bSb), (S→a), (S→b), (S→)}
(C) G3 = (V, , R3, S), where R3 = {(S→Sa), (S→Sb), (S→)}
(D) G4 = (V, , R3, S), where R3 = {(S→aSb), (S→)}
Solution:
(b) is false.
S→aSa
S→aaa
Here w = a, wR = ? (aa) can‟t possible.
So option b is false.
because grammar generate palindrome of even length.
Answer: A
Q62. Which of the following CFG generates all the strings contains more 1‟s than 0‟s?
(A)S → 0T | 11T T → 0S | 11S |
(B)S → 0S1 | 1S0 | 1S1 | 1
(C) S → TS | 1T | 1S T → TT | 0T1 | 1T0 |
(D) S → TS | 1T | 11 T → TT | 0T1 | 1T0 | 1
Answer: C
Solution:
(B) It will not generate even length strings like 1011. So, this is false.
Answer: (a)&(b)
Q65. Consider the pushdown automaton with the following transition rules:
δ(q,0,Z0) = {(q,XZ0)}
δ(q,0,X) = {(q,XX)}
δ(q,1,X) = {(q,X)}
δ(q,ε,X) = {(p,ε)}
δ(p,ε,X) = {(p,ε)}
δ(p,1,X) = {(p,XX)}
δ(p,1,Z0) = {(p,ε)}
The start state is q. For which of the following inputs can the PDA first enter state p with
the input empty and the stack containing XXZ0 [i.e., the ID (p,ε,XXZ0)]?
(A) 001111 (B) 0101010
(C) 001110 (D)111001
(A) L1 = {anb3n | n ≥ 0}
(B) L2 = {anbn | n ≥ 0}
(C) L3 = {anbn+3 | n ≥ 0}
(D) L4 = {anbm | n ≥ 0, m > n + 3}
Solution:
Push a when input is „a‟ and top of stack is z then push a, if input is „a‟ and top of the
stack is a then push a. If input is b and top of stack is z/a then for 3 b just change state,
after 3 b if input is b and top of stack is a then pop a, if input is and top of stack is z
then accept it. So it show anbn+3| n≥0
Answer: C
whenever a arrives it pushes A on stack. Now if input string ends, then we will be on
final state q1.
If b arrives in input, then we will be on final state q2. Now at q2 we pop all A from stack
so number of b should be less than number of A.
It will accept aibj such that 0<=j<=i;
So, option A is correct.
(A){aibj| 0≤ 𝑗 ≤ 𝑖} (B){aibj| 0≤ 𝑖 ≤ 𝑗}
(C){anbn| n≥ 0} (D){(ab)n | n≥ 0}
(A){aibjck |
i + k = j} (B) {aibjck | i<j=k }
(C) {aibjci | i =j} (D) {aibjck | i<j and k>0}
Answer: A
Solution:
Whenever a arrives it pushes A on stack and whenever b arrives if top of stack has A
then pop it. If stack is empty then push B on stack. Now if c arrives in input and top of
stack has B then pop B.
It will accept the language where a followed by b followed by c and number of b equals
to thesum ofnumber of a‟sand number of c‟s.
So, option A is correct.
(A){aicjbi | i,j≥ 0}
(B) {aicjbk | i, j, 𝑘 ≥ 0}
(C) {aicjbi | i, j> 0}
(D) {aibi | i≥ 0}
Answer: A
Solution:
(A)L(G)={a2nb2n, n≥ 1}
(B)L(G)={a2n+1b2n+1, n≥ 1}
(C)L(G)={a2nb2n, n≥ 0}
(D)L(G)={a2n+1b2n+1, n≥ 0}
Answer: D
it will accept string in which odd number of a‟s followed by same odd number of b‟s so
option D is correct.
Then pop a
Then pop a
(, $ ) means if the input is Null and top of stack contain dollar then go to final
state.So, „aabb‟ will also be acceptable.
(A) L = {aibj | i= j}
(B) L = {aibj | i = 2*j}
(C) L = {aibj | i= j and i =2*j}
(D) L = {aibj | i ≤ j ≤ 2i}
Solution:
The given PDA accepts,
L= {aibj |ij 2i }
Because when a comes push A or AA , when b comes pop .
Answer: D
(A) set of all strings over {0, 1} which contain at most three 1‟s
(B) set of all strings over {0, 1} which contain exactly three 1‟s
(C) set of all strings over {0, 1} which contain at least three 1‟s
(D) set of all strings over {0, 1}
Solution: The given PDA accepts 0* 10*10*(0+1)*
i.e. it accepts all the string over {0,1} which contain at least three one’s.
Answer:C
Q79. Consider the following PDA
Q94. Consider the CFL L1 = {anbmcm| m,n >0 }. Choose a context-free language L2 that ensures
that L1 L2 is not context free?
(A) L2 = {anbmcn| n,m >0} (B) L2 = {a}* U {b}* U {c}
(C) L2 = {a,b}*L1 (D) L2 = {anbncn| n >0}
Q100. Let L1 = {anbn : n >= 0}, and L2 = {bnan: n >=0}. Then L1.L2 is:
(A){anb2man: n, m>=0} (B){anbnambm: m, n >=0}
(C){amb2mam: m>=0} (D) {anbn+mam: m, n >=0}
Solution:
L1= anbn:n>=0
L2= bn an: n>=0
L1.L2= anbn.bnan
abba, abbbaa, abbbbaaa.
Q103. Let L be a language. Then symmetric (L) = {w: w ∈ L and wr∈ L}.
Which of the following two statements is/are true?
S1: If L is regular, symmetric (L) is also regular.
S2: If L is context-free, symmetric (L) is also context-free.
(A) Only S1 (B) Only S2
(C) both S1 and S2 (D) Neither S1 nor S2
Answer: A
Solution: Symmetric (L) = 𝐿 ∩ 𝐿𝑅
Since regular language is closed under reversal operation and intersection, hence it is
also
closed under symmetric operation. So, S1 is true.
But CFL is not closed under symmetric operation because CFL is not closed under
intersection operation. For example:
L = 𝑎𝑛 𝑏𝑛 𝑎𝑚 | 𝑛, 𝑚 ≥ 0 and LR = 𝑎𝑚 𝑏𝑛 𝑎𝑛 | 𝑚, 𝑛 ≥ 0
Now, 𝐿 ∩ 𝐿𝑅 = 𝑎𝑛 𝑏 𝑛 𝑎𝑛 | 𝑛 ≥ 0 ; which is not CFL.
Q104. Let L1 = {anbncp |n, p≥0} and L2 = {ambncn| m, n≥0} then (𝐿1 𝑈 𝐿2) will be
(A)
(B) a*b*c*
(C) anbncn
(D) {* - a*b*c*} {ai bj ck | 𝑖 ≠ 𝑗 𝑎𝑛𝑑 j ≠ 𝑘}
Q106. Let L1 = {w1w2 : |w1| = |w2|, w1 (a, b)* and w2 (c, d)*} and L2 = {a, c}*.
Then L1 L2 will be:
(A) (B) (a + c)*
(C) a*c* (D) {ancn | n>=0}
Answer: D
Q109. Select the correct statement (Assume that L1, L2, L3 are TM acceptable)
(I) For any languages L1, L2 and L3, L1(L2 L3) (L1L2) (L1L3)
(II) For any languages L1, L2 and L3, (L1L2) (L1L3) L1(L2 L3).
(A)only I (B)only II
(C)Both I&II (D)None of them
Answer:A
Solution:Let L1 = {a, aa}, L2 = {b, c}, and L3 = {ab, c}. Then, L2 ∩L3 = {c}, so
L1(L2 ∩L3) = {ac, aac}. L1L2 = {ab, ac, aab, aac}, L1L3 = {aab, ac, aaab,
aac}, So, L1L2 ∩ L1L3 = {ac, aab, aac}. So, II is false.
(c) For every string generated by G, we can always have at least one Left-most
derivation and one rightmost derivation (need not be different).
Q121. Which of the following statement is /are true for an arbitrary context free language?
(i) Every context-free language A is regular.
(ii) Every context-free language is recursive enumerable.
(iii) Every context-free language is recursively enumerable but not recursive.
(iv) Every context-free language is recursive.
(A) ii and iv only (B) i, ii and iv only
(C) ii and iii only (D)None
Answer: A
Solution:
(i) It is False, because not Every context-free language A is regular.
(ii) Yes, very context-free language is recursive enumerable.
(iii) False because every context-free language is recursively enumerable and recursive.
(iv) Yes, every context-free language is recursive
Grammar to PDA,
Q122. Consider the following grammar G:
S aSb | aSbb | ab
Suppose you want to construct PDA M (Q, Σ, , 𝛿, z, F) for language generated by
given grammar G.
M is defined by Q = {q0, q1, qf}, Σ = {a, b} = {𝑆, 𝐴, 𝐵, 𝑧}, F = {qf} and 𝛿 is not known.
Which of the following is correct transition rule (𝛿) for M?
(a) 𝛿 (q0, λ, S) = {(q1, Sz)}, 𝛿 (q1, a, S) = {(q1, SB), (q1, SBB), (q1, B)}, 𝛿 (q1, b, B)=
{(q1, λ)}, 𝛿 (q1, λ, z) = {(q1, z)}
(b) 𝛿 (q0, λ, S) = {(q1, Sz)}, 𝛿 (q1, a, S) = {(q1, SB), (q1, SBB), (q1, B)}, 𝛿 (q1, b, B) =
{(q1, λ)}, 𝛿 (q1, λ, z) = {(qf, z)}
(c) 𝛿 (q0, λ, S) = {(q1, Sz)}, 𝛿 (q1, a, S) = {(q1, SB), (q1, SBB)}, 𝛿 (q1, b, B) = {(q1, λ)},
𝛿 (q1, λ, z) = {(qf, z)}
(d) None of the above
Solution
Check for option B:-
Push S on stack
then SaSB|aSBB|aBB
Bb
Data for next three questions: Consider the following PDA M (Q, Σ, , 𝛿, z, F) for a
grammar G: M is defined by Q = {q0, q1, qf}, Σ = {a, b}, = {𝑆, 𝐴, 𝐵, 𝐶, 𝑧}, F = {qf} and the transition
rules (𝛿) are:
𝛿 𝑞0 , 𝜆, 𝑧 = 𝑞1 , 𝑆𝑧 , 𝛿 𝑞1 , 𝑎, 𝑆 = 𝑞1 , 𝐴 ,
𝛿 𝑞1 , 𝑎, 𝐴 = 𝑞1 , 𝐴𝐵𝐶 , 𝑞1 , 𝜆 , 𝛿 𝑞1 , 𝑏, 𝐵 = 𝑞1 , 𝜆 ,
𝛿 𝑞1 , 𝑏, 𝐴 = 𝑞1 , 𝐵 , 𝛿 𝑞1 , 𝑐, 𝐶 = 𝑞1 , 𝜆 , 𝛿 𝑞1 , 𝜆, 𝑧 = 𝑞𝑓 , 𝑧
𝑆 ⟶ 𝑎𝐴 ⟶ 𝑎𝑎 𝑆 ⟶ 𝑎𝐴 ⟶ 𝑎𝑏𝑏
𝑆 ⟶ 𝑎𝐴 ⟶ 𝑎𝑎𝐴𝐵𝐶 ⟶ 𝑎𝑎𝑎𝐵𝐶 𝑆 ⟶ 𝑎𝐴 ⟶ 𝑎𝑎𝐴𝐵𝐶 ⟶ 𝑎𝑎𝑏𝑏𝑏𝑐
⟶ 𝑎𝑎𝑎𝑏𝐶 ⟶ 𝑎𝑎𝑎𝑏𝑐
Only I & V are accepted.
Q126. [MSQ]
Which of the following grammar is/are equivalent to G?
(A) S aA, A aAbc | bb | a
(B) S aA, A aABc | bB | a, Bb
(C) S aA, A aABC | bB | a, B b, Cc
(D) S aS | aSbc | bb | a
Answer: a, b, c
Solution:
𝛿 𝑞1 , 𝑎, 𝑆 = 𝑞1 , 𝐴 , ⟹ 𝑆 ⟶ 𝑎𝐴
⟹ 𝑎𝑛+2 𝑏𝑐 𝑛 𝑛 ≥ 0 ∪ 𝑎𝑛+1 𝑏𝑏 𝑏𝑐 𝑛 |𝑛 ≥ 0
𝛿 𝑞1 , 𝑎, 𝐴 = 𝑞1 , 𝐴𝐵𝐶 , 𝑞1 , 𝜆 ⟹ 𝐴 ⟶ 𝑎𝐴𝐵𝐶 | 𝑎
𝑛+1
⟹ 𝑎 𝑏𝑐 𝑛 ≥ 0 ∪ 𝑎𝑛 𝑏𝑏 𝑏𝑐 𝑛 |𝑛 ≥ 0
𝑛
𝛿 𝑞1 , 𝑏, 𝐵 = 𝑞1 , 𝜆 , ⟹𝐵 ⟶𝑏 ⟹ 𝑏
𝛿 𝑞1 , 𝑏, 𝐴 = 𝑞1 , 𝐵 , ⟹ 𝐴 ⟶ 𝑏𝐵 ⟹ 𝑏𝑏
𝛿 𝑞1 , 𝑐, 𝐶 = 𝑞1 , 𝜆 , ⟹𝐶 ⟶𝑐 ⟹ 𝑐
𝑛+2 𝑛 𝑛+1 𝑛
L (M) = 𝑎 𝑏𝑐 𝑛 ≥ 0 ∪ 𝑎 𝑏𝑏 𝑏𝑐 |𝑛 ≥ 0
And the grammar G will be:
𝑆 ⟶ 𝑎𝐴, 𝐴 ⟶ 𝑎𝐴𝐵𝐶 𝑎 𝑏𝐵, 𝐵 ⟶ 𝑏, 𝐶 ⟶𝑐
BASIC THEORY OF COMPUTATION Page 85
Option a, b and c are equivalents. So, optionsa, b, care correct.
Solution:
For non-terminals e $ D there is no useful production (i.e generating some string of terminals).
Only remaining useful production rule:-
SaS|BA
Baa
Aa
It can be written as:-
SaS|aaa (putting production rule of A &B).
or SaS|aA
Aaa
Both b& c are correct.
Answer: D
Q137. [MSQ]
Which of the following rule(s) doesn‟t belong to CNF of any CFG?
(A) S → BC (B) B → Bc
(C) B → a (D) S → B
Solution:
For grammar to be in CNF:-
Single Non-terminal→ two non-terminals or single terminal.
S→BC (In CNF)
B→BC(Not in CNF)
B→a (In CNF)
S→B (Not in CNF) {because unit production is not allowed in CNF}
Answer: b & d
Q141. Which of the following sets of productions is not in Chomsky normal form?
G1 : S AB A AB|a B Ba|b
G2 : S AB A AB|a B BA|b
G3 : S A|B A AB|a B BA|b
(A) G2 (B) G1, G2, G3
(C)G2 and G3 (D) G1 and G3
Solution:
G1→is not in CNF.
Because of B→Ba
CNF definition said that single non- terminal derived two non-terminal or single
terminal.
G3:- S→A/B
By definition of CNF.
Answer: D
Q148. Let L be a context free language and w = uvxyz is any string in L such that 𝑤 ≥ 𝑚;
where m is some constant positive integer then which of the following conditions must
be satisfied in order to apply pumping lemma?
(i) 𝑣𝑥𝑦 ≤ 𝑚 (ii) vy ≠ 𝜀
(iii) 𝑣𝑥𝑦 ≥ 𝑚 (iv) vy = 𝜀
(A) i and ii only
(B) iii and iv only
(C) i and iv only
(D) ii and iii only
Solution:
Pumping lemma for CFL states that:
Let L be an infinite context free language. Then there exist some positive integer m such that any
wL with |w| >m can be decomposed as
w= uvxyz
with |vxy|≤m
and |vy| 1 i.e. vy
such that uvi xyi zL for all i=0,1,2,…..
(i) (ii) are correct.
Answer: A
Q149. Consider the language L = {aibjaibj | i, j >= 0}. Consider the following “proof" that L
satisfies the pumping lemma. Let p be the pumping length. Choose Z = apbapb.
Consider a division of Z, where u = ap-1, v = a, w = b, x = a and y = ap-1b. Clearly
uviwxiy is in L for every i.
(A) This is an incorrect proof because all divisions of Z have not been considered.
(B) This is an incorrect proof because all possible Z have not been considered.
(C) This is a correct proof.
(D)None of above
Answer:
BASIC THEORY OF COMPUTATION Page 96
Solution:
Q150. Consider the language L = {anbncn | n >= 0}. Consider the following “proof" that L does
not satisfy the pumping lemma. Let p >= 1 be the pumping length. Choose z = apbpcp.
Consider the division of z, where u = , v = a, w = , x = , and y = ap-1bpcp.
Clearly uv0wx0y is not in L.
(A) This is an incorrect proof because all divisions of z have not been considered.
(B) This is an incorrect proof because all possible z have not been considered.
(C) This is a correct proof.
(D)None of above
Answer:
Solution:
Solution:
All are undecidable.
(1) Intersection of 2 context free is atmost recursive and language of generated by recursive = is
undecidable.
(2) Their intersection is CFL is undecidable.
(3) Their intersection is atmost recursive and regularity of context sensitive grammar is
undecidable.
(4) Same reason as 1.
Answer: D
(A)a* (B)a*ba*
(C)ba* (D)aba*
Answer: D
Solution:
Q6. What language does the following Turing Machine (TM) accept?
M = (Q = {q0, q1, q2}, Σ = {a, b}, Γ = {a, b, B}, δ, q0, B, F = {q2}); where the transition
function δ is given by
δ(q0, a) = {(q0, a, R)}
δ(q0, b) = {(q1, b, R)}
δ(q1, B) = {(q2, B, R)}
δ (q, x) = stop everywhere else
Q7. Consider the Turing machine M = (Q, Σ, Γ, δ, q0, qacc, qrej); where
• Q = {q0, q1, q2, q3, qacc, qrej}
• Σ = {0, 1}, and Γ = {0, 1, A, B, t}
• δ is given as follows:
δ(q0, 0) = (q1, A, R) δ(q0, B) = (q3, B, R)
δ(q1, 0) = (q1, 0, R) δ(q1, B) = (q1, B, R)
δ(q1, 1) = (q2, B, L) δ(q2, B) = (q2, B, L)
δ(q2, 0) = (q2, 0, L) δ(q2, A) = (q0, A, R)
δ(q3, B) = (q3, B, R) δ(q3, t) = (qacc, t, R)
In all other cases, δ(q, X) = (qrej, t, R). So for example, δ(q0, 1) = (qrej, t, R).
How many of the following strings are rejected by M? __________
i. 10001 ii. 111000 iii. 0010
iv. 10100 v. 101010
Answer:
Solution:
Q8. A Turing machine M with start state q0 and accepting state qf has the following transition
function:
δ(q, a) 0 1 B
q0 (q1 ,0,R) - -
q1 - (q0, 1, R) (qf , B, R)
qf - - -
Which of the following strings are accepted by TM?
(A) 1110 (B) 0110
(C) 01011 (D) 0101
Q14. Determine what the Turing machine does when presented with the “aaabbbb”.
(A) TM halts at final state
(B) TM does not halt and loop forever
(C) TM rejects the input
(D) Cannot say about this input
Answer: C
Solution: The given TM accepts L = {𝑎𝑛 𝑏𝑛 | 𝑛 ≥ 1}. So, TM rejects the input.
Q15. Determine what the Turing machine does when presented with the “aaaaabbbbb”.
(A) TM halt at final state
(B) TM does not halt and loop forever
(C) TM reject the input
(D) Cannot say about this input
Q18. What is the smallest number of tape symbols that a TM with nonempty input alphabet
could have?
(A) 0 (B) 1
(C) 2 (D) 3
Answer: C
Q19. Suppose that a Turing Machine is run on an input. Which of the following is false?
(A) Infinitely many configurations of the machine can occur.
(B) If a configuration of the machine arises twice in a computation on this input, the
machine enters an infinite loop.
(C) Every configuration contains exactly one state of the machine.
(D) A configuration of the machine might have infinite length because the tape is infinite.
Q20. Consider a Turing machine which can move only left, at most 5 times in the course of
computation on any input. Consider all TMs that have this property. What languages do
they recognize?
(A) Exactly the regular languages.
(B) Exactly the context-free languages.
(C) Exactly the decidable languages.
Q21. What language is accepted by the Turing machine whose transition graph is shown
below?
(A) L = {anbman+m : n ≥ 0, m ≥ 1}
(B) L = {ambnam+n : m ≥ 0, n ≥ 1}
(C) L = {anbman+m : n ≥ 1, m ≥ 1}
(D) L = {anbman+m : n ≥ 0, m ≥ 0}
(A) {ak bk ck | k ≥ 0}
(B) {ai bj ck | i, j, k ≥ 0 and i = k}
(C) {ai bj ck | i, j, k ≥ 0 and i = k or j = k}
(D) {ai bj ck | i, j, k ≥ 0 & i = k and j = k}
Q35. Then L2 is
(A) Recursive (B) RE (C) Not RE (D) finite
Q36. Then L3 is
(A) Recursive (B) RE (C) Not RE (D) finite
Q37. Then L4 is
(A) Recursive (B) RE (C) Not RE (D) finite
Q38. Then L5 is
(A) Recursive (B) RE (C) Not RE (D) finite
Q39. Then L6 is
(A) Recursive (B) RE (C) Not RE (D) finite
Q40. Then L7 is
(A) Recursive (B) RE (C) Not RE (D) finite
Q41. Then L8 is
(A) Recursive (B) RE (C) Not RE (D) Co-RE
Q42. Then L9 is
(A) Recursive (B) RE (C) Not RE (D) Co-RE
Q43. Then L10 is
(A) RE (B) Co-RE (C) Not RE (D) Both b & c
Q44. [MSQ]
The language ADFA = {<D, w> | D is DFA that accepts w}is
(A) Decidable (B) Turing Recognizable
(C) Not Turing Recognizable (D) None
∗
Q45. The language ACFG = {<G>|G is CFG and L (G) = }is
(A) Decidable (B) Turing Recognizable
Q47. EQTM = {<M1, M2> | M1, M2 are TMs with L(M1) = L(M2)}?
(A) Decidable (B) Turing Recognizable
(C) Not Turing Recognizable (D) None
Q66. Consider an arbitrary language L ⊆ {0, 1}∗ . Which of the following statements must be
true?
i) If L is decidable, then L is infinite.
BASIC THEORY OF COMPUTATION Page 122
ii) If L is not decidable, then L is infinite.
iii) If L is the union of two regular languages, then its complement L is context-free.
iv) If L is context-free, then its complement L is context-free.
v) If L is finite, then L is context-free.
(A) iii and v only
(B)i and ii only
(C)ii, iv and v only
(D)ii, iii and v only
Q67. Consider the following sets of languages over the alphabet {0, 1}:
• LDTM is the set of all languages L ⊆ {0, 1} ∗ such that L is accepted by at least one
deterministic Turing machine.
• LNTM is the set of all languages L ⊆ {0, 1} ∗ such that L is accepted by at least one non-
deterministic Turing machine.
Which of the following statements is/are true?
(A) LDTM LNTM
(B) LDTM LNTM
(C) LDTM = LNTM
(D) Undecidable problem
Q68. Which of the following statements are correct?
i) For every recursive language L, there is a Turing machine M with 𝐿 as its language.
ii) For every non-deterministic push-down automaton, there is an equivalent
deterministic push-down automaton.
iii) Non-deterministic Turing machines are strictly more powerful than Deterministic
Turing machines.
(A) i only (B) ii only
(C) iii only (D) i and iii only
Q69. Which of the following statements are correct?
i) DFA reads its input fully before accepting a string.
ii) A multi-tape TM is equivalent to a single tape TM.
iii) A DTM may accept a string without reading its input.
iv) The number of configurations of an LBA is fixed by its number of states Q.
(A)ii and iii only (B)ii only
(C) i, ii and iii (D)All the above
Q70. State which of the following statements are true?
(I) If A is context-free, then A is Turing-recognizable.
(II) Every language is Turing-recognizable.
(III) For a Turing machine M and a string w, M either accepts orrejects w.
(IV) The language ((01 ∪ 10)*0 ∪ 1)* is countable.
(V) If language A is recognized by a 14-tape nondeterministic Turing machine, then
How many numbers of states should be made accepting in order for this automaton to accept the
language of strings with zero or an even number of 1? __________
Q9. Which of the following regular expression generates the language recognized by the following
FSM?
Q15. Which is the most restrictive class to which the following grammar belongs?
S → xB
Q17. Which is the most restrictive class to which the following grammar belongs?
S → xB
xB → xCy
xCy → xyz
C → CwC
C→
Q18. What is the minimum number of states in the DFA for the language over 0,1 which accepts the set
of all strings which contain the substring 111?_______
Answer: 4
Solution:
Q2. Which of the following sets of productions is not in Chomsky normal form?
G1: S→AB G2: S→AB G3: S→A|B
A→AB|a A→AB|a A→AB|a
B→Ba|b B→BA|b B→BA
(A) G1 (B) G3
(C) G2 &G3 (D) G1&G3
Q3. Which of the following context-free grammar productions describes the language which is a subset
of {a}* in which all strings contain an odd number of a symbols ambiguously. In all cases, the start
symbol is S and the alphabet is {a}.
(A) S → a | aSa (B) S → aaS | a
(C) S → Saa | a (D) S → aA | Aa | a A → aS
Q4. Which of the following descriptions best fits the language L = {anbmcndm | n, m ≥ 0}?
(A) L is a regular language
(B) L is a context-free language that is not regular
(C) L is a context-sensitive language that is not context-free
Q7. Let L consist of all binary strings beginning with a 1 such that its value when converted to decimal
is divisible by 5. Which of the following is true?
(A) L can be recognised by a deterministic finite state automaton.
(B) L can be recognised by a non-deterministic finite state automaton but not by a deterministic
finite state automaton.
(C) L can be recognised by a deterministic push-down automaton but not by a non-deterministic
finite state automaton.
(D) L can be recognised by a non-deterministic push-down automaton but not by a deterministic
push-down automaton
Q10. Suppose we apply minimization to the following DFA over {a, b}:
Q12. Which one of the following regular expressions generates all strings in {a,b}* with a even number
of a’s?
(A) b*ab*ab* (B) (a+b)*a(a+b)*a(a+b)*
(C) ((a+b)*a(a+b)*a(a+b)*)* (D) (b*ab*ab*)*
Q13. Which of the following statements is the most correct answer?
(A) Every finite language is regular.
(B) For some regular grammar G L(G) = L(G)* .
(C) Different regular expressions can describe the same language.
(D)All statements are correct
Q14. Which of the following regular expressions describes the language- the set of all strings over {0, 1}
containing at least two 1’s?
(A) (0+1)*11(0+1)*
(B) 0*110*
(C) 0*10*10*
(D) (0+1)*1(0+1)*1(0+1)*
Q15. Consider a PDA P = ({q}, {0, 1}, {0, 1, Z0}, T, q, Z0, {p}), where T consists of the transitions
δ(q, 0, Z0) = {(q, 0Z0)}
δ(q, 1, Z0) = {(q, 1Z0)}
δ(q, 0, 0) = {(q, 00)}
δ(q, 0, 1) = {(q, ε)}
δ(q, 1, 1) = {(q, 11)}
δ(q, 1, 0) = {(q, ε)}
δ(q, ε, Z0) = {(p, ε)}
The language accepted by the following PDA is:
(A) {0n1n | n>=0}
Q16. If L = {0} and M = {11}. Then how many strings are in (L∪M)3?___________
Q17. The grammar S → aS | aSbS | is ambiguous. How many parse tree string aab has? ________
Q25. How many of the following languages is/are context free? ____________
i. L1= {aibj| i and j are two prime number smaller than 1000.}
ii. L2= {bi#(biR)+1 | bi is the binary representation of integer i; i 0}
iii. L3 = {w {a,b}* | a (w) = b (w) and w does not contain substing abaa or babb}.
Closure Properties
Decidability/Undecidability
• Every question we‟ve asked about the language of finite automata is decidable
Is w L(M)?, Is L(M)= , Is L(M)= finite , Is L(M)= *