0% found this document useful (0 votes)
217 views163 pages

Basic TOC 2022 - Solution of CFL - TM & Backside Test

Uploaded by

vishalcontent69
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
217 views163 pages

Basic TOC 2022 - Solution of CFL - TM & Backside Test

Uploaded by

vishalcontent69
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 163

CONTEXT FREE LANGUAGE

Q1. Which of the following languages is/are context free languages?


(I) L = {anbj | n ≤ j2}
(II) L = {anbjck | k = j*n}
(III) L = {anbjck|n < j, n ≤ k ≤ j}
(A)I&II only (B) II &III only
(C) I & III only (D) None of the above

BASIC THEORY OF COMPUTATION Page 1


Q2. Which of the following language is/are NCFL?
(I) L = {ambncpdq| n = q or m ≤ p and m+ n = p + q}
(II) L = {ambncp | m = n or n = p or m = p}
(III) L = {ambncp | m = n and n = p and m = p}
(IV) L = {ambncp | m  n or n  p or m  p}
(A) II &IV only (B) I & IV only
(C) I &II only(D) None of above

BASIC THEORY OF COMPUTATION Page 2


BASIC THEORY OF COMPUTATION Page 3
Q3. Which of the following language is/are context free?
L1 = {anbj| n ≤ j2}
L2 = {an| n is prime}
L3 = {anwwRan| n ≥ 0 and w{a, b}*}
L4 = {anbjajbn| n ≤ j}
L5 = {xy| x, y {0, 1}* and x ≠ y}
(A) L3 and L4 only (B) L1 and L4 only
(C) L2 and L5 only (D) L3 and L5 only

BASIC THEORY OF COMPUTATION Page 4


BASIC THEORY OF COMPUTATION Page 5
L5 = {xy| x, y {0, 1}* and x ≠ y} = (a, b)+ = regular
Except 𝜆, ever binary string belongs to L5. So, it is CFL.

BASIC THEORY OF COMPUTATION Page 6


Q4. Which of the following language is/are context free?
L1 = {anbnanbn : n ≥ 0}, Σ = {a, b}.
L2 = {wR#z : w is a substring of z, w, z ∈ {a, b}*}, Σ = {a, b, #}.
L3 = {w#z : w is a substring of z, w, z ∈ {a, b}*}, Σ = {a, b, #}.
L4 = {x+y=z : x + y = z in unary where x, y, z ∈ 11*}, Σ = {1, +, =}.
(A) L3 and L4 only (B) L2 and L4 only
(C) L4 only (D) None
Answer:B
Solution:
i) L1: Ensuring more than one equality is not possible in CFL.
ii) L2: Reverse match is possible with one stack, so it is CFL.
iii) L3: Exact match of string is not possible with one stack. So, it is not CFL.
iv) L4 = {1+1 = 11, 11+1=111, 1+11 =111, 11+111=11111, 1111+1=11111, 1+1111=11111, …}
L4 is CFL and their PDA is shown below:

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.

BASIC THEORY OF COMPUTATION Page 7



L4 = Complement of {ww| w ∈ 𝑎, 𝑏 * − 𝑥 | 𝑥 ∈ 𝑎, 𝑏 𝑎𝑛𝑑 𝑥 𝑖𝑠 𝑜𝑑𝑑 𝑖𝑛𝑡𝑒𝑔𝑒𝑟
= NCFL – Regular = NCFL.
Q6. Which of the following language is/are DCFL?
L1 = {wwR| w  a*b*}
L2 = {w| w{a, b}* and each prefix of w has at least as many a‟s as b‟s}
L3 = {w| w {a, b}* and m na(w) = k nb(w) for arbitrary constants m and k}
(A) Only L2 (B) L2 and L3
(C) L1 and L3 (D) All of the above
Answer: D
Solution:
i) L1: {wwR | w belongs to a*b*}
Here w can be aaa or aabb or aaabb or aab or bb or bbb etc.
Now languages has strings like
if w = aaa then aaaaaa∈ 𝐿1
if w = aab then aabbaa∈ 𝐿1
if w = bbb then bbbbbb∈ 𝐿1
if w = bb then bbbb∈ 𝐿1
if w = aabbb then aabbbbbbaa∈ 𝐿1
and so on.
𝜆, 𝑎2 , 𝑎4 , 𝑎6 , …
𝐿1 = 𝑏2 , 𝑏4 , 𝑏6 … , = 𝑎𝑎 ∗ + 𝑏𝑏 ∗ + 𝑎𝑛 𝑏2𝑚 𝑎𝑛 | 𝑛, 𝑚 ≥ 0 .
𝑎𝑏𝑏𝑎, 𝑎𝑎𝑏𝑏𝑎𝑎, 𝑎𝑏𝑏𝑏𝑏𝑎, …
So, it is DCFL because 𝑎𝑛 𝑏2𝑚 𝑎𝑛 | 𝑛, 𝑚 ≥ 0 is DCFL.
ii) L2:
if „a‟ then push „a‟ on stack if „b‟ arrives then pop „a‟ from stack. If „b‟ arrives and stack is
empty then strings doesn't belong to L2. At last stack should contain „a‟ only or it should
be empty.
iii) L3:Let m = 1, k = 1 then L is DCFL.

Q7. Which of the following language is/are NCFL?


(i){0n1n| n >0}∪ {0n12n| n ≥ 0}
(ii){1n0n1m| m, n >0}∪{1m0n12n| m, n ≥ 0}
(iii){0n1n| n >0}∪{12n0n| n ≥ 0}
(A) i only (B) i, ii and iii only
(C) iii only (D) ii only
Answer: B
i) it is NCFL because we don‟t know whether to pop 0 on single 1 or double 1.
ii) It is NCFL because we don‟t know whether to push 1 on stack or 0 on stack. Because
in first part we have to push 1 on stack to ensure equal number of zeros and in second
part we have to push 0 on stack to ensure 2 time number of 1.
iii) It is DCFL so NCFL as well.

BASIC THEORY OF COMPUTATION Page 8


Q8. Which of the following language is/are context free?
(i) L = {anbn: n  0 and n is not a multiple of 5}
(ii){1k0i1i0j1j0k | i, j, k > 0}
(iii) {w#x | w is a substring of x, where w, x are in {0,1}*}.
(iv) {0i1i0j1i | i, j > 0}
(v) {(0n1n)m| m, n > 0}.
(vi) Complement of {(0n1n)m| m, n > 0}.
(A) i, ii and vi only (B) i and ii only
(C) iii and v only (D) i, ii, iii and v only
Answer: B
Solution:
(i) L= {anbn: n  0 and n is not a multiple of 5} = 𝑎𝑛 𝑏𝑛 | 𝑛 ≥ 0 − 𝑎 5𝑛 𝑏5𝑛 | 𝑛 ≥ 0

(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.

BASIC THEORY OF COMPUTATION Page 9


Q9. Which of the following language is/are context free?
L1 = {w {a, b, c}*|na(w) = nb(w) ≤ nc(w)}
L2 = {anbm| n and m are both prime}
L3 = {anbjakbl| n ≤k, j ≤l}
L4 = {w {a, b}*|na(w) = nb(w),w does not contain a substring aab}
(A)L2 only (B)L1 and L3 only
(C)L4 only (D)None
Answer:C
Solution:
i) ensuring more than one equality is not possible with one stack. So, it is not a CFL.
ii) ensuring prime number is not possible in CFL.
iii) it is not CFL because we are not able to ensure such equalities.
iv)
L = {w|w does not contain a substring aab} is regular and
M = {w ∈{a, b}*|na (w) = nb(w)} is CFL.
L4 = L intersection M is CFL, because context free languages are closed under regular
intersection.

Q10. The language L = {(a+b+c)*wcwR, where w (a+b)+} is


(A) Regular (B) Deterministic CFL
(C) Non- Deterministic CFL (D) Not a CFL
Solution: L = {(a+b+c)*wcw where w(a+b) } and abcabcba L.It is accepted by
R +

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

Q11. The language L = {wRcw(a+b+c)*, where w (a+b)+} is


(A) Regular (B) Deterministic CFL
(C) Non- Deterministic CFL (D) Not a CFL
Solution: L= L = {wRcw(a+b+c)*}
It is accepted by DPDA.abcba (a+b+c)*
push wR than if string is ab than push it on stack if input is b and top of stack contain b
than pop b, than if top of stack contain a and string is b than pop a {and then accept
String of abc.So it is deterministic CFL.
Answer: B

BASIC THEORY OF COMPUTATION Page 10


Q12. Which of the following is/are not CFL?
(i) L = {www | w {0, 1}}
(ii) L = {0n | n is perfect square}
(iii) L = {0n | n is either prime number or odd number or both}
(iv) L = {0n | n is not perfect cube}
(A) i only (B) ii and iv only
(C) ii, iii and iv only (D) i and iv only
Solution:
(i) L= {www|w {0, 1}. It is CFL; because w is either 0 or 1 it finite language.
(ii) L= {0n| n is perfect square}
L= {04, 09, 016………………}
Here we can‟t say about number of zero‟s.
So it is not CFL.
(iii) It is CFL and it is also regular.
L= {0n|n is either prime or odd or both}
So

So it is regular and CFL also.


Answer: B
Q13. [MSQ]
Which of the following language is/are context free?
(A) L = {anbn: n  0 and n is neither prime nor composite}
(B) L = {ap | p is prime number or p = 0}. {ap | p is not a prime number}
(C) L = {0i1i0i1i | i is a prime number and 0 < i < 100}
(D) L = {(0n1m)k| m, n >= 0}.
Answer: a, b, c, d
Solution: A) It is finite so regular so CFL as well.
B) L = {a0,a2,a3,a5,a7,a11,....}.{a0,a1,a4,a6,a8,a9,...} = a* hence reular so CFL as well.
C) It is finite so regular so CFL as well.
D) It is regular so CFL as well.

BASIC THEORY OF COMPUTATION Page 11


Q14. [MSQ]
Which of the following language is/are context free?
(A) L1 = {w {a, b, c} | na(w) = nb(w) = nc(w)}
(B) L2 = {anbm|n/m is integer ;where n & m are prime numbers}
(C) L3 = {anbjakbl| n = k and j =2l}
(D) L4 = {ww | w {a, b}*and na(w) < 2nb(w)) <100}
Answer: a, b, d
Solution:
L1 = {}; because w can be either „a‟ or „b‟ or „c‟. So, it is regular.
L2 = {}; because one prime doesn‟t divide any other prime number. So, it is regular.
L4 is finite. So, it is regular.
L1, L2 and L4 all are finite languages so Regular therefore CFL as well.
For L3 such type of equality can‟t be ensured because we can access only top element of
stack so not a CFL.

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:

BASIC THEORY OF COMPUTATION Page 12


(A) It is point of indeterminism that where is the start point of x.
(B) It is DCFL because before occurrence of first c string is x and after c starting point of
x R.
(C) It is regular because it is (a + b + c)* and every regular language is DCFL.
(D) It is also DCFL. Same reason as option(B).

Q17. Which of the following language is/are DCFL?


1. L = {www | w 0*}
2. L = {wxw |w0*1* and x{0, 1}* }
3. L = {wxwR |w0*1* and x{0, 1}* }
(A) 1 only (B) 1 & 2 only
(C) 2 & 3 only (D) All the above
Answer: D
Solution:
1) It is regular and its regular expression is (000) * and so it is DCFL.
2) It is regular and its regular expression is (0+1) *and so it is DCFL.
3) It is regular and its regular expression is (0+1)*.So,it is DCFL.

Q18. Which of the following descriptions best fits the language


L = {x  {a b, c }* | #a(x) = #b(x) + #c(x) }
(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
(D) L is not a context-sensitive language
Answer: B
Solution:
To ensure equality #a(x) = #b(x) + #c(x) we need some memory which is not available in DFA or
NFA. We can check this equality with the help of single stack as if a arrives then push it on stack
and if b or c arrives then pop a from stack. At the end of string stack must be empty then string is
accepted otherwise reject.

BASIC THEORY OF COMPUTATION Page 13


Q19. [MSQ]
Let L1 be a context-free language and L2 L1 then which of the following statement
is/are true?
(A) L2 is definitely context-free.
(B) L2 may not be a context-free language.
(C) L1 L2 is definitely context-free.
(D) L1R is context sensitive.
Answer: b, c, d
Solution:
(A) Context free languages are not closed under subset for e.g.,
L2 = {aP | p is a prime number} and L1 = a*
L2 is subset of L1 but L2 is not context free.
(B) It is True because in some cases L2 can be context free for e.g.
L2 = {aP | p <= 100} andL1 = a*
L2 is subset of L1 and L2 is context free.
(C) Since L1 is context free and L2 is subset of L1 so L1 U L2 = L1 = context free.
(D) Context free languages are closed under reversal.

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.

BASIC THEORY OF COMPUTATION Page 14


Q21. Let L language collection of strings over {0, 1} containing ten more 0 than 1 or containing
ten more 1 than 0. This language is
(A) Regular
(B)Context free but not regular
(C) Recursive but not context free
(D) Recursively enumerable but not recursive
Answer: B
Solution:
To ensure #0(w) = #1(w) + 10 or #1(w) = #0(w) + 10 we need stack so it is CFL but not
regular.
There is point of indeterminism that whether to push 0 on stack or 1 on stack.
If #0(w) = #1(w) + 10 then push 0 on stack and if #1(w) = #0(w) + 10 then push 1 on
stack.

Q22. Which of the following languages is/are context free?


1. {ai| i is prime}
2. {(anb)n|n 1}
3. {(anb)m|m, n 1}
(A)Only 1&2
(B)Only 2&3
(C)Only 1&3
(D)None
Answer: D
Solution:
(1) {ai | i is prime} It is not CFL. Whether a number is prime this cannot be computed with a
stack.
(2) {(anb)n |n >= 1} It is not CFL because we have to ensure equal number of a’s more than one
time which is not possible with single stack.
(3) {(anb)m |m, n >= 1} here also same reason as point 2. So, it is not CFL.

Q23. Consider the following language L = {anbnanbn: n ≥ 0}.Which of the followingstatement


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.

BASIC THEORY OF COMPUTATION Page 15


Solution:
L = {anbnanbn: n ≥ 0}
This is not context free, but it is accepted by context sensitive grammar.
It is not context free because if input is a than push a , and if b and top of the stack
contain a than pop a , so we can ensure that a=b, of starting but we can‟t ensure that
anbnanbn. anbnan, here a is equal so it is not context free.
Answer: C
Q24. Which of the following languages is/ are not context free?
(i) L = {aibjckdl | i+j = k+l and i, j, k, l N}
(ii) L = {0n#02n#03n | n>=0}
(iii) L = {uawb | u, w  {a,b}* and |u| = |w|}
(iv) L = {w ∈ {a, b}* : w has twice as many b's as a's}
(v) L = {amb2nc3ndp: p > m, and m, n ≥ 1}.
(A) iv and v only (B) ii only
(C) ii and v only (D) i, iii, iv, v
Solution: (i) L = {aibj ckdl | i+j = k+l and i, j, k, l N}
here i+ j= k+1In this push a then push b if input is c then pop item from top of stack ,
then d and pop item from top of stack.and input is  and top of stack contain $, then
we can ensure that i+j =k+1.So it is CFL.

(ii) It is not CFL.


L= {0n# 02n # 03n |n>=0}
Push 0, then # and if input is 0 then on two 0 pop one 0 from stack top , so here we can
ensure 0n 02n, but we can‟t say about 03n .So it is not context free language.

(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

BASIC THEORY OF COMPUTATION Page 16


Q25. Which of the following languages is/are CFLs?
L1 = {0i1j2k |i<j<k}.
L2 = {w(0+1+2)*| w does not contain the same number of all 3 symbols}.
L3 = {uawb|u,w(a+b)*,|u|=|w|}
L4 = {bibi+1|bi is i in binary i  1}. The alphabet here is {0,1,}.
(A)L1 and L2 only (B) L2, L3 and L4 only
(C) L3 only (D) L3 and L4 only
Solution: L1:- {0i1j2k |i<j<k}
This language is not in CFL because here we need to again check two condition first k>j ,
j>I , so at a time we can‟t ensure this by PDA So L1 is not CFL.
L2:- It is also not in CFL, because of same reason.
L3:- It is in CFL, It is accepted by NDPDA.
L4:- bi = 010, bi+1= 011
L4 is like ww. So, it is not CFL.
Answer: C
Q26. Which of the following languages is/are context free?
L1 = {aibkcj | j= max (i, k) }
L2 = {x ∈ {a, b}* : |x| is even and the first half of x has one more „a‟ than does the second
half}.
L3 = {w ∈ {a, b}* : the first, middle, and last characters of w are identical}.
L4 = {aibj |i = kj for some positive integer k}
(A) L2 only (B) L3 only
(C) L1 & L2 (D) L2 & L3
Solution:
L1, we have two comparisons 1st for finding maximum, 2nd for equality of j & max.
 It is not CFL, because it requires two stacks.
L2:- It is accepted by NDPDA.
It is NCFL.
L3:- L3 is accepted by NCFL.
i.e., By NDPDA, we can ensure L3.
Since By DFA, we can ensure 157 & last symbol are identical then, by NPDA we can
ensure 1st, middle & last symbol identical, if know middle character.
L4: It is not CFL because we have infinite value of k.
L2 & L3 are CFL. So, (D) is correct.Answer: D

BASIC THEORY OF COMPUTATION Page 17


Q27. Consider the following language L = {wR#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:
wz here w is substring of z. means w is abb. bba#babb
than in this we need to push bba on stack than if „id‟ is # than change the state if is b
and top of stack is b than pop b, if not than again read input a and top of stack is a
than pop „a‟ so on. So, for this we need to make NDPDA. So, it is NCFL.
so, it is context free not regular.
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:
wz
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

BASIC THEORY OF COMPUTATION Page 18


Q29. The language L = {0i1j2i3j |i, j ≥ 0} is
(A) Regular (B) Deterministic CFL
(B) Non-Deterministic CFL (D) Not a CFL
Solution:
{0i1j2i3j |i, j ≥ 0}
If input is 0 than push 0 then input is 1 than push 1 , than input is 2 than we need to pop
zero for ensuring that number of 0= number of 2 , but top of the stack contain 1, we can‟t
ensure that number of 0 = number of 2.So it is not CFL.
Answer: D
Q30. The language L = {0i1j2j3i |i, j ≥ 0} is
(A) Regular (B) Deterministic CFL
(C) Non-Deterministic CFL (D) Not a CFL
Solution:
Input is 0 than push zero ,than if is 1 than push 1 and input is 2 and top of stack contain
1 than for each two pop a 1, and than input is 3 than for each 3 pop, one zero if input is
null and top of stack also null, means language is accept.
Answer: B
Q31. The language L = {0i1j |i, j ≥ 0 and i = 3j} is
(A) Regular (B) Deterministic CFL
(C) Non-Deterministic CFL (D) Not a CFL
Solution:
Push zero on stack and for each one pop 3 zero from top of the stack.So it is deterministic
CFL.
Answer: B
Q32. Which of the following language/s is/are not CFL?
1. L = {anbncmambncn | n  0, m  0}
2. L = {anbmcn| n = 3m & n  0, m  0}
3. L = {ambncm#wwR#wcwR| w{a, b}* and wR is reverse string of w}
(A)1 only (B)2 & 3 only
(C)1&2 only (D)none
Solution:
(1) L = {anbncmambncn | n  0, m  0}
not ensured by single stack . not CFL, we can use stack for anbn and cman. but not bncn.
because we can’t ensure an bn . and bn cn by single stack.
(1) is not CFL.
(2) L= L = {anbmcn| n = 3m & n  0, m  0}
 not CFL. because 2 stack are required.

BASIC THEORY OF COMPUTATION Page 19


(3) L = {ambncm#wwR#wcwR| w{a, b}* and wR is reverse string of w}
here also 2 stack are required .
It is not CFL .
Answer: None
Or

BASIC THEORY OF COMPUTATION Page 20


Q33. Let L1 = {w: w is palindrome & w {a, b}*} and L2 = {wwR#w : w{a, b}*}, then.
Which of the following statement is not true?
(A) L1 is CFL but L2 is DCFL.
(B) L1 is DCFL but L1 is not DCFL.
(C) Both L1 and L2 are CFL.
(D) L1 is CFL but L2 is not CFL.

Solution:
L1 = {w : w is palindrome & w {a, b}*}NCFL
L2= {wwR # w} not CFL
two stacks are required.
Answer:D

Q34. Which of the following languages on 𝛴 = {a, b} is/are context- free?


(i) L = {aibj | i ≤ j3}
(ii) L = {aibj | i + j is an even number}
(iii) L = {aibj | i * j is composite number}
(iv) L = {aibj | i + j is an odd number}
(A) Only i, iii
(B) ii, iv only
(C) Only i, ii and iv
(D) all
Solution:
(i) L= {aibj|ij3}
one stack  for j3 = x(say)
2nd stack ix
not CFL
(ii) L = {aibj | i + j is an even number}
It is regular
Regular expression = a(aa)*b(bb)* +(aa)*(bb)*
It is CFL .

BASIC THEORY OF COMPUTATION Page 21


(iii) L = {aibj | i * j is composite number}
is not ensured by single stack.
not CFL.
(iv) L = {aibj | i + j is an odd number}
It is regular. regular expression = (aa)*b(bb)*+a(aa)*(bb)*
correct answer is (B).
Answer:B

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

Q36. Which of the following language is/are DCFL?


(A) L = {anbm| n m }
(B) L = {w#wR|wR is reverse of w}
(C) L = {anbm | n≤m≤3n}
(D) both a&b
Solution:
(a) L = {anbm| n m}DCFLbecause sometimes n>m and n<m
 PDA can be constructing.

BASIC THEORY OF COMPUTATION Page 22


(b) L= {w#wR|wR is reverse of w}
When „a‟ comes then push a. And „b‟ comes then push b. i.e. before „#‟ push
everyalphabet after that , when „a‟ comes and top of the stack is also „a‟ then pop i.e.
when input alphabet and top of stack are same then pop.At the end, if we have no
input alphabet and stack is empty then we can say string is accepted otherwise
rejected.
(c) L = {anbm | n≤m≤3n}= {anbn| n>= 0} {anb2n| n>= 0}{anb3n| n>= 0}
Due to these three cases,it is NCFL.
Q37. Which of the following language is/are not CFL?
1. L = {anbmck | k = HCF(m, n)} 2. L = {anbmck | k = LCM(m, n)}
3. L = {anbmck | k = max(m, n)} 4. L = {anbmck | k = min(m, n)}
(A)1 & 2 only (B) 3 & 4 only
(C)2 & 4 only (D) All the above
Solution:
(1) L= {anbmck |k= HCF(m,n)}
We have required one stack to find HCF and other stack is required to check equality of k
and result of HCF.
 It is not CFLand, similarly all are not CFL.
Answer:D

Q38. Which of the following language/s is/are CFL?


1. If L1 = {wwR| wR is reverse of w} then L1.L1.L1 is CFL.
2. If L2 = {wwRwwRwwR| wR is reverse of w} then L2 is CFL.
3. If L3 = {wwR| wR is reverse of w}, then complement of L3 is NCFL.
(A)1 only (B)1 & 3 only

BASIC THEORY OF COMPUTATION Page 23


(C)2 & 3 only (D)All the above
Solution:
(1) L1= {wwR| wR is reverse of w} CFL.
L= L1.L1.L1 = concatenation of CFL = CFL
(2) L2 = {wwRwwRwwR| wR is reverse of w}
not ensured by single stack
(3) L3 is NCFL.
 Complement of L3 is NCFL.
Answer:B

Q39. Which of the following language is/are DCFL?


1. L = {uv : u vR where u, v Σ* and vR is reverse of v}.
2. L = {uv : u contains even number of 0 and v contains odd number of 1;
Where u, v  {0, 1}*}.
3. L = {uv : u L1& vL1; where L1 is DCFL }
4. 1. L = {u#v : u vR where u, v Σ* and vR is reverse of v}.
(A) 1, 3 only (B) 1, 3, 4 only
(C) 2, 3, 4 only (D) All the above
Solution:
1) L1= {wwR |wR is reverse of w}
L= L1. L1.L1 = concatenation of CFL= CFL
2) L2 = {uv : u contains even number of 0 and v contains odd number of 1}
It is regular and NFA for this.

After concatenation, we get L.


 L is DCFL.
3) L = {uv : uL1 and v L where L1 is DCFL}
= concatenation of two DCFL L1and L1
= DCFL.
 2 and 3 are DCFL.
(4) L= {u#v:u vR}

BASIC THEORY OF COMPUTATION Page 24


Before #, every element / alphabet will be pushed and after #, when input alphabet and top of the
stack is same, then p otherwise string is rejected. If input is finished and top of the stack is empty
then string will be accepted by PDA
 It is DCFL.
Answer:C

Q40. Which of the following languages are NOT context-free?


L1 = {0n+m1n0m|n, m ≥ 0},
L2 = {0n+m1n+m0 m |n, m ≥ 0}, and
L3 = {0n+m1n0n+ m |n, m ≥ 0}
(A) L1only (B) L3 only
(C) L1 and L2 (D) L2 and L3

BASIC THEORY OF COMPUTATION Page 25


BASIC THEORY OF COMPUTATION Page 26
Q41. A context-free grammar G is ambiguous if and only if
(A) Some string w ∈ L(G) has at least two different derivations.
(B) Some string w ∈ L(G) has at least two different parse trees.
(C) Every string w ∈ L(G) has at least two different parse trees.
(D) Every string w ∈ L(G) has at least two different derivations.

Q42. Consider the following grammar: (Assume starting symbol is S)


G1 G2
S  aA | bB | cS | aS S  aS | bSa | aSb | bS
A  bAa | λ |λ
B  bB | a
Which of the following grammar is/are ambiguous?
(A) G1 only (B) G2 only
(C) Both G1 & G2 (D) Neither G1 nor G2
Answer: C
Solution:
Grammar G1:
For string „caba‟, G1 has two parse trees corresponding to following derivations:
1. S  cS  caA  cabAa  caba

BASIC THEORY OF COMPUTATION Page 27


2. S  cS  caS  cabB caba
Grammar G2:
For string „ba‟, G2 has two parse trees corresponding to following derivations:
1. S  bSa  ba
2. S  bS  baS  ba
So, we can say that both G1 and G2 are ambiguous grammar.
Q43. [MSQ]
Which of the following grammars have more than one parse tree for the string ‘1001’?
(a) (b) (c) (d)
S  XY S  XY S  0S | 1S | SS S  1S0S
X 0X | 1X | λ X 0X1 | 1X0|λ S0|1 S  0S1S
Y1Y1 | 0Y0 | Y1Y| 0Y |λ S λ
λ

BASIC THEORY OF COMPUTATION Page 28


Q44. [MSQ]
Consider the following grammar G with starting symbol S:
S  aSb | bSa | aSa | bSb | AB | BA
A  aA | λ
B  bB | λ
For which of the following string(s), G has more than one parse tree?
(A) ab (B) aabb
(C) abba (D) abab

BASIC THEORY OF COMPUTATION Page 29


Answer: a, b, c, d
Solution:

Q45. Consider the following grammar G with starting symbol S:


S  aSb | bSa | aSa | bSb | AB | BA
A  aA | λ
B  bB | λ
How many different parse trees are possible for string „abba‟? ___________
Answer: 3
Solution:

BASIC THEORY OF COMPUTATION Page 30


Q46. Which of the parse trees below yield the same word?

(A) iii and iv only (B) i, ii and v only


(C) ii and v only (D) iii, iv and vi only
Solution:
Option (ii) and (v) yield the same word.
 ababababababa
 ababababababa
Answer: C

Q47. Here is a parse tree that is derived from some unknown grammar G.

BASIC THEORY OF COMPUTATION Page 31


Which of the following productions is not surely for grammar G?
(A) S → ABS (B) A → aB
(C) S → AB (D) S → aA
Solution:
S→ABS surely production rules.
S→AB
S→aA {Also surely production rule}
A→aB {For this we can‟t say anything) .
Because on parse tree A is not replaced by aB.
Answer: B

Q48. The parse tree below represents a rightmost derivation according to the grammar
S → ABS|AB|aA, A → aS|a, B → bA

Which of the following is a right-sentential form in this derivation?


(I) ABaA (II) bAba
(III) aaBB (IV) aabAba
(A)I&II only (B) III & IV only
(C) I only (D) All except III
Solution:
S→ABS
S→ABaA
So only (i) is right sentential form in this derivation.
So, Answer is C.

BASIC THEORY OF COMPUTATION Page 32


Q49. Consider the following context free grammar: G = ({S, A, a, b}, {a, b}, R, S),
where R = {S aAS S  a ASbA A SS Aba } and parse tree for the string
“aaaabaa” is shown below:

Which of the following are left-sentential forms corresponding to this derivation?


(i) aAS
(ii) aSS
(iii) aaSS
(iv) aaS
(v) aaaaAS
(A)i, iii and v only (B)ii and iv only
(C)ii, iii and v only (D)All the above
Answer: A
Solution:
Left most derivation of “aaaabaa”:
S-> aAS
S-> aSSS
S-> aaSS
S-> aaaS
S-> aaaaAS
S-> aaaabaS
S-> aaaabaa
So, Left-sentential forms are i, iii, and v

BASIC THEORY OF COMPUTATION Page 33


Q50. Consider the grammar (with start variable S and terminals a and c).
S  SaS | cS | cc
Which of following parse trees matches the grammar?

(A) i ,iii,iv (B)iii,iv


(C)ii (D)i and iv
Answer: A
Solution:
S-> aSS is not a production rule so parse tree 2 doesn‟t belongs to grammar.
Q51. Consider the following CFG
S → aB | bA
B → b | bS| aBB
A → a| aS| bAA
Now consider the following derivation of above CFG
S ⇒ aB ⇒ aaBB ⇒ aaBb ⇒ aabSb ⇒ aabbAb ⇒ aabbab
This derivation is
(A) a leftmost derivation
(B)a rightmost derivation
(C)both leftmost and rightmost derivation
(D)neither leftmost nor rightmost derivation

BASIC THEORY OF COMPUTATION Page 34


Q52. Given the simple CFG with non-terminals {S,A,B}, terminals {a,b}, and productions
S → AB, A → AB | a, B → BA | b.
Which of the following derivation is NOT a derivation of the string abab?
(A) S ⇒ AB ⇒ Ab ⇒ABb ⇒ ABAb ⇒ AbAb ⇒ Abab ⇒ abab
(B) S ⇒ AB ⇒ ABB ⇒ ABAB ⇒ aBaB ⇒ abab
(C) S ⇒ AB ⇒ ABA ⇒ ABAB ⇒ ABAb ⇒ AbAb ⇒ Abab ⇒ abab
(D) S ⇒ AB ⇒ aB ⇒ aBA ⇒ abA ⇒ abAB ⇒ abaB ⇒ abab

Answer: B

Solution: Cannot replace two non-terminals simultaneously because derivation is a step-


by-step procedure.

BASIC THEORY OF COMPUTATION Page 35


Q53. Consider the following grammar G with start symbol S:
S if id then S else S
S  if id then S
S  id
Which of following is/are true?
(i) G is Type 3 grammar.
(ii) G is Type 2 grammar
(iii) G is unambiguous grammar.
(iv) G is ambiguous grammar.
(A) i, ii and iv only (b) ii and iv only
(C) ii and iii only (D) i, ii and iii only
Solution:
(i) Type 3 is regular grammar, but G is not regular, because regular grammar said that a
non –terminal followed by terminal or terminal followed by a non – terminal. So this
grammar is not in this form, so it is not type 3 grammar.

(ii) It is type 2 grammar.

(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

BASIC THEORY OF COMPUTATION Page 36


Solution:
(i) G is type 2: is true because type 2 grammar is context free grammar and by the
definition of Type 2 grammar left hand-side should contain single non terminal.
So it is type 2 grammar.
(ii) G is ambiguous: -true [S → 0A→ 01S → 01, and S → 0A → 01]

(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
0011010110L(G) So, 1111100101000L(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

BASIC THEORY OF COMPUTATION Page 37


Q56. Consider the following statements about the context free grammar
G = {S -> SS, S ->ab, S ->ba, S ->ɛ}
Which of the following statements is/are true about G
I. G is ambiguous.
II. G produces all strings with equal number of a‟s and b‟s.
III. L (G) can be accepted by a deterministic PDA.
(A) I only
(B) I and III only
(C) II and III only
(D) I, II and III

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 as and bs” False.
Because it doesn‟t generate a string of the form aabb.
(iii) (ab + ba)* it generates (ab+ba)*, but it accepted by DPDA.

Q57. Consider the grammar G given by the productions


S → aSa | aBa | b | λ
B → bB | b
Then which of the following is/are true about G?
(i)G is context sensitive grammar.
(ii)G accept the language L where L = {aibjak | i = k and i, j, k  0}.
(iii) G is not unambiguous.
(A)ii only (B) ii & iii only
(C)i & ii only (D) All are true

BASIC THEORY OF COMPUTATION Page 38


Solution:
S→aSa|aBa|b|
B→bB|b
(i) Context sensitive grammar said that ||||.
and for S→
|1|1 |1|= |1|
because in grammar length of  is 1.
(ii) It is also true.
S →aSa
S→ aaSaa
S→ aabaa
here always generate the string where left a= Number of right a
ai bjak {i =k}.
(iii) G is not unambiguous: - True
Because G is ambiguous for string aba.
Because for aba there is two parse tree.

So it is ambiguous.
Answer: D

Q58. Consider the following grammar G


S  TC | AR
T aTb | 
C  Cc | 
R bRc | C
A Aa | 
The language is generated by G is : (Assume i, j, k>=0)
(A) L = {aibjck | k = j and i>=j} (B) L = {aibjck | i = j and k>=j}
(C) L = {aibjck | i = j or k>=0 } (D) L = {aibjck | i = j or k>=j}
BASIC THEORY OF COMPUTATION Page 39
Solution:
S→ TC → aTbC → aaTbbC → aabbC → aabbCc → aabbc
This string is generated by grammar.
Check for option (a) :- Option (a) is false.
L= {aibj ck |k=j and i>j}
but in this string aabbc, j≠k and i>=j
So this option (a) is incorrect because in string aabbc , j≠k.
Now check for option (b).
L= {ai bjck|i=j and kj}
in string aabbc, i=j but k doesn‟t j
so option b is also incorrect .
Now check for option ( c):-
String aabbc is satisfied by option c.
but if we take S→AR
S→.
Language L on option (c) accept aaabbc here i≠j but k>=0
but this string is not generated by grammar.
option (d):
ai bjck|i=j or k>=j}
option d is true it accepts all string that generated by grammer.
Answer: D
Q59. Consider three language L1, L2, L3 and three grammar G1, G2, G3:
L1 = {aibjck | k = i +2*j}
L2 ={aibick | k>=3},
L3 = {aibjck | k = i +j}
G1: G2: G3:
S aSc | T S aSc | T S  TC
T bTc |  T bTcc |  T aTb | 
C  Cc | ccc

Which of the following language, grammar pair (L, G) are equivalent?


(A)(L1, G1), (L2, G2), (L3, G3) (B)(L1, G3), (L2, G2), (L3, G1)
(C)(L1, G2), (L2, G2), (L3, G3) (D) (L1, G2), (L2, G3), (L3, G1)
Solution:

BASIC THEORY OF COMPUTATION Page 40


G1:- S→aSc
S→aaScc
S→aaTcc
S→aabTccc
S→aabccc
k=3, i=2, j=1
3= 2+2*1
34
So G1 is not corresponding to L1.
for this string (aabccc) for L2 , and L3 satisfy .
So check for another string.
S→aSc
S→aTc
S→abTcc
S→abcc
Now this is false for L2, because L2 said that k should be  3. but here k=2.
Now check for grammer G2:
S→aSc
S→aaScc
S→aaTcc
S→aabTcccc
S→aabcccc
in this k=4 i=2 j=1
42+1, 43 so doesnot corresponding to L3.
k=4 i=2 ,j=1
4= 2+2
4=4
Now this string corresponds to L1 and L2 both.
Now check for another string.
G2:
S→aSc

BASIC THEORY OF COMPUTATION Page 41


S→aaScc
S→aaaScc
S→aaaSccc →aaabTccccc→aaabccccc
k=5, i=3 j=1
5=3+2*1
5=5
So G2 is correspond to L1 and L2 also. But G2 generate , but L2 can‟t generate .
because k should >=3 , so G2 corresponding to L1.
Answer: D
Q60. Match the columnwhich CFG corresponds to which language?
Language Grammar
1. {0n1n | n>0} U {0n12n | n>0} i. S  0A1 | 0B11
A  0A1 | 
B  0B11 | 
2. Binary strings with twice as many 1s ii. S 0A0 | 1A1
as 0s. A  0A | 1A | 
3. {w  {0,1}*| w starts and ends with iii. S → 0A11 |
the same symbol} A → 0A11 | 
(A) 1-i, 2-iii, 3-ii (B) 1-ii, 2-i, 3-iii
(C) 1-ii, 2-iii,3-I (D) 1-i, 2-ii, 3-iii
Answer: A
Solution:
i.
A  0A1 |  ⟹ 0𝑛 1𝑛 | 𝑛 ≥ 0
B  0B11 |  ⟹ 0𝑛 12𝑛 | 𝑛 ≥ 0
S  0A1 | 0B11 ⟹ 0𝑛 1𝑛 | 𝑛 > 0 ∪ 0𝑛 12𝑛 | 𝑛 > 0
Language generated by above grammar = 0𝑛 1𝑛 | 𝑛 > 0 ∪ 0𝑛 12𝑛 | 𝑛 > 0
ii.
A  0A | 1A |  ⟹ 𝑤 | 𝑤 ∈ 0, 1 ∗
⟹ 0+1 ∗

S 0A0 | 1A1 ⟹ 0 0 + 1 ∗ 0 + 10 0 + 1 ∗ 1

BASIC THEORY OF COMPUTATION Page 42


Language generated by above grammar
= {w  {0,1}*| w starts and ends with the same symbol}
iii.
A → 0A11 |  ⟹ 0𝑛 12𝑛 | 𝑛 ≥ 0
S → 0A11 | ⟹ 0𝑛 12𝑛 | 𝑛 ≥ 0
Language generated by above grammar L= 0𝑛 12𝑛 | 𝑛 ≥ 0
L contains the strings with twice as many 1s as 0s.
So, 1 – i, 2 – iii, 3 – ii.
So, option A is correct.

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:

BASIC THEORY OF COMPUTATION Page 43


(A) It will generate 0; It contains a lesser number of 1‟s than 0‟s. So, this is false.

(B) It will not generate even length strings like 1011. So, this is false.

(C) It is correct because

T → TT | 0T1 | 1T0 |  ⟹ 𝑤 | 𝑤 𝑕𝑎𝑠 𝑒𝑞𝑢𝑎𝑙 𝑛𝑢𝑚𝑏𝑒𝑟 𝑜𝑓 0′ 𝑠 𝑎𝑛𝑑 1′𝑠

S → TS | 1T | 1S ⟹ 𝑠𝑒𝑡 𝑜𝑓 𝑎𝑙𝑙 𝑡𝑕𝑒 𝑠𝑡𝑟𝑖𝑛𝑔𝑠 𝑐𝑜𝑛𝑡𝑎𝑖𝑛𝑠 𝑚𝑜𝑟𝑒 1’𝑠 𝑡𝑕𝑎𝑛 0’𝑠

L = {1, 110, 101, 011, …}

(D) It will not generate 1. So, this is false.

Q63. Consider the following Pushdown Automaton (PDA) P1:


P1 = (Q = {q0, q1}, Σ = {a, b, c}, Γ = {0, 1, #}, δ, q0, Z0 = #, F = {q1}) where the transition
function δ is given by
δ(q0, a, #) = {(q0, 0#), (q0, 11#)}
δ(q0, a, 0) = {(q0, 00), (q0, 110)}
δ(q0, a, 1) = {(q0, 01), (q0, 111)}
δ(q0, b, 0) = {(q0, )}
δ(q0, c, 1) = {(q0, )}
δ(q0, , #) = {(q1, #)}
δ(q, w, z) = ∅ everywhere else Acceptance is by final state.
Which of the following words are accepted by the PDA P1?
(i) ab (ii) aababcc (iii) ac
(A)i only (B)i and ii only (C)i and iii only (D)iii only

BASIC THEORY OF COMPUTATION Page 44


BASIC THEORY OF COMPUTATION Page 45
Q64. Let M be the PDA

Which of the following strings are accepted by M?


(A)aaaa (B) baab (C) aaa (D) ab

Answer: (a)&(b)

BASIC THEORY OF COMPUTATION Page 46


Solution:
Answer is (a) &(b) It is NPDA
It accept the language like this L={xy | x|| =|y| ,na(x) = na(y) and also nb(x)= nb(y)}

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

BASIC THEORY OF COMPUTATION Page 47


BASIC THEORY OF COMPUTATION Page 48
BASIC THEORY OF COMPUTATION Page 49
BASIC THEORY OF COMPUTATION Page 50
Q66. Here are the transitions of a deterministic pushdown automaton. The start state is q0,
and f is the accepting state.
State-Symbol a b ε
q0-Z0 (q1,AAZ0) (q2,BZ0) (f,ε)
q1-A (q1,AAA) (q1,ε) -
q1-Z0 - - (q0,Z0)
q2-B (q3,ε) (q2,BB) -
q2-Z0 - - (q0,Z0)
q3-B - - (q2,ε)
q3-Z0 - - (q1,AZ0)
Identify below the one input string that the PDA accepts.
(A) bbbab (B)abbbab
(C)abbbabb (D) bbaabab
Answer:
Solution:

BASIC THEORY OF COMPUTATION Page 51


Q67. 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,ε)}
From the (p, 1101, XXZ0), which of the following states can NOT be reached?
(A) (p,101,XXZ0) (B) (p,1101,XZ0)
(C) (p,ε,XZ0) (D)(p,101,XXXZ0)

BASIC THEORY OF COMPUTATION Page 52


PDA to Language
Q68. Let M be the PDA defined by
Q = {q0, q1, q2} Σ = {a, b} Γ = {A} F = {q1, q2}
δ(q0, a, λ) = {[q0, A]}
δ(q0, λ, λ) = {[q1, λ]}
δ(q0, b, A) = {[q2, λ]}
δ(q1, λ, A) = {[q1, λ]}
δ(q2, b, A) = {[q2, λ]}
δ(q2, λ, A) = {[q2, λ]}
The language accepted by M is?
(A) The PDA M accepts the language {aibj| 0 ≤ i, j}
(B) The PDA M accepts the language {aibj| 0 ≤ i ≤ j}
(C) The PDA M accepts the language {aibj| 0 ≤ j ≤ i}
(D) The PDA M accepts the language {aibj| i = j}
Answer: C
Solution:

BASIC THEORY OF COMPUTATION Page 53


Option (b) is false: aibj|0 ij
In this number of b is more but PDA works like that if input is a then push on stack ,
and if input is b and top of the stack is a, then pop a. If input is empty and stack
contains A than pop A. so this show that ij. So answer is C.

Q69. The language accepted by following PDA is

(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

BASIC THEORY OF COMPUTATION Page 54


Q70. Let M be the PDA defined by
Q = {q0, q1, q2} = {a, b} = {A}F = {q1, q2}
(q0, a, ) = {[q0,A]}
(q0, , ) = {[q1, ]}
(q0, b,A) = {[q2, ]}
(q1, ,A) = {[q1, ]}
(q2, b,A) = {[q2, ]}
(q2, ,A) = {[q2, ]}
The language accepted by M is:
(A){aibj| 0≤ 𝑗 ≤ 𝑖} (B){aibj| 0≤ 𝑖 ≤ 𝑗}
(C){anbn| n≥ 0} (D){(ab)n | n≥ 0}
Answer: A
Solution:

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.

Q71. The language accepted by following PDA is:

(A){aibj| 0≤ 𝑗 ≤ 𝑖} (B){aibj| 0≤ 𝑖 ≤ 𝑗}
(C){anbn| n≥ 0} (D){(ab)n | n≥ 0}

BASIC THEORY OF COMPUTATION Page 55


Answer: B
Solution: If a arrives in input, then push A on stack.
If b arrives then if top of stack has A, then pop it. If stack is empty then simply move
ahead and read new input char. So, it will accept a followed by b and number of b
should be greater than or equal to number of a.
So, option B is correct.

Q72. The language accepted by following PDA

(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.

Q73. The language accepted by following PDA is:

(A){aicjbi | i,j≥ 0}
(B) {aicjbk | i, j, 𝑘 ≥ 0}
(C) {aicjbi | i, j> 0}
(D) {aibi | i≥ 0}
Answer: A
Solution:

BASIC THEORY OF COMPUTATION Page 56


whenever a arrives it pushes A on stack and whenever b arrives it pops A from stack.
It will accept the language where a followed by c followed by b and equal number of a
and b.
So, option A is correct.
Q74. The language accepted by following PDA is

(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.

BASIC THEORY OF COMPUTATION Page 57


Q75. Consider the following PDA

Which of the following grammar is equivalent to given PDA?


(A) S → SS | aSb | ab
(B) S → SS | ab | λ
(C) S → SS | aSb | λ
(D) S → aSb | λ
Solution:
(a,  → a) means ( means) whatever in the top of stack, just push a.
So it can generate string of the form abab, aabb.
If top of the stack is a, and input is b, than delete (pop) a.

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.

BASIC THEORY OF COMPUTATION Page 58


a, {input a and whatever in the top of stack push a.
then input is b and top of the stack contain a then pop a.

Q76. The language accepted by following automata is

(A) L = {aibjck | i= j or j = k} (B) L = {aibjck | i = j and j = k}


(C) L = {aibjck | i= j + k} (D) L = {aibjck | j = i + k}
Solution:
The given PDA accepts L= {aibjck| j=i+k}
Because, 1st a comes push a then b comes pop a again, if b comes then push b and then if c comes
pop b.
Answer:D
Q77. The language accepted by following automata is

(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 |ij 2i }
Because when a comes push A or AA , when b comes pop .
Answer: D

BASIC THEORY OF COMPUTATION Page 59


Q78. The language accepted by following automata is

(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

The language accepted by following PDA is?


(A) L = {anbncm : n>=0, m>=0} (B)L = {anbmcm : n>=0, m>=0}
(C) L = {anbm+ncm : n>=0, m>=0} (D)L = {anbncm : n>=0, m>=0}

BASIC THEORY OF COMPUTATION Page 60


Q80. The language is accepted by the following PDA is
M = (q0, q1,...., q5},{a, b},{0,1,a,z},,z,q0,{q5}),
(q0,b,z)={(q1,1z)},
(q1,b,1)={(q1,11)},
(q2,a,1)={(q3,)},
(q3,a,1)={(q4,)}
(q4,a,z)={(q4,z),(q5,z)}
(A){biaj+3|i≥1,j≥ 0} (B){biaj+3|i≥1,j≥ 1}
(C) {} (D) ∅
Answer: D
Solution: There is a no reachable path from initial state to final state. So, L =∅.

BASIC THEORY OF COMPUTATION Page 61


Q81. The language accepted by following PDA is

(A) L = {anbmcn+m n ≥ 0,m ≥ 0}.


(B) L = {anbn+mcm |n ≥ 0,m ≥ 0}
(C) L = {anbmcm n ≥ 0,m ≥ 0
(D) L = {anbmcn n ≥ 0,m ≥1}

Q82. The language accepted by following PDA is

BASIC THEORY OF COMPUTATION Page 62


(A) L = {anbmcm n ≥ 0, m ≥ 0}
(B) L = {a3bmcm m ≥ 0}
(C)L = {a3nbmcm n ≥ 0, m ≥ 0}
(D) None

For next two Question: Push down automata for


P = {Q = {q0, q0},  = {[,]},  = {A, B}, q0, F = { q1}, δ }
δ(q0,[, ε) = {( q0,A)}
δ(q0,], ε) = {( q0,B)}
δ(q0, ε, ε) = {( q1, ε)}
δ(q1,[,A) = {( q1,ε)}
δ(q1,],B) = {( q1, ε)}
δ(q, a, x) = ∅ otherwise
Q83. Suppose the current instantaneous description of P is < q1, AAAAA> and the unread
portion of the input is []][. The instantaneous description after one step is
(A) The machine crashes (B) < q1, AAAAAA>
(C) < q1, AAAA> (D) < q1, AAA>
Answer: C
Solution:

BASIC THEORY OF COMPUTATION Page 63


Q84. The language recognized by PDA is
(A) {[ n ]n | n≥0} (B) {[ i ] j : i≥j≥0}
(C) {wu | w, u {[,]}* and u is prefix of wR} (D) None of these
Answer: D
Solution: The language accepted by PDA is
L = {[[]], []][, [[][][ …}.
So, option D is correct.
Q85. The language accepted by following PDA is

(A) L = { na(w) + nb(w) = nc(w)} (B) L={anbmcm |m,n≥0}


(C) L = { na(w) + nc(w)= nb(w)} (D)None
Answer: A

BASIC THEORY OF COMPUTATION Page 64


Closure properties of CFL, DCFL, (DPDA, NPDA)
Q86. Let L1 be a context-free language and let L2 L1.
(A) L2 is definitely context-free.
(B) L2 may be a context free language.
(C) L1 and L2 is definitely not context-free.
(D) L2 never be a regular

BASIC THEORY OF COMPUTATION Page 65


Q87. Let L1 and L2 be two DCFL‟s. Then L1  L2 is guaranteed to be:
(A) Context-Free (B)Deterministic Context-Free
(C) Regular (D)can‟t say

BASIC THEORY OF COMPUTATION Page 66


Q88. Let L1 and L2 be two DCFL‟s. Then L1 U L2 is guaranteed to be:
(A) Context-Free (B)Deterministic Context-Free
(C) Regular (D)can‟t say
Answer: A
Solution: DCFL is not closed under union. Every DCFL is CFL and CFL is closed under
union. So, we can say that union of two DCFL may or not be DCFL but it is always CFL.

Q89. Let L be a DCFL. Then *- L is guaranteed to be


(A) Non-Deterministic Context-Free (B)Deterministic Context-Free
(C)Regular (D)can‟t say

Q90. Which of following is/are correct?


S1: If L1 and L1 U L2 are context free, then L2 must be context free.
S2: If L1 is context free and L2 is regular, then L1 − L2 is context free.
(A)Only S1 (B)Only S2
(C)Both S1&S2 (D)None of them
Answer: B
Solution:
S1: L1 = (a + b)* and L2 = {ap | p is a prime number}. Here L1 U L2 = (a + b)* = CFL.
Here L1 and L1 U L2 are context free, but L2 is not context-free. So, S1 is false.
S2: L1 − L2 = L1 ∩ 𝐿2𝐶 = CFL ∩ (regular)c = CFL ∩ (regular) = CFL. So, S2 is True.

BASIC THEORY OF COMPUTATION Page 67


Q91. Which of following is/are correct?
S1: If L1 is regular and L2 is context free, then L1 − L2 is context free.
S2: If L1 is regular and L2 is context-free, then L1  L2 must be a CFL.
(A)Only S1
(B)Only S2
(C)Both S1&S2
(D)None of them

BASIC THEORY OF COMPUTATION Page 68


Q92. Which of following is/are correct?
S1: Every infinite set of strings over a single letter alphabet ∑={a} contains an infinite
Context free subset.
S2:Every infinite context-free set contains an infinite regular subset.
(A)Only S1 (B) Only S2
(C) Both S1&S2 (D) Neither S1 nor S2
Answer: D
Solution: S1 is false when L = 𝑎𝑝 | 𝑝 𝑖𝑠 𝑎 𝑝𝑟𝑖𝑚𝑒 as a n infinite set of strings then it
doesn‟t have any infiniteContext free subset.
S2 is false when L = 𝑎𝑛 𝑏𝑛 | 𝑛 ≥ 0 as an infinite context-free set then it doesn‟t have any
infinite regular subset.

BASIC THEORY OF COMPUTATION Page 69


Q93. Which of following is/are correct?
S1: If both L and 𝐿are context-free, then L must be regular.
S2: There is a language L which is context-free but not regular such that 𝐿is also
Context-free.
(A) Only S1 (B) Only S2
(C) Both S1&S2 (D) Neither S1 nor S2
Answer: B
Solution: If L is DCFL then 𝐿 is DCFL.

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}

Q95. Which of following is/are correct statement?


(i) The language {0n1n U 0m1m| 0 ≤ n ≤ 1000,m>0 } is regular.
(ii) If a language is context-free, then it must be regular
(iii) If a language is regular, then it may be infinite.
(A)(i) and (ii) (B) (iii) only
(C)(i) and (iii) (D)(ii) and (iii)

BASIC THEORY OF COMPUTATION Page 70


Q96. The language L = {0i1i ⋃1i0i | i ≥ 0} is
(A) Regular (B) Deterministic CFL
(C) Non-Deterministic CFL (D) Not a CFL
Answer: B
Solution:
0i1i +1i0i

BASIC THEORY OF COMPUTATION Page 71


It is DPDA, because here is no confusion.
So it is deterministic context free language
Answer: B

Q97. Let L1 = {bnan | n ≥ 0} and L2 = {(ba)n | n ≥ 1}. What is |L1  L2|?


(A) 0 (B) 1
(C) 2 (D) infinite
Answer: B
Solution: Since L1  L2 = {ba} hence |L1  L2|= 1.

Q98. Let L1 = {bn | n ≥ 1}. What is L1.L1?


(A) {bnbn | n ≥ 1} (B){bn| n >1}
(C) {bnbm | m, n >1} (D) (bb)+
Answer: B
Solution:L1.L1 = {bn | n ≥ 1}.{bn | n ≥ 1} = {𝑏2 , 𝑏3 , 𝑏4 … } = {𝑏𝑛 } | 𝑛 > 1}

Q99. Let L1 = {anbn : n >=0}. Then L1.L1 is:


(A){anbn: n >=0} (B){anbnambm : m, n >=0}
(C){a2nb2n: n >=0} (D){anbnanbn : n >=0}
Answer: B
Solution:L1.L1 = 𝑎𝑏𝑎𝑏, 𝑎𝑏𝑎𝑎𝑏𝑏, 𝑎𝑎𝑏𝑏𝑎𝑏. . . = 𝑎𝑛 𝑏𝑛 𝑎𝑚 𝑏𝑚 | 𝑛, 𝑚 ≥ 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.

BASIC THEORY OF COMPUTATION Page 72


from this string we can draw conclusion that b is sum of a before b, and after b.
So language is anbn+m am : m,n>=0
Answer: D
Q101. Let L1 = {w | w* and w = wr,  = {a, b}} and L2= a*b*a* . Then L1 L2=
(A) {anbnam | n, m  0} (B) {anbman | n, m  0}
(C) {ambnan | n, m  0} (D) {anbnan | n, m  0}
Solution:
L1 L2 {aba, aa, bb , abba }  a * b*c* .so it generate string than has first and last is equal
, b can be any. anbman|n,m 0
Answer: B
Q102. Let L1 = {(ab)na | n ≥ 0} and L2 = {a(ba)n | n ≥ 0}. What is |L1 𝐿2|?
(A) 0 (B) 1
(C) 2 (D) infinite
Answer: A
Solution: L1 = (ab)*a, and L2 = a(ba)*. Here L1 = L2. So, |L1 𝐿2|= |L1 – L2| = 0.

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 ≠ 𝑘}

BASIC THEORY OF COMPUTATION Page 73


Q105. Let L1 = {anbncp |n, p≥0} and L2 = {ambncn| m, n≥0} then L1  L2 is
(A)  (B) a*b*c*
(C) anbncn (D) {* - a*b*c*}

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

BASIC THEORY OF COMPUTATION Page 74


Solution: L1 = {abcd, ac, aacc, abbccd, aaaccc …} and L2 = {ac, aacc, ca, ccaa, aaaccc …}
L1  L2 = {ancn | n>=0}.

Q107. Suppose L1 is a context-free language and L2 is a non-context-free language, such that


L1  L2 =  Then L1 U L2 is
(A) Necessarily context-free (B) Necessarily non-context-free
(C) May or may not be context-free (D)None of above
Answer: C
Solution:
Case I: Let L2 = {ww | w ∈ 𝑎, 𝑏 ∗ } and L1 = complement of L1.
Here L2 is non-CFL and L1 is CFL. And also L1  L2 =  .
Then L1 U L2 = (a + b)*; which is regular and also CFL.
Case II: Let L1 = ∅ and L2 = {ap | p is prime}.
Here L2 is non-CFL and L1 is CFL. And also L1  L2 =  .
Then L1 U L2 = { ap | p is prime}; which is non-CFL.
So, option C is correct.

Q108. Select the correct statement


(i) If L1 is context-free and L2 is regular, then L1 − L2 is context free.
(ii) If L1 is regular and L2 is context free, then L1 − L2 is context free.
(iii) L1 = L2 if and only if L1* = L2*
(A) Only i (B) ii & iii
(C) i & iii (D) None
Answer: A
Solution:
(i) It is true because L1 − L2 = 𝐿1 ∩ 𝐿2 = 𝐶𝐹𝐿 ∩ 𝑅𝑒𝑔𝑢𝑙𝑎𝑟 = 𝐶𝐹𝐿 ∩ 𝑅𝑒𝑔𝑢𝑙𝑎𝑟 = 𝐶𝐹𝐿.
(ii) It is False because L1 − L2 = 𝐿1 ∩ 𝐿2 = 𝑟𝑒𝑔𝑢𝑙𝑎𝑟 ∩ 𝐶𝐹𝐿 ; (may or may not be CFL)
Because CFL is not closed under complement.
(iii) It is false when L1 = a*b* and L2 = (a + b) then L1* = L2* but L1 ≠L2.

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.

BASIC THEORY OF COMPUTATION Page 75


Q110. Let A and B be two languages over {0,1} such that A is a subset of B. Consider the
following statements:
(1) If B is finite, then A is finite.
(2) If B is context-free, A is context-free.
(3) If the complement of B is context-free, then the complement of A is context-free.
Which of the above statements is true?
(A) 1 only (B) 1 and 2 only
(C) 1 and 3 only (D) 2 and 3 only
Answer:A
Solution: It is given that A is a subset of B.
1. If B is finite, then A is definitely finite because subset of finite is finite. So, it is true.
2. Subset of context-free language may not be context-free.
For example: 𝑎𝑛 𝑏𝑛 𝑐 𝑛 | 𝑛 ≥ 0 ⊆a*b*c*. So, it is false.
3. It is also false. Let B = complement of 𝑎𝑛 𝑏𝑛 𝑐 𝑛 | 𝑛 ≥ 0 and A = 𝑐 𝑛 𝑏𝑛 𝑎𝑛 | 𝑛 > 1
Here A ⊆ B and B is CFL. But A is not CFL.

Q111. How many of the following is/are correct statement? _____________


(i) For any CFG G there's a CFG G0 such that G0 is not ambiguous and L (G) = L (G0).
(ii) The CFLs are closed under symmetric difference.
(iii) If L is context free, the set of even-length strings of L are context free.
(iv) If the set of prime-length strings of L are context free and the set of composite-length
strings of L are context free then L itself is context free.
Answer:2
Solution:
(i)It is not necessary because there exists an inherently ambiguous context-free language
for which there doesn‟t exist any unambiguous grammar. So, it is false.
(ii)The CFLs are not closed under symmetric difference. So, it is false.
(iii) It is TRUE. We have to little bit change in PDA of L.
(iv) It is true.
If L = (the set of prime-length strings of L are context free) ∪ (the set of composite-length
strings of L are context free) ∪ (set of string of L of one length and zero length) = CFL

BASIC THEORY OF COMPUTATION Page 76


Q112. Which one of the following statements is FALSE?
(A) There exist context-free languages such that all the context-free grammars generating
them are ambiguous.
(B) An unambiguous context free grammar always has a unique parse tree for each
string of the language generated by it
(C) Both deterministic and non-deterministic pushdown automata always accept the
same set of languages
(D) A finite set of string from one alphabet is always a context-free language.
Solution
Both DPDA and NPDA don‟t accept the same set of language.
{anbn | n>=0} {anb2n | n>=0} (Accepted by Ndpda) but not dpda.
Answer: C
Q113. Consider the set of grammars in which every rule that has two symbols on the RHS
Must have exactly one variable and one terminal. These grammars can generates
(A) It generates all regular languages but no others.
(B) It generates some languages that are not context-free.
(C) It generates all regular languages and some others, but not all of the CFLs.
(D) It can generates all CFLs
Solution:
Set of grammars – {which either or right, linear or right linear, linear form}.
So, it generates all the regular language and some other, but not all CFL.
Answer C.
Q114. Which of the following statement is/are true?
S1: Any regular language can be generated by a context-free grammar
S2: Some non-regular languages cannot be generated by any CFG
S3: The intersection of a CFL and regular set is a CFL
S4: All non-regular languages can be generated by CFGs
(A) S1, S2 and S4 only (B) S1, S3 and S4 only
(C) S2, S3 and S4 only (D) S1, S2 and S3 only
Solution:
S1:- Regular language is also context free, so it is accepted by context fee grammar so
statement S1 is true.
S2:- Some non-regular language is not generated by any CFG is true.
- True; because some non-regular language like anbncn is also not context free, so it is not
generated by any CFG.
S3:-Intersect of CFG  Regular = CFL true.

BASIC THEORY OF COMPUTATION Page 77


anbn  =  { is CFL also}
anbn a*b* = anbn {It is CFL}
Answer: D

Q115. Which of the following statements is true?


(A) Both the regular languages and the context-free languages are closed under the
reverse operation.
(B) Neither the regular languages nor the context-free languages is closed under the
reverse operation.
(C) The regular languages are closed under the reverse operation but the context-free
Languages are not.
(D)The context-free languages are closed under the reverse operation but the regular
languages are not.
Solution: Both the context free and regular language are closed reversal.

Q116. Which of the following is true?


(A) If L is context free, then L* must be regular.
(B) If L is an infinite context-free language, then in any context-free grammar generating
L there exists at least one recursive rule.
(C) Both a and b are true.
(D) None of these.

BASIC THEORY OF COMPUTATION Page 78


Q117. Which of the following statement is correct?
(A) If there is no pushdown automaton accepting L, then L cannot be regular.
(B) If L is accepted by a deterministic PDA, then L' (the complement of L) must be
Regular.
(C) If, for a given L in {a, b}*, there exist x, y, z, such that y  and xynz L for all n  0,
then L must be regular.
(D) If L is regular and L = L1  L2 for some L1 and L2, then at least one of L1 and L2
must be regular.
Answer: A
Solution:
(a) It is correct because for every regular language there exists an equivalent PDA.
(b) It is false when L = 𝑎𝑛 𝑏𝑛 | 𝑛 ≥ 0 .
(c) It is False because pumping lemma cannot be used to proof that L is regular.
(d) It is False because L1 = 𝑎𝑛 𝑏𝑛 | 𝑛 ≥ 0 and L2 = 𝑏𝑛 𝑎𝑛 | 𝑛 ≥ 0 .
In this case L1 ∩ L2 = empty set; which is regular.

Q118. Which of the following is false?


(A) If L is an infinite context-free language, then there is some context-free grammar
generating L that has no rule of the form A  B, where A and B are nonterminal
symbols.
(B) Every context-free grammar can be converted into an equivalent regular grammar.
(C) Given a context-free grammar generating L, every string in L has a right-most
derivation.
(D) All are false.
Answer: B
Solution:

(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).

BASIC THEORY OF COMPUTATION Page 79


Q119. Select the correct statements
(i) Language {0, 11} is context-free.
(ii) There is a deterministic Push-down automaton for the language of even length
Palindromes.
(iii) There are some ambiguous context-free grammars that can be disambiguated
(rewritten to become unambiguous).
(iv) Every context-free grammar can be disambiguated.
(A) i only (B) i and iii only
(C)ii and iii only (D)All are true
Answer: B
Solution:

So, option B is False.

Q120. For every context-free grammar, there is a


(i) Language equivalent left-linear context-free grammar.
(ii) Language equivalent deterministic finite automaton.
(iii) Language equivalent push down automaton.
(iv) Language equivalent Turing machine.
(A) i and iii only (B) i, iii and iv only
(C)iii and iv only (D) all except i
Answer: C
Solution:

BASIC THEORY OF COMPUTATION Page 80


(i) False; it is true for Regular language.
(ii) False; it is true for Regular language
(iii) True: for every CFL there is push down automaton.
(iv) True: for every CFL there is an equivalent Turing machine.

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 SaSB|aSBB|aBB
Bb

BASIC THEORY OF COMPUTATION Page 81


When  appears and top of stack has z then move to the final state.
 In option ‘a’ it does not move to final state.
 In option c, SaB is not present in the PDA.
Answer: B
Q123. Consider the following grammar G: (Assume S is a starting symbol of G)
s aA | bBC | cC
Aa
B  bB | b
C cC | d
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) 𝛿 𝑞0 , 𝜆, 𝑧 = {(q1 , Sz)}, 𝛿 𝑞1 , 𝜆, 𝑆 = {(𝑞1 , aA), (𝑞1 , bBC), (𝑞1 , cC)},
𝛿 𝑞1 , 𝜆, 𝐴 = (𝑞1 , 𝑎) , 𝛿 𝑞1 , 𝜆, 𝐵 = 𝑞1 , 𝑏𝐵 , (𝑞1 , 𝑏) ,
𝛿 𝑞1 , 𝜆, 𝐶 = 𝑞1 , 𝑐𝐶 , (𝑞1 , 𝑐) , 𝛿 𝑞1 , 𝑎, 𝑎 = 𝑞1 , 𝜆 , ,
𝛿 𝑞1 , 𝑐, 𝑐 = 𝑞1 , 𝜆 , 𝛿 𝑞1 , 𝑑, 𝑑 = 𝑞1 , 𝜆 , , 𝛿 𝑞1 , 𝑏, 𝑏 = 𝑞1 , 𝜆 ,
(B) 𝛿 𝑞0 , 𝜆, 𝑧 = {(q1 , Sz)}, 𝛿 𝑞1 , 𝜆, 𝑆 = {(𝑞1 , aA), (𝑞1 , bBC), (𝑞1 , cC)},
𝛿 𝑞1 , 𝜆, 𝐴 = (𝑞1 , 𝑎) , 𝛿 𝑞1 , 𝜆, 𝐵 = 𝑞1 , 𝑏𝐵 , (𝑞1 , 𝑏) ,
𝛿 𝑞1 , 𝜆, 𝐶 = 𝑞1 , 𝑐𝐶 , (𝑞1 , 𝑑) , 𝛿 𝑞1 , 𝜆, 𝑧 = 𝑞𝑓 , 𝑧
(C) 𝛿 𝑞0 , 𝜆, 𝑧 = {(q1 , Sz)}, 𝛿 𝑞1 , 𝜆, 𝑆 = {(𝑞1 , aA), (𝑞1 , bBC), (𝑞1 , cC)},
𝛿 𝑞1 , 𝜆, 𝐴 = (𝑞1 , 𝑎) , 𝛿 𝑞1 , 𝜆, 𝐵 = 𝑞1 , 𝑏𝐵 , (𝑞1 , 𝑏) ,
𝛿 𝑞1 , 𝜆, 𝐶 = 𝑞1 , 𝑐𝐶 , (𝑞1 , 𝑑) , 𝛿 𝑞1 , 𝜆, 𝑧 = 𝑞𝑓 , 𝑧 ,
𝛿 𝑞1 , 𝑎, 𝑎 = 𝑞1 , 𝜆 , , 𝛿 𝑞1 , 𝑏, 𝑏 = 𝑞1 , 𝜆 , , 𝛿 𝑞1 , 𝑐, 𝑐 = 𝑞1 , 𝜆 ,
𝛿 𝑞1 , 𝑑, 𝑑 = 𝑞1 , 𝜆 ,
(D) none of the above
Answer: C
Solution:

BASIC THEORY OF COMPUTATION Page 82


BASIC THEORY OF COMPUTATION Page 83
PDA of grammar to string
Q124. 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 , 𝑏, 𝑏 = 𝑞1 , 𝜆 ,
𝛿 𝑞1 , 𝜆, 𝑧 = 𝑞𝑓 , 𝑧
Which of the following string is not accepted by M?
(A) aaaaa (B) b
(C) bbaa (D) bbb
Answer: b, c
Solution: The equivalent grammar G is:
S → 𝑎𝐴 | 𝑏𝐵, A → 𝑎𝐴 | 𝑎, B → 𝑏 | 𝑏𝐵,
L(G) = aa+ + bb+
So, „b‟ and „bbaa‟ are not generated by G.

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 , 𝜆, 𝑧 = 𝑞𝑓 , 𝑧

BASIC THEORY OF COMPUTATION Page 84


Q125. How many of the following string is/are accepted by M? _______
(i) aaabc (ii) aabbc (iii) aabc (iv) aac (v) aa
Answers: 2
Solution:
𝛿 𝑞1 , 𝑎, 𝑆 = 𝑞1 , 𝐴 , ⟹ 𝑆 ⟶ 𝑎𝐴
𝛿 𝑞1 , 𝑎, 𝐴 = 𝑞1 , 𝐴𝐵𝐶 , 𝑞1 , 𝜆 ⟹ 𝐴 ⟶ 𝑎𝐴𝐵𝐶 | 𝑎
𝛿 𝑞1 , 𝑏, 𝐵 = 𝑞1 , 𝜆 , ⟹𝐵 ⟶𝑏 ⟹ 𝑏
𝛿 𝑞1 , 𝑏, 𝐴 = 𝑞1 , 𝐵 , ⟹ 𝐴 ⟶ 𝑏𝐵 ⟹ 𝑏𝑏
𝛿 𝑞1 , 𝑐, 𝐶 = 𝑞1 , 𝜆 , ⟹𝐶 ⟶𝑐 ⟹ 𝑐

Grammar will be:


𝑆 ⟶ 𝑎𝐴 ⟹ 𝑎𝑛+2 𝑏𝑐 𝑛 𝑛 ≥ 0 ∪ 𝑎𝑛+1 𝑏𝑏 𝑏𝑐 𝑛 |𝑛 ≥ 0
𝐴 ⟶ 𝑎𝐴𝐵𝐶 | 𝑎 ⟹ 𝑎𝑛+1 𝑏𝑐 𝑛 𝑛 ≥ 0 ∪ 𝑎𝑛 𝑏𝑏 𝑏𝑐 𝑛 |𝑛 ≥ 0
𝐵 ⟶𝑏 ⟹ 𝑏
𝐴 ⟶ 𝑏𝐵 ⟹ 𝑏𝑏
𝐶 ⟶𝑐 ⟹ 𝑐
𝑛+2
L (M) = 𝑎 𝑏𝑐 𝑛 ≥ 0 ∪ 𝑎 𝑏𝑏 𝑏𝑐 𝑛 |𝑛 ≥ 0
𝑛 𝑛+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, Bb
(C) S  aA, A  aABC | bB | a, B  b, Cc
(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.

Q127. Which of the following language is equivalent to language generated by G?


(A) L = 𝑎𝑎∗ 𝑎 + 𝑏𝑏 𝑏𝑐 ∗
(B) L = 𝑎𝑎𝑘 𝑤 𝑏𝑐 𝑘 | 𝑘 ≥ 0 𝑎𝑛𝑑 𝑤 = {𝑎, 𝑏𝑏}
(C) L = 𝑎𝑘 𝑎𝑏𝑏 𝑏𝑐 𝑘 | 𝑘 ≥ 0
(D) None of these
Answer: B
Solution:
𝛿 𝑞1 , 𝑎, 𝑆 = 𝑞1 , 𝐴 , ⟹ 𝑆 ⟶ 𝑎𝐴
⟹ 𝑎𝑛+2 𝑏𝑐 𝑛
𝑛 ≥ 0 ∪ 𝑎𝑛+1 𝑏𝑏 𝑏𝑐 𝑛 |𝑛 ≥ 0
𝛿 𝑞1 , 𝑎, 𝐴 = 𝑞1 , 𝐴𝐵𝐶 , 𝑞1 , 𝜆 ⟹ 𝐴 ⟶ 𝑎𝐴𝐵𝐶 | 𝑎
⟹ 𝑎𝑛+1 𝑏𝑐 𝑛
𝑛 ≥ 0 ∪ 𝑎𝑛 𝑏𝑏 𝑏𝑐 𝑛 |𝑛 ≥ 0
𝛿 𝑞1 , 𝑏, 𝐵 = 𝑞1 , 𝜆 , ⟹𝐵 ⟶𝑏 ⟹ 𝑏
𝛿 𝑞1 , 𝑏, 𝐴 = 𝑞1 , 𝐵 , ⟹ 𝐴 ⟶ 𝑏𝐵 ⟹ 𝑏𝑏
𝛿 𝑞1 , 𝑐, 𝐶 = 𝑞1 , 𝜆 , ⟹𝐶 ⟶𝑐 ⟹ 𝑐
The language accepted by M is L = 𝑎𝑎𝑘 𝑤 𝑏𝑐 𝑘
| 𝑘 ≥ 0 𝑎𝑛𝑑 𝑤 = {𝑎, 𝑏𝑏} .
PDA to Grammar
Q128. Consider the following PDAM (Q, Σ, , 𝛿, z

Which of the following grammar is/are equivalent to given PDA?


(A) S  0S1 | λ (B) S  0S1 | 01
(C) S  0S1 | 0011 (D) None of the above
Answer: B
Solution:
(a) It is false because λ is generated by G but not accepted by M.
(b) It is correct because on each „0‟, we push „0‟ and then on each „1‟, if stack contains „0‟
then pop. At the end if input is finished and stack is empty then string will be
accepted.
So, the language accepted by M is 0𝑛 1𝑛 | 𝑛 > 0 .
Its equivalent grammar is S  0S1 | 01.

BASIC THEORY OF COMPUTATION Page 86


(c) It is false because 01 is not generated by grammar.
So, option B is correct.

(CNF and GNF)


Q129. Which of the following grammar doesn‟t have useless production?
(A) S  aAa| BC, A  aa |Aa, BcC | c
(B) S aAb | Bc | aA, A  BC, BbB |AC, C cC| c
(C)S ABb | aA, A  BC| c, BbB |AC, C cC| CC
(D) S aSb | λ | aA, A BC|λ, BbB |AC|b, C cC| λ
Solution:
(a) BcC is useless because it never terminals.
(b) ABc or BbB are useless productions
(c) BbB or CcC |CC are useless production a option is correct.
Answer: D
Q130. Consider following grammar G with productions
S aS | BA | CD, A a| Da, Baa|aC, CaCb| cC|CC
After removing all useless production from G, which of the following grammar is
equivalent to G?
(A) S aS | a | aa (B)S aS| aaa
(C) S aS|aA , A aa (D)b& c

Solution:
For non-terminals e $ D there is no useful production (i.e generating some string of terminals).
Only remaining useful production rule:-
SaS|BA
Baa
Aa
It can be written as:-
SaS|aaa (putting production rule of A &B).
or SaS|aA
Aaa
Both b& c are correct.
Answer: D

Q131. Consider following grammar G with productions


S Aa | C, A bA| B,B aB | C | b, C cC | c
After removing all unit-production from G, which of the following grammar is
Equivalent to G?
(A) S Aa | c, A bA | aB | cC | b | c, B aB | cC | b | c, C cC | c
(B)S Aa | cC | c, A bA | aB | cC | b | c, B aB | cC | b | c
(C)S Aa | cC | c, A bA | aB| b | c, B aB | cC | b | c, C cC | c
(D) S Aa | cC | c, A bA | aB | cC | b | c, B aB | cC | b | c, C cC | c

BASIC THEORY OF COMPUTATION Page 87


Solution:
Removing the unit production rule meaning :-
Remove the xy type of production rule where X and Y both are terminals.
SAa|cC|c
BaB|cC|c|b
AbA|aB|cC|c|b
CcC|c
So, the correct option is d)
Answer: D

Q132. Consider following grammar G with productions


S AaB | aaB,A  λ, B bbA| λ
After removing all λ-production from G, which of the following grammar is
equivalent to G?
(A)S aB | aaB,B  bb (B)S  a | aaB| aa,B  bb
(C)S aB | aaB| bb,B  bb| λ (D) S aB | aaB| a | aa,B  bb
Solution:
BbbA| putting A=
Bbb| Putting A= and B= (All possible combination)
SaB|aaB|aa|a
So, the correct answer is :-
SaB|aaB|aa|a
Bbb
Answer: D

Q133. Consider following grammar G with productions


S aA | aBB| AB, A aaA| λ, B bB| bbC, CB|λ
After removing all unit-production, all useless production and all λ-production from
G, which of the following grammar is equivalent to G?
(A) S aA | aBB| AB| a| bb, A aaA| aa, B bB| bbC| bb, CbB|bbC| bb
(B) S aA | aBB| AB| bB| bbC| a| bb, A aaA| aa, B bB| bbB| bb,
(C) S aA | aBB| AB| bB| bbC| a| bb, A aaA| aa, B bB|bb, CbB|bbC| bb
(D) S  aA | aBB| AB| bB| bbC| a| bb|aB, A aaA| aa, B bB| bbC| bb,
CbB| bbC|b
Solution: After removing all production:-
SaA|aBB|a|AB | B
AaaA|aa
BbB|bb|bbC
CB
After removing all unit production :-
SaA|aBB|a|bB|bb|bbC | AB
AaaA|aa
BbB|bb|bbC
CbB|bb|bbC

BASIC THEORY OF COMPUTATION Page 88


There is no useless production
So, None of the option is correct.
Answer: None
Or

BASIC THEORY OF COMPUTATION Page 89


Q134. Convert the following grammar into Chomsky normal form:
S ABa|bC, Aa|λ, Bb|C, Cc|λ
(A)S ABa| bC|Ba|Aa|a|b, Aa, Bb|c, Cc
(B) S  DA |BC|BA|AA|a|b, Aa, Bb, Cc, DBA
(C)S  AD |BC|D|AA|a|b, Aa, Bb, Cc, DAB
(D) S  DA |BC|BA|AA|a|b, Aa, Bb|c, Cc, DAB
Solution:
First remove the A production:-
SBa|Aa|b|bC|a|ABa
Aa|
Bb|c
Cc
Putting DAB
SDA|BA|AA|b|BC|a
Aa
Bb
Bc
Cc
DAB
Answer: D

Q135. Convert the following grammar G into Greibach normal form:


S  abc | aSb| aaSc | bSc
(A)S  aABC | aSB | AaSc | bSc, Aa, Bb, Cc,
(B)S  aBC | aSB | aASc | bSC, Aa, Bb, Cc
(C) S  aBC | aSB | aASC | bSC, Aa, Bb, Cc
(D)S  aABC| aSb | aASC | bSC, Aa, Bb, Cc
Solution:
For the grammar be in 4, the production rule is of type:-
SaV
(where V I set of non- terminals)
SaBC|aSB|aASC|bSC
Aa
Bb
Cc
Answer: C
Q136. Let G be a grammar in Chomsky Normal Form. Let w1,w2  L(G) such that
|w1| = |w2|. Which of the following is true?
(A) Any derivation of w1 has exactly the same number of steps as any derivation of w2.
(B) Some derivations of w1 may be shorter than some derivations of w2.
(C) Different derivations of w1 have different lengths.
(D) Some derivations of w1 maybe longer than some derivations of w2.
Answer:A

BASIC THEORY OF COMPUTATION Page 90


Solution: Since G is in CNF hence any derivation of w1 has exactly the same number of
steps as any derivation of w2.

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

For the next three questions, consider the following grammar:


G1 = ({S, T}, {a, b}, {S → aT, T → aT, T→ b}, S)
G2 = ({S, S1, S2}, {a, b}, {S → aS1, S1 → aS1, S1 → bS2, S2 →a}, S)
G3 = ({S, S1, A, B}, {a, b}, {S → AS1, S1 → AS1, S1 → bB, A → a, B → b}, S)
G4 = ({S, S1, S2, A, B}, {a, b}, {S → AS1|, S1 → AS1|BS2, A → a, B → b, S2→a}, S)

Q138. Which of the above grammars are regular grammars?


(A) G1 and G2 (B) G2 and G3
(C) G3 and G4 (D) G4 and G1
Answer: A
Solution:

Q139. Which of the above grammars is in Greibach Normal Form?


(A) G1 (B) G1 andG2
(C) G3 (D) G4
Solution:
By the definition of GNF.
GNF said that non- terminal → aV*
V= {set variable}
So grammer G1 = {S→aT , T→aT,T→b}

BASIC THEORY OF COMPUTATION Page 91


So it is in Greibach Normal form .
G2:- Also in Gribach Normal form.
Answer:B

Q140. Which of the above grammars is in Chomsky Normal Form?


(A)G1 (B) G2
(C) G3 (D) G4
Solution:
For Grammer to be in CNF:-
Non- terminal →two non- terminal
Non terminal →terminal
and null can produce by only starting symbol.
So grammar G4 is in Chomsky Normal Form.
Answer: 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

BASIC THEORY OF COMPUTATION Page 92


Q142. Consider a grammar G
S→abSb|bSaa|aa
Which of the following grammar are in GNF and equivalent to G?
(A)S→aBSb | bSAA | aA, A→a,B→b
(B)S→aBSb | bSAa | aA, A→a, B→b
(C)S→aBSB | bSAA | A, A→aa, B→b
(D) S→aBSB | bSAA | aA, A→a, B→b
Solution:
A→ a
B→ b
S→ aBSB
S→ bSAA
S→ aA
Answer: D

BASIC THEORY OF COMPUTATION Page 93


CYK Algorithm
For next four questions: Consider the following grammar G:
S  AB | BC
A  BA | a
B  CC | b
C  AB | a
We are applying CYK algorithm for the string „baaba‟ and given grammar G. The incomplete
triangular table is shown below:

For each of following questions select the correct one.


Common Solution:

BASIC THEORY OF COMPUTATION Page 94


Q143. The cell [2, 1] contains
(A) {B} (B) {A, B}
(C) ∅ (D) {S, A}
Answer: C
Q144. The cell [3, 1] contains
(A) {B} (B) {A, B}
(C) ∅ (D) {S, A}
Answer: C
Q145. The cell [3, 2] contains
(A) {B} (B) {A, B}
(C) ∅ (D) {S, A}
Answer: A
Q146. The cell [5, 3] contains
(A) {B} (B) {A, C}
(C) ∅ (D) {S, A}
Answer: B

BASIC THEORY OF COMPUTATION Page 95


Pumping lemma for CFL
Q147. Consider the CFG used in the proof of the pumping lemma: we chose a string long
enough so that it is accepted by the CFG and repeats a variable. What if such a string
does not exist for this CFG?
(A) There is no possibility of this happening: there always is such a string.
(B) The CFG‟s language must be finite.
(C) The CFG‟s language may or may not be infinite.
(D) Then there is at most 1 variable that produces a single terminal in the CFG.
Answer: B
Solution:
Since it is written in the question, “such string does not exist” means variable is not
repeating, hence language is finite.

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
wL with |w| >m can be decomposed as
w= uvxyz
with |vxy|≤m
and |vy| 1 i.e. vy 
such that uvi xyi zL 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:

Q151. Select the correct statements


(I) Since the pumping lemma applies to all context-free languages, all context-free
languages contain an infinite number of strings.
(II) The stack alphabet of pushdown automata must be the same as the input alphabet.
(III) The stack alphabet of pushdown automata must be different from the input alphabet.
(IV) If a language L satisfies the conditions stated in the pumping lemma for CFLs, then L
is context free.
(A) Only I&II (B) Only I & III
(C) Only III&IV (D)None of above
Answer:
Solution:

Decidability of CFL & CFG


Q152. Which of the following is/are decidable properties of context free?
(I) For context-free grammar G find if string w  G
(II) For context-free grammar G find if L (G) = 
(III) For context-free grammar G find if L (G) is infinite.
(A) Only I (B) Only I&II
(C) I, II & III (D) Only II & III
Answer: C
Solution:
I. Membership algorithm exists for CFG. So, it is decidable.
II. The context-free emptiness problem is decidable.
III. The context-free finiteness problem is decidable.

BASIC THEORY OF COMPUTATION Page 97


Q153. Which of the following language is/are Turing decidable?
1. L = {<G1, G2> | G1 & G2 are regular grammar and L(G1)  L(G2)}
2. L = {<G, R> | G is a CFG & R is a regular expression and L(G)  L(R)}
3. L = {<G, R> | G is a CFG & R is a regular expression and L(R)  L(G)}
(A) 1 only (B) 1 & 2 only
(C) 2 & 3 only (D) 1 & 3 only
Solution
(1) L(G1)  L(G2)
It is true for regular language. It is decidable.
(2) It is decidable.
(3) It is not decidable.
Answer: B

Q154. Which of the following language is/are NOT Turing decidable?


1. L = {<G1, G2> | G1 & G2 are CFG and L(G1)  L(G2) is empty}
2. L = {<G1, G2> | G1 & G2 are CFG and L(G1)  L(G2) is CFL}
3. L = {<G1, G2> | G1 & G2 are CFG and L(G1)  L(G2) is regular}
4. L = {<G1, G2> | G1 & G2 are DCFG and L(G1)  L(G2) is empty}
(A) 1 & 2 only
(B) 1, 2 & 3 only
(C) 1, 2 & 4 only
(D) All the above

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

Q155. Which of the following language is/are not decidable?


1. L = {<G> | G is a CFG and λ L(G)}
2. L = {<G, w> | G is a CFG and w L(G)}
3. L = {<G> | G is a CFG and G is unambiguous}

BASIC THEORY OF COMPUTATION Page 98


4. L = {<G> | G is a CFG and L(G) ∑*}
(A) 1 & 2 only
(B) 3 & 4 only
(C) 3 only
(D) 4 only
Solution:
Membership is decidable for context free grammars.
So L(G) and wL(G) are decidable.
CFG is unambiguous is undecidable problem
To check whether L(G) * , we need to check every string and there are infinite string hence
undecidable.
So, only option 3&4 are undecidable.
Answer: B
Q156. [MSQ]
Which of the following languages are undecidable?
(A) L = {<G, > | L (G) = *; where G is a CFG and  is finite set of alphabets}
(B) L = {<G, R> | L (G) = R; where G is CFG and R is regular language}
(C) L = {<G1, G2> | L (G1) = L (G2); where G1 and G2 are two CFG‟s}
(D) L = {<G1, G2> | L (G1)  L (G2); where G1 and G2 are two CFG‟s}
Answer: a, b, c, d
Solution: All are undecidable

BASIC THEORY OF COMPUTATION Page 99


TURING MACHINE
Q1. The language accepted by the following Turing machine is:

(A)a* (B)a*ba*
(C)ba* (D)aba*
Answer: D
Solution:

Q2. Given a Turing Machine M, what‟s L (M)?

(A) 0*10 (B) 0*10(0+1)*


(C) (0+1)* (D) 
Answer: B
Solution:
L (M) = 0*10(0+1)*

Q3. Given a Turing Machine M, what‟s L (M)?

(A) (b +ab)*aa (B) b*aa(a+b)*


(C) b*(ab)*aa(a+b)* (D) (b+ab)*aa(a+b)*
Answer: D
Solution:

BASIC THEORY OF COMPUTATION Page 100


Q4. Given a Turing Machine M, what‟s L (M)?

(A)L(M) = (a+b)*aa(a+b)* (B)L(M) = (a+b)*aa


(C)L(M) = b*ab*a(a+b)* (D)L(M) = b*a(a+b)*a
Answer: A
Solution: By TM we can say that it accepts all the string over {a, b} which has „aa‟ as
substring. So, the language L(M) = (a+b)*aa(a+b)*.

Q5. Consider the following Turing Machine:


M =({q0,q1,q2,qacc,qrej},{a,b},{a,b,B} ,𝛿,q0,qacc,qrej),where
𝛿 (q0, a) = (q1, b, R)
𝛿 (q1, b) = (q2 , a, L)
𝛿 (q2, b)= (q0, b, R)
𝛿 (q1, B)= (qacc, B,R)
As always, we assume for cases not mentioned above 𝛿 (q , a)=(qrej , B , R) What can we
say about the Turing machine M?
(A) M halts on all inputs (B) M never halts on some inputs
(C) M does not halt on any input (D) None of these
Answer: A
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

BASIC THEORY OF COMPUTATION Page 101


(A) a*b (B) aa*b
(C) ∅ (D) a*b(a+b)*
Answer: A
Solution:

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

BASIC THEORY OF COMPUTATION Page 102


Q9. The language accepted by the following Turing machine is
M1 = ({q0, qaccept, qreject}, {0, 1}, {0, 1,}, δ, q0, qaccept, qreject)
δ(q0, 0) = (qaccept, 0, R)
δ(q0, 1) = (qreject, 1, R)
δ(q0,) = (qreject, 1, R).
(A) 0+ 1* (B)0* 1*
(C) (0+1)*(D) 0 (0*1*)*
Answer: D

BASIC THEORY OF COMPUTATION Page 103


Q10. 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).
Which of the following strings are accepted by M?
i) 0011 ii)0101
iii)01 iv)10100
v) 1010
(A) i and iii (B) iii and v
(C) i, ii and iv (D) ii and iii
Answer: A
Solution:

BASIC THEORY OF COMPUTATION Page 104


Q11. The following Turing machine
M2 = ({q0, q1, qaccept, qreject}, {0, 1}, {0, 1, #,}, δ, q0, qaccept, qreject)
δ(q0, 0) = (qaccept, 0, R)
δ(q0, 1) = (q1, 1, R)
δ(q0, #) = (qreject, 1, R)
δ(q0,) = (qreject, 1, R).
δ(q1, 0) = (q1, #, R)
δ(q1, 1) = (q1, #, R)
δ(q1, #) = (q1, #, R)
δ(q1,) = (q1, #, R)
(A) halts on all the string starts with 0
(B) does not halts on 
(C) halts on all the string starts with 1
(D) does not halts on any string.
Answer: A
Solution:

Data for next two questions: Consider the following TM

Q12. The outcome of the computation of M on input „00’is


(A) ACCEPT (B) REJECT
(C) LOOP (D) None
BASIC THEORY OF COMPUTATION Page 105
Q13. The outcome of the computation of M on input „01’is
(A)ACCEPT (B) REJECT
(C) LOOP (D) None
Answer: B
Solution:

BASIC THEORY OF COMPUTATION Page 106


For Next Three Questions: Consider the Turing machine:

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

BASIC THEORY OF COMPUTATION Page 107


Answer: A
Solution: The given TM accepts L = {𝑎𝑛 𝑏𝑛 | 𝑛 ≥ 1}. So, TM halts at final state.
Q16. Is there any input for which the Turing machine goes into an infinite loop?
(A) No.
(B) Yes, there is an input “abb” for which the Turing machine goes into an infinite loop.
(C) Yes, there is an input “aaaaaabbbbbbbbbb” for which the Turing machine goes into an
infinite loop.
(D) None of the above.

Q17. What is the smallest number of states that a TM could have?


(A) 0 (B) 1
(C) 2 (D) 3
Answer: C

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.

BASIC THEORY OF COMPUTATION Page 108


(D) Exactly the recognizable languages

Q21. What language is accepted by the Turing machine whose transition graph is shown
below?

(A) The language of the machine is therefore ab*b


(B) The language of the machine is therefore bb*a(a+b)*
(C) The language of the machine is therefore ab* + bb*a(a+b)*
(D) The language of the machine is therefore ab*b + bb*a(a+b)*

BASIC THEORY OF COMPUTATION Page 109


BASIC THEORY OF COMPUTATION Page 110
Q22. [MSQ]
The language accepted by the following Turing machine is

(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}

BASIC THEORY OF COMPUTATION Page 111


BASIC THEORY OF COMPUTATION Page 112
Q23. [MSQ]
Which language does the following TM accept?

(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}

BASIC THEORY OF COMPUTATION Page 113


Q24. Construct following Turing machine with input alphabet {a, b},

The language accepted by given Turing machine is


(A)L = {aibj | i ≥ 0, j= i} (B) L = {aibj | i ≥ 0, j < i}
(C) L = {aibj | i ≥ 0, j ≤ i} (D) L = {aibj | i ≥ 0, j ≥ i}

Q25. The following language


L1 = {<M>|M is a TM and there exists an input on which M halts in less than |<M>|
steps} is:
(A) recursive
(B) recursively enumerable but not recursive
(C) not recursively enumerable
(D) Regular
Q26. The language L2 = {<M>|M is a TM and |L(M)| ≤ 3} is:
(A) recursive
(B) recursively numerable but not recursive
(C) not recursively enumerable
(D) none of the above

Q27. The following language


L2 = {<M>|M is a TM and |L(M)| ≥ 3} is:
(A) Recursive
(B) recursively enumerable but not recursive
(C) not recursively enumerable
(D) none of the above

BASIC THEORY OF COMPUTATION Page 114


Q28. The following language
L4 = {<M>|M is a TM that accepts all even numbers}is:
(A) recursive
(B) recursively enumerable but not recursive
(C) not recursively enumerable
(D) none of these
Answer: C
Solution: For any TM, there doesn‟t exist any algorithm to check all even numbers.
Because we have to check all even numbers (which is infinite). So, it is not RE.
Q29. The following language
L1 = {<M>|M is a TM and L(M) is finite}is:
(A) recursive
(B) recursively enumerable but not recursive
(C) not recursively enumerable
(D) context-Sensitive but not CFL
Q30. The following language
L1 = {<M>| there exist x, y ∈ Σ*such that either x ∈L(M) or y ∉ L(M)}.
(A) recursive
(B) recursively enumerable but not recursive
(C) not recursively enumerable
(D) context-Sensitive but not CFL

Q31. The following language


L1 = {<M, x, k>|M is a TM, and M does not halt on x within k steps}is:
(A) Recursive
(B) Recursively enumerable but not recursive
(C) Not recursively enumerable
(D) Not recursive
Q32. The following language
L1 = {<M>|M is a TM, and M accepts (at least) two strings of different lengths} is:
(A) Recursive
(B) Recursively enumerable but not recursive
(C) Not recursively enumerable
(D) Not recursive
Q33. Let the language 𝐴 𝑇𝑀 ={<M,w> | M is a TM that accepts string w} then the complement of
the language is
(A) Decidable (B) Turing Recognizable
(C) Not Turing Recognizable (D) None
Data for next ten questions: Consider the following languages (Q34 to 43 - 2020)
L1 = {<M> | M is a TM and M accepts at most 225 distinct inputs}

BASIC THEORY OF COMPUTATION Page 115


L2 = {<M> | M is a TM and M accepts at least 225 distinct inputs}
L3 = {<M> | M is a TM and M accepts exactly 225 distinct inputs}
L4 = {<M, w> | M is a TM and M doesn‟t halt on „w‟}.
L5 = {<M, w> | M is a TM and M halts on „w‟}
L6 = {<M, w> | M is a TM and M accepts „w‟}
L7 = {<M, w> | M is a TM and M rejects „w‟}
L8= {<M> | M is a TM and M has exactly five states}
L9 = {<M> | M is a TM and M has exactly three tapes}
L10 = {<M> | M is a TM and L(M) = {001, 100}}
Q34. Then L1 is
(A) Recursive (B) RE (C) Not RE (D) finite

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

BASIC THEORY OF COMPUTATION Page 116


(C) Not Turing Recognizable (D) None
Q46. [MSQ]
The language ECFG = {<G> | G is a CFG and L (G) = ∅} is
(A) Decidable (B) Turing Recognizable
(C) Not Turing Recognizable (D) None

Q47. EQTM = {<M1, M2> | M1, M2 are TMs with L(M1) = L(M2)}?
(A) Decidable (B) Turing Recognizable
(C) Not Turing Recognizable (D) None

Q48. EQDFA={<M1,M2> | M1,M2 are DFAs with L(M1)=L(M2)}?


(A) Decidable (B) Turing Recognizable
(C) Not Turing Recognizable (D) None
Q49. Consider the following language
L = {<M> : M is TM such that L(M) = ∅}.
(A) Turing recognizable
(B) Turing decidable
(C) Not Turing recognizable
(D) CO-RE
Q50. Which of the following statements is true for every language L ⊆ {0, 1}*?
1. L is non-empty.
2. L is decidable or L is infinite (or both).
3. L is accepted by some DFA with 42 states if and only if L is accepted by some NFA
with 42 states.
4. L is decidable if and only if its complement L is undecidable.
(A) 1 and 4 Only
(B) 2 and 3 Only
(C) 2 Only
(D) 1, 2, 3 Only
Data for next two questions: Let M be a standard Turing machine (with a single one-track tape
and a single head) that decides the regular language 0*1*.
Q51. Which of the following must be true?
1. Given an empty initial tape, M eventually halts.
2. M accepts the string 1111.
3. M rejects the string 0110.
4. M moves its head to the right at least once, given input 1100.
(A) 2 & 3only
(B) 1& 4 only
(C) 2,3& 4 only
(D) All are true
Q52. Which of the following is /are not always true?

BASIC THEORY OF COMPUTATION Page 117


1. M moves its head to the right at least once, given input 0101.
2. M never accepts before reading a blank.
3. For some input string, M moves its head to the left at least once.
4. For some input string, M changes at least one symbol on the tape.
(A) 2, 3 & 4
(B) 3 & 4
(C) 1 & 2
(D) All
Q53. Which of the following problems about Turing machines is/are undecidable?
1. To determine, given a Turing machine M, a state q, and a string w, whether M ever
reaches state q when started with input w from its initial state.
2. To determine, given a Turing machine M and a string w, whether M ever moves its
head to the left when started with input w.
3. To determine, given Turing machine M and a string w, whether w is accepted by M
within some given time constraint T.
4. To determine, given a Turing machine M, and a string w, whether M ever halt for
input w.
(A) 1 & 2 only (B) 2 and 4 only
(C) 1, 2 & 4 only (D) all are undecidable
Q54. Which of the following problems about context-free grammars are undecidable?
1. Given a context-free grammar G, is ε ∈L (G)?
2. Given a context-free grammar G, is {ε} = L (G)?
3. Given two context-free grammars G1 and G2, is L (G1) ⊆ L (G2).
(A) 1only (B) 2 only
(C) 3 only (D) 1, 2 and 3
Data for next two questions: Let G1 and G2 are CFGs and R denotes given regular expression.
Q55. Which of the following problems are undecidable?
1. L (G1) ∩ L (G2) ≠∅
2. L (G1) ≠ L (G2)
3. L (G1) ≠ L (R)
(A) 1only (B) 2 only
(C) 1, 3 only (D) 1, 2 and 3
Q56. Which of the following problems is/are decidable?
1. L (G2) – L (G1) ≠∅?
2. L (R) – L (G1) ≠∅
3. L (R) = finite
4. L (G1 U G2) = Σ*
(A) 1 & 2 only (B) 3 & 4 only
(C) 1, 3 only (D) 3 only

BASIC THEORY OF COMPUTATION Page 118


Q57. How many of the following languages are Un-decidable? ________
1. L = {<M> | M is a TM and M accepts at least one string over {0, 1}}.
2. L = {<M> | M is a TM and M accept all strings over {0, 1}}.
3. L = {<M> | M is a TM and M accepts “Hello”}.
4. L = {<M1, M2> | M1 and M2 are TM‟s and M1 accept more strings than M2}.
5. L = {<M> | M is a TM and M take more than 1000 steps to process input w}.
6. L = {<M1, M2> | M1 and M2 are TM‟s and M1 take more steps than M2 to process input
w}
Q58. 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.

Q59. Which of the following statement is/are true?


i. There is a language that is decidable and its complement is not decidable.
ii. There is a language that is recognizable and its complement is not recognizable.
iii. The problem of determining whether a TM accepts at least 7 strings is un decidable. iv.
The problem of determining whether a TM has at least 7 states is un decidable.
(A) i and iv only
(B) ii and iii only
(C) i, ii and iii only
(D) iii and iv only
Q60. 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.
(D) Exactly the recognizable languages
Q61. Select all the statements that are TRUE. The class of recursively enumerable languages :
1. Not closed under union
2. Closed under intersection
3. Closed under complement
4. Not closed under Kleen's star
5. Not closed under infinite union
(A) 1, 2 and 4 only (B) 3 and 5 only
(C) 2 and 5 only (D) 1and 4 only
Q62. Which of the following statement/s is/are true?

BASIC THEORY OF COMPUTATION Page 119


1. If A is regular and B is regular, then A U Bc is always Recursive.
2. If A is context-free and B is regular, then A U Bc is always Recursively enumerable
3. If A is regular and B is context-free, then A Bc is regular.
4. If A is recursive and B is recursive, then A Bc is always Recursively enumerable but
not recursive.
(A) 1 only (B) 1 & 2 only
(C) 1, 2 & 4 only (D) All the above

Q63. Which of the following statement/s is/are false?


1. If A is recursive and B is Recursively enumerable (RE), then A U Bc is Recursively
enumerable.
2. If A is recursively enumerable and B is recursive then A U Bc is Recursive.
3. If A is regular language and B is non-regular language then A  Bc is always regular.
4. If A is RE and their complement is also RE then A is always Turing decidable.
(A) 1 & 2 only (B) 1, 2 & 3 only
(C) 4 only (D) All the above

Q64. Which of the following statements about formal languages is false?


(A) Every recursive language is recursively enumerable.
(B) The complement of a recursive language is recursive.
(C) The complement of a recursively enumerable language is recursively enumerable.
(D) The union of two recursively enumerable languages is recursively enumerable

BASIC THEORY OF COMPUTATION Page 120


Q65. Which of the following is/are not decidable?
1.ACFG = {<G, w> : G is a CFG that generates string w}
2.ECFG = {<G> : G is a CFG and L(G) = }
3. DCFG= {<G> : G is a CFG and G is ambiguous}
4.UCFG={<G>: L(G) ≠* }
(A) 3 and 4 only
(B) 1 and 3only
(C)1, 2 and 4 only

BASIC THEORY OF COMPUTATION Page 121


(D) 2, 3 and 4 only

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

BASIC THEORY OF COMPUTATION Page 123


there is a single-tape deterministic Turing machine that also recognizes A.
(A) I, IV and V only (B) I and V only
(C) All except II (D) All the above
For next five questions: Let L1 and L2 be languages in the respective language class, and let R
be a regular language, and x be a given word over alphabet. Some problems are given in the
questions identify the classes of languages for which the problem is decidable
Q71. L1 U L2 = * is decidable for
i) regular languages ii) context-free languages
iii) recursive languages iv) recursively enumerable languages
(A)Only i &ii (B)Only i
(C)Only ii&iv (D)Only iii &iv

Q72. x  L1is decidable for


i) regular languages ii) context-free languages
iii) recursive languages iv) recursively enumerable languages
(A)Only ii&iii (B)Only i,ii&iii
(C)Only iii&iv (D)Only I & iv

BASIC THEORY OF COMPUTATION Page 124


Q73. R  L1 is decidable for
i) regular languages ii) context-free languages
iii) recursive languages iv) recursively enumerable languages
(A)Only ii&iii (B)Only I

BASIC THEORY OF COMPUTATION Page 125


(C)Only ii&iv (D)Only iii&iv

Q74. L1 − R = ∅is decidable for


i) regular languages ii) context-free languages
iii) recursive languages iv) recursively enumerable languages
(A)Only ii (B)Only i & ii
(C)Only iii &iv (D)Only ii &iii

BASIC THEORY OF COMPUTATION Page 126


Q75. y  L1, |y| <5 is decidable for
i)regular languages ii) context-free languages
iii) recursive languages iv) recursively enumerable languages
(A) Only iii & iv (B) Only ii & iii
(C) Only i, ii & iii (D) Only i & iv

BASIC THEORY OF COMPUTATION Page 127


BASIC THEORY OF COMPUTATION Page 128
Q76. Which of following is/are correct?
S1: Deterministic two-stack automata are as powerful as Turing machines.
S2: {⟨M⟩ | M is a Turing machine and M does not accept 101} is recursively enumerable
(A)Only S1 (B)Only S2
(C)Both S1&S2 (D)None of them

Q77. Which of the following problem is undecidable?


(A) membership problem for CFL
(B) membership problem for regular sets
(C) membership problem for CSL
(D)membership problem for type 0 languages

BASIC THEORY OF COMPUTATION Page 129


Q78. Which of the following is/are true about uncountable set?
(i) If A is a subset of B and A is uncountable, then so is B.
(ii) If A is infinite (even countably infinite) then the power set of A is uncountable
(iii) If A is uncountable and B is any set, then the union A U B is also uncountable.
(iv) If A is uncountable and B is any set, then the Cartesian product A x B is also
uncountable.
(A) i, ii only (B) iii, iv only
(C)ii, iii, iv only (D)All the above
Q79. Which of the following statement is/are True?
1. The language (0 ∪ 1)* is countable.
2. The set of all possible language over {a, b} is countable.
3. The set of recursively enumerable languages is countable.
4. The Cartesian product of a finite number of countable set is countable.
(A) 1 & 4 only (B) 2 & 3 only
(C) 1, 3 & 4 only (D) All the above
Q80. Which of the following statement is/are NOT true?
1. Set of all prime numbers is countable.
2. Set of rational numbers is uncountable.
3. Set of Binary Sequences is uncountable.
4. Set of real Numbers is uncountable.
5. Set of all integers is countable.
(A) 1 & 2 only (B) 3, 4 & 5 only
(C) 2 only (D) 1, 2 & 3 only

Q81. Which of the following statement is/are true?

BASIC THEORY OF COMPUTATION Page 130


1. The set of all pairs, (i, j) with i, j positive integers, is countable.
2. The set of all triplets, (i, j, k) with i, j, k positive integers, is countable.
(A) 1 only (B) 2 only
(C) Both 1 & 2 (D) Neither 1 nor 2
Q82. If S1 and S2 are countable set, then how many of the following statement is/are true?
1. S1  S2 is countable. 2. S1  S2 is countable.
3. S1  S2 is countable. 4. S1 - S2 is countable.
Q83. Which of the following statement is/are true?
1. Subset of infinite countable set is countable.
2. Superset of countable set may be uncountable.
3. There exists a countably infinite set which is subset of an uncountable set.
4. Power set of countably infinite set is always countable.
(A) 1 & 2 only (B) 3 & 4 only
(C) 1, 2 & 3 only (D) All the above

Marks :50 Theory of Computation Test-1 Time:40


Q1. Consider the following NFA N over ΣN = {a, b, c}:

Which of the following words are accepted by N?


i.  ii. aaa iii. bbb iv.aac
v. abc vi. abbab vii. Abbbacc
(A) i, iii, iv and vi (B)Only ii, iv and vi
(C) Only iii and vi (D) i, ii, iii, iv and vi

BASIC THEORY OF COMPUTATION Page 131


Q2. Which of the following strings is a member of the language described by the regular expression
(a*ba*ba*ba*)* ?
(A)bbbb (B) bbaaabb
(C) bbaaabbbabb (D) bbabbbab

BASIC THEORY OF COMPUTATION Page 132


Q3. Which of the following strings is a member of the language over {a, b} defined by the regular
expression (aa + ba)*(bb)* ?
(A)aabbba (B) aaaabb
(C) babbaa (D) bbaa

BASIC THEORY OF COMPUTATION Page 133


Q4. Which language generates the grammar G given by the productions?
S → aSa | aBa
B → bB | b
(A) L(G) = {anbman | n >0, m >0}.
(B) L(G) = {anbnan | n >0, m >0}.
(C) L(G) = {anbmam | n >0, m >0}.
(D) L(G) = {ambman | n >0, m >0}.

Q5. Consider the following grammar.


S  SS S 0 S
The regular expression for the language that is accepted by this grammar is
(A)(00)* (B) 00* (C) 0* (D) 0*0

BASIC THEORY OF COMPUTATION Page 134


Q6. Consider the following finite automaton over the alphabet {0, 1}. A is the starting state but so far
there are no accepting states.

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? __________

BASIC THEORY OF COMPUTATION Page 135


Q7. How many of these statements is/are correct? ________
i. abc  {a, b, c}+ ii. abc  {a, b, c}* iii. abc  {a, b, c}1iv. abc  {a, b, c}2
v. abc  {a, b, c}3
vi. abc  {a, b, c}4 vii. abc  {a, b, c}0viii. ∅ {a, b, c}* ix.
∅ {a, b, c}0 x.  {a, b, c}* xi.  {a, b, c}0

BASIC THEORY OF COMPUTATION Page 136


Q8. \What is the minimum number of states in the DFA for the following language ( ={a,b}) ?
________L= {w| w * w has exactly two a’s and at least two b’s}

Q9. Which of the following regular expression generates the language recognized by the following
FSM?

BASIC THEORY OF COMPUTATION Page 137


(a) (a+b)* (b) (ab)* + (ba)*
(c) ((ab)+ + (ba)+)+ (d) (ab+ba)*

BASIC THEORY OF COMPUTATION Page 138


Q10. Consider the following FSM M:

Which of the following language is accepted by M?


(a) All strings in {a, b}* that contains at least one occurrence of string ba.
(b) All strings in {a, b}* that contain no occurrence of string bab.
(c) All strings in {a, b}* that ends with ba.
(d) All strings in {a, b}* that contain at least one b.

BASIC THEORY OF COMPUTATION Page 139


Q11. Consider the following NFA {Q,, δ, q0, F}:
Q = {q0, q1, q2, q3}
 = {a, b, c}
δ(q0, a) = {q1, q2}
δ(q1, a) = {q0, q1}
δ(q2, b) = {q3}
δ(q3, c) = {q3}
In all other cases, the value of δ is the empty set.
• q0 is the initial state.
• F = {q3}.
What is the language accepted by this automaton?
(A) a*bc*
+
(B) a bc*
(C) a(aa+)*bc*
(D) None are correct option

BASIC THEORY OF COMPUTATION Page 140


Q12. Which strings are accepted by the automaton?

(A) bacababb (B) abacaba


(C) cabacaba (D) abacababa

BASIC THEORY OF COMPUTATION Page 141


BASIC THEORY OF COMPUTATION Page 142
BASIC THEORY OF COMPUTATION Page 143
BASIC THEORY OF COMPUTATION Page 144
Q13. Consider the deterministic automaton recognizing the set of strings in {0, 1} containing at least
three occurrences of three consecutive 1’s, overlapping permitted. How many states would it
have?__________

BASIC THEORY OF COMPUTATION Page 145


Q14. Which of the following regular expressions describes the language consisting of strings of arbitrary
length from the alphabet a, b, c where ‘a’ and ‘b’ can occur at any position, but ‘c’ can only occur
immediately after ‘b’?
(A) abc*
(B) (a+b+bc)*
(C) aa+bb+ab+ba+bc+ca+cb
(D) a* +b* +c*

Q15. Which is the most restrictive class to which the following grammar belongs?
S → xB

BASIC THEORY OF COMPUTATION Page 146


xB → xCy
xCy → xyz
C → CwC
C→
(A) context free (B) context sensitive
(C) unrestricted (D) regular

BASIC THEORY OF COMPUTATION Page 147


BASIC THEORY OF COMPUTATION Page 148
Q16. Which of the following regular expressions describes the language consisting of strings of arbitrary
length from the alphabet a, b, c where ‘a’ and ‘b’ can occur at any position, but ‘c’ can only occur
immediately after ‘b’?
(A) abc* (B) (a+b+bc)*
(C) aa+bb+ab+ba+bc+ca+cb (D) a* +b* +c*

Q17. Which is the most restrictive class to which the following grammar belongs?
S → xB
xB → xCy
xCy → xyz
C → CwC
C→

BASIC THEORY OF COMPUTATION Page 149


(A) context free (B) context sensitive
(C) unrestricted (D) regular

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:

Q19. Match the following regular expression with their description


(i) 0+(0+1)1+ 1. any string that has exactly three 1’s.
(ii) 0*10*10*10* 2. any string of length 3 or greater that is one or more 0’s are
followed by one or more 1’s.
(iii) 0*(100*)*1* 3. any string that has no substring 00 after first 11
(iv) (0+ 10)*1(1+10)* 4. any string that has no substring 110
(A) i-2, ii-1, iii-3, iv-4 (B) i-2, ii-1, iii-4, iv-3
(C) i-1, ii-2, iii-4, iv-3 (D) None

BASIC THEORY OF COMPUTATION Page 150


Q20. Let r, s, t be regular expression. which of the following identities is correct?
(A) (r+s)* = r*s* (B) (r*s)* = (rs)*
(C) (r+s)* = r*+s* (D) (rs+r)*r = r(sr+r)*

Q21. Which of the following statements is FALSE?


(A) The intersection of a context free language with a regular language is context free.
(B) The intersection of two regular languages is regular.
(C) The intersection of two context free languages is context free
(D) The intersection of a regular language and the complement of a regular language is regular.

BASIC THEORY OF COMPUTATION Page 151


Q22. Consider the following two regular expressions R1 and R2.
R1 = (a+b)*a(a+b)* R2= a*b*aa*b*
Which of the following relation is correct?
(A) R1 = R2 (B) R1 ⊆ R2
(C) R1 ⊇ R2 (D) None of these

Q23. Which of the following languages are regular


i) Set of all strings of form { 0k1l k + l = 8} over alphabet Σ = {0, 1}.
ii) Set of all strings of form { 0k1l k − l = 8} over alphabet Σ = {0, 1}.
(A) Only I (B) Only ii
(C) Both i & ii (D) Neither i nor ii

BASIC THEORY OF COMPUTATION Page 152


Q24. Consider the following two regular expressions R1 and R2.
R1= (a+ab+bb)(a+b)* R2= abb*
Which of the following relation is correct?
(A) R1 = R2 (B) R1 ⊆ R2
(C) R1 ⊇ R2 (D) None of these

BASIC THEORY OF COMPUTATION Page 153


Q25. Which of the following grammars is a regular grammar with the same language as the regular
expression a* + b* +ab ?
(A)S -> AB A -> aA /  B -> bB / 
(B)S -> ab / A / B A -> Aa | a B -> Bb / b
(C) S -> A / B A -> aA / b B -> Bb / a
(D)S -> ab / A / B A -> aA |  B -> bB / 

BASIC THEORY OF COMPUTATION Page 154


Marks :50 Theory of Computation Test-2 Time:40
Q1. Consider the following context –free grammar, with start symbol S and terminals {a ; <>}.
S→<L L→ aR | <LR R →> | ; L
How many different parse trees are there for sting <<a ; a>?
(A) 0 (B) 1
(C)2 (D) More than two

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

BASIC THEORY OF COMPUTATION Page 155


(D) L is not a context-sensitive language

Q5. Consider the following three languages:


• L1 = {anbmcdmen| n,m ≥ 0}
• L2 = {(ab)ncdm| n,m ≥ 0}
• L3 = {anb(cd)nen| n ≥ 0}
One of the languages is regular, one context-free and not regular and one not context-free. Which
are the regular and the non-regular context-free languages respectively?
(A) L2 ,L1 (B) L1,L2
(C) L3, L1 (D) L2,L3

Q6. Consider the following languages over the alphabet {0,1)


L1 = {x.xR |x𝜖 {0,1}*} L2 = {x.x |x𝜖 {0,1}*}
R R
where x is the reverse of sting x; e.g. 011 = 110.Which of the following is true?
(A) Both L1 and L2 are regular.
(B) Ll is context-free but not regular where as L2 is regular.
(C) Both L1 and L2 are context free and neither is regular.
(D) Ll is context free but L2 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

Q8. Which of the following languages is/are regular?__________


𝑛
(i) {an(bc)m : n ≥ 0 ,m>n} (ii) {𝑎2 : n ≥ 0}
(iii) {ananan : n ≥ 0} (iv) { 0mk1nk | 0 ≤ k ≤ 5, m, n, k  N }
Q9. Let ai denote a sequence a. a …. a with i letters and let N be the set of natural numbers {1.2… } Let
2
L1 ={ai b2i| i∈ 𝑁}and L2={ai bi | i∈ 𝑁 } be two languages. Which of the following is correct?
(a) Both L1 and L2 are context free languages.
(b) L1 is context-free and L2 is recursive but not context-free.
(c) Both L1 and L2 are recursive but not context-free.
(d) L1 is regular and L2 is context-free.

Q10. Suppose we apply minimization to the following DFA over {a, b}:

BASIC THEORY OF COMPUTATION Page 156


Which of the following correctly describes the resulting DFA M?
(A) M has just a single state. (B) M has 2 states, 1 of which is accepting.
(C) M has 3 states, 1 of which is accepting. (D) M has 3 states, 2 of which are accepting.

Q11. Which of the following is/are true?__________


1. If L is a regular language, then L1= {wwr | w  L} must be a regular language.
2. For every pair of regular expressions and R and S, the languages denoted by R(SR)* and (RS)*R
are the same.
3. If L1 and L2 are languages such that L1, L1L2, and L2L1 are all regular, then L2 must be
regular

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}

BASIC THEORY OF COMPUTATION Page 157


(B) All palindromes over 0’s and 1’s
(C) All the strings with equal number of 0’s and 1’s
(D) All the strings with more 0’s then 1’s

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? ________

Q18. Which of the following two languages is/are context-free?


L = {aibjckdl | i = k or j = 2l}
m
M = {aibjcmdk | i = k and j = 22 }
(A) Only L
(B) Only M
(C) Both L and M
(D) neither M nor L
Q19. Which of the following is FALSE?
(A) CFLs are closed under union but not closed under complement.
(B) Regular sets are closed under intersection and Kleene Closure.
(C) Recursive languages are closed under intersection but not closed under complement.
(D) Recursively enumerable languages are closed under union and intersection
Q20. Consider the following NFA

Grammar equivalent to following NFA is:


(A) a+(b*ab)* (B) a(b*ab)*
(C) a(b*a*b*)*ab (D) None

Q21. Given two not regular languages over ={a,b}:


L1 = { w | the number of a’s in w is equal to the number of b’s}
L2 = { w | the number of a’s in w is not equal to the number of b’s}
(I) The language L = L1  L2 is regular
(II) The language L = L1  L2 is regular
(A) I is true (B) II is true
(C) I and II both are true (D) none

Q22. Let L be a regular defining following operation on L


1. Even (L) is the set of all strings x in L such that |x| is even.
2. Triple (L) = {x | x=uvw, such that u, v, w are in L, and |u| = |v| = |w|}.
3. PREFIX (L) to be the set of prefixes over L

BASIC THEORY OF COMPUTATION Page 158


Regular languages are closed under which of the following operations?
(A) 1 and 3 (B) 2 and 3
(C) 1 and 2 (D) 1, 2 and 3

Q23. Which of the following statement is TRUE?


(A) {ai bi+j cj | i, j >= 0} is regular
(B) If L1 is non regular and (L2  L1), then L2 must be regular
(C) {(an b)n | n >= 1} is context free
(D) {(an b)m | m, n >= 1} is context free

Q24. Which of following Statement is INCORRECT about Regular Languages:


(A) If L over 1 is regular, then L over any  containing 1 is regular
(B) For any natural number n, {ai bk ci | 0  i  n} is non regular
(C) If L1 over 1 and L2 over 2 are regular then L1  L2 is regular
(D) If the lengths of strings in L are multiples of 3, then L is regular

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

BASIC THEORY OF COMPUTATION Page 159


List of theorems:
1. The class of regular languages is closed under union.
2. The class of regular languages is closed under concatenation.
3. Every NFA has an equivalent DFA.
4. The class of regular languages is closed under Kleene - star.
5. (Kleene‟s theorem) Language A is regular if A has a regular expression.
6. If A is finite language, then A is regular.
7. The class of regular languages is closed under intersection.
8. The class of regular languages is closed under complementation.
9. If A is regular language, then ∃ number p where, if s ∈ A with |s| > = p, then ∃ strings x,
y, z such that
s = xyz and (1) xyiz ∈ A for each i > = 0, (2) |y | > 0, and (3) |xy | < = p
10. Every CFL can be described by a CFG G = (V, , R, S) in Chomsky normal form, i.e., each
rule in G has one of two form s: A → BC or A → x, where (A Є V), (B, C Є V  {S}), x Є ,
and we also allow the rule S → Є.

BASIC THEORY OF COMPUTATION Page 160


11. If A is a regular language, then A is also a CFL.
12. A language is context free iff some PDA recognizes it.
13. (Pumping lemma for CFLs) For every CFL L, ∃ pumping length p such that ∀ strings s Є L
with |s| > = p, we can writes s = uvxyz with (1) uvixyiz Є L ∀ i > = 0, (2) |v y| > = 1, (3)
|vxy | < = p.
14. The class of CFLs is closed under union.
15. The class of CFLs is close d under concatenation.
16. The class of CFLs is closed under Kleene- star.
17. For e very multi- tape TM M , there is a single- tape TM M such that L (M) = L (M‟)
18. Every NTM has an equivalent deterministic TM.
19. Language L is Turing-recognizable if an NTM recognizes it.
20. A language is enumerable if some enumerator enumerates it
Church-Turing Thesis The information of algorithm is the same as Turing machine algorithm
1. ADFA = {<B, w> | B is a DFA that accepts string w} is Turing-decidable.
2. ANFA = {<B, w> | B is an NFA that accepts string w} is Turing-decidable.
3. AREX = {<R, w> | R is a regular expression that generates string w} is Turing-decidable.
4. EDFA = {<B> | B is a DFA with L (B) = Ø} is Turing-decidable.
5. EQDFA = {<A, B> | A and B are DFAS with L (A) = L (B)} is Turing-decidable
6. ACFG= {<G, w> | G is a CFG that generates string w} is Turing-decidable.
7. E= {G | G is a CFG with L (G) = Ø} is Turing-decidable.
8. Every CFL is Turing-decidable
9. ATM = {<M, w> | M is a TM that accepts string w} is undecidable.
10. The set R of all real numbers is uncountable
11. Some languages are not Turing-recognizable.
12. A language is decidable if it is both Turing-recognizable and co-Turing- recognizable.
13. ATM (bar) is not Turing-recognizable.
14. HALTTM = {<M, w> | M is a TM that halts on w} is undecidable.
15. ETMTM= {<M> | M is a TM with L (M) = Ø} is undecidable.
16. REGTM= {<M> is a TM and L (M) is regular} is undecidable.
17. EQTM= {<M1, M2> | M1, M2 are TMs with L (M1) = L (M2)} is undecidable.
18. (Rice‟s Thm.) Let P be any subset of the class of Turing-recognizable languages such that
P ≠ Ø and
P (bar) ≠ Ø. Then LP = {<M> | L (M) ∈ P} is undecidable.
19. If A < =m B and B is Turing-decidable, then A is Turing-decidable.
20. If A < =m B and A is undecidable, then B is undecidable.
21. If A < =m B and B is Turing-recognizable, then A is Turing-recognizable.
22. If A < =m B and A is not Turing-recognizable, then B is not Turing-recognizable.
23. ETM= {<M> is a TM with L (M) = Ø} is not Turing-recognizable.
24. EQTM= {<M1, M2> | M1, M2 are TMs with L (M1) = L (M2)} is neither Turing- recognizable
nor co-Turing-recognizable.

BASIC THEORY OF COMPUTATION Page 161


25. Let t (n) be a function with t (n) > = n. Then any t (n)-time multi-tape TM has an equivalent
O (t2 (n))-time single-tape TM.
26. Let t (n) be a function with t (n) > = n. Then any t (n)-time NTM has an equivalent 2O (t (n))-
time deterministic 1- tape TM.
27. PATH ∈ P.
28. REL PRIME ∈ P.
29. Every CFL is in P.
30. A language is in NP iff it is decided by some nondeterministic polynomial- time TM.
31. NP = Uk > = 0 NTIME(nk)
32. CLIQUE ∈ NP.
33. SUBSET-SUM ∈ NP.
34. If A < =P PB and B ∈ P, then A ∈ P.
35. 3SAT is polynomial-time reducible to CLIQUE
36. If there is an NP-Complete problem B and B ∈ P, then P = NP.
37. If B is NP- Complete and B < =P C for C ∈ NP, the n C is NP- Complete.
38. SAT is NP- Complete.
39. SAT is NP- Complete
40. CLIQUE is NP- Complete.
41. ILP is NP-Complete.

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)= *

• Some questions about the languages of CFGs are decidable


Is L(G) = , some aren‟t like Is L(G) = *
• Everything we‟ve tried for Turing machines is undecidable.
Is L(G) = , L(G)= * • Is the language semi decided by M regular? Context-free?
For Context free Grammar it is undecidable
 whether a CFG accepts the language of all strings
 whether two CFGs describe the same language
 whether CFG is ambiguous
 if a context-sensitive grammar describes a context-free language
 if a CFG, has an equivalent PDA that is deterministic
 if Given an ambiguous CFG, whether or not there is a different CFG that generates the
same language but is not ambiguous
 whether the complement of a given CFL is context free?
 whether the intersection of two CFL's is context free?
 given two CFG's, how can we tell if they have a word in common?
Decidable Problem for CFG
BASIC THEORY OF COMPUTATION Page 162
 DPDA Equality is Decidable
 Membership is decidable

BASIC THEORY OF COMPUTATION Page 163

You might also like