Deterministic Finite Automata: 1. (MCQ) (GATE-2021: 2M) 3. (NAT) (GATE-2021: 1M)
Deterministic Finite Automata: 1. (MCQ) (GATE-2021: 2M) 3. (NAT) (GATE-2021: 1M)
CHAPTER
1
Deterministic Finite Automata 3. [NAT] [GATE-2021 : 1M]
1. [MCQ] [GATE-2021 : 2M] Consider the following deterministic finite
Consider the following language: automaton (DFA)
L = {w {0,1} * | w ends with the substring 011}
Which one of the following deterministic finite
automata accepts L?
(a)
The number of strings of length 8 accepted by the
above automaton is ___.
(d)
8.1
GATE Wallah CS & IT Topic wise PYQs
Theory of Computation
p b q b
(a) r
a a
s
(a)
00 01 10 11 q
00 1 0
a,b
01 1 a,b
10 0
s
11 0 (b) b a,b
(b) p a,b q r
00 01 10 11 q a
00 0 1
01 1 a,b
10 0 a,b
11 0 (c) a,b b
p q r
(c)
00 01 10 11 q
00 1 0
01 1
b
10 0
11 0 p b q
(d)
00 01 10 11 q a a
00 1 0 (d)
s
01 1
10 0 a,b
11 0
8.2
GATE Wallah CS & IT Topic wise PYQs
Finite Automata and Transducer
a b (a) (b)
8.3
GATE Wallah CS & IT Topic wise PYQs
Theory of Computation
(a) Set of all strings that do not end with ab 18. [NAT] [GATE-2017 : 1M]
(b) Set of all strings that begin with either an a or ab The minimum possible number of states of a
(c) Set of all strings that do not contain the substring deterministic finite automaton that accepts the
ab. regular language L = {w1 a w2| w1, w2 ∈{a, b}*,
(d) The set described by the regular expression |w1|=2,|w2| ≥ 3} is___________.
b*aa*(ba)*b*
19. [NAT] [GATE-2015 : 2M]
Minimization
14. [NAT] [GATE-2023 : 1M]
Consider the language L over the alphabet {0, 1},
given below:
L = {w ∈ {0, 1}* | w does not contain three or more
consecutive 1’s}. Consider the DFAs M and N given above. The number
The minimum number of states in a Deterministic of states in a minimal DFA that accepts the language
Finite-state Automaton (DFA) for L is _____. L(M) L(N) is _______.
8.4
GATE Wallah CS & IT Topic wise PYQs
Finite Automata and Transducer
21. [MCQ] [GATE-2010 : 2M] Assume the initial state of the Mealy machine is 0.
Let w be any string of length n in {0,1}*. Let L be What are the Boolean expressions corresponding to
the set of all substrings of w. What is the minimum t and y in terms of s and b?
number of states in a non-deterministic finite (a) t = s + b
automaton that accepts L? y = sb
(a) n – 1 (b) n (b) t = b
(c) n + 1 (d) 2n – 1 y = sb
(c) t = b
22. [MCQ] [GATE-2008: 1M]
y = sb
Let N be an NFA with n states and let M be the
(d) t = s + b
minimized DFA with m states recognizing the same
language. Which of the following is y = sb
NECESSARILY true?
(a) m ≤ 2n 24. [MCQ] [GATE-2009 : 2M]
(b) n ≤ m Given the following state table of an FSM with two
(c) M has one accept state states A and B, one input and one output:
(d) m = 2n
Present Present Input Next Next Output
State A State B State State
Mealy Machine A B
23. [MCQ] [GATE-2021 : 2M] 0 0 0 0 0 1
Suppose we want to design a synchronous circuit
0 1 0 1 0 0
that processes a string of 0’s and 1’s. Given a string,
it produces another string by replacing the first 1 in 1 0 0 0 1 0
any subsequence of consecutive 1’s by a 0. Consider
1 1 0 1 0 0
the following example.
Input sequence: 00100011000011100 0 0 1 0 1 0
Output sequence: 00000001000001100 0 1 1 0 0 1
A mealy Machine is a state machine where both the 1 0 1 0 1 1
next state and the output are functions of the present
state and the current input. 1 1 1 0 0 1
The above-mentioned circuit can be designed as a If the initial state is A = 0, B = 0, what is the
two-state Mealy machine. The states in the Mealy minimum length of an input string which will take
machine can be represented using Boolean values 0 the machine to the state A = 0, B = 1 with output
and 1. We denote the current state, the next state, the = 1?
next incoming bit, and the output bit of the Mealy (a) 3 (b) 4
machine by the variables s, t, b and y respectively. (c) 5 (d) 6
❑❑❑
8.5
GATE Wallah CS & IT Topic wise PYQs
Theory of Computation
DFA for ending with 011: Every symbol is having two choices
0101010101010101
2 2 2 2 2 2 2 2
Total strings with length 8 = 28
Total strings with length 8 = 256
4. (d)
1. L(A) = Regular
2. (c)
L = *– L Complement of L(A) = Regular = Regular
= {0, 1}* – L Every Regular language is CFL
If L is a DFA with K states than in L DFA also
2. L(A) = 11*0(0 + 1)* + 0(0 + 1)*
having K states because number of states in L and
L are same. = (11*0 + 0) (0 + 1)*
= (1+ 0 + 0) ( 0 + 1)*
= (1+ + ) 0 (0 + 1)*
= 1*0 (0 + 1)*
8.6
GATE Wallah CS & IT Topic wise PYQs
Finite Automata and Transducer
3. Minimal DFA for [1*0 (0 + 1)*]: (iii) {p}, {q}, {r}, {s, t}
Number of states = 4.
Here s and t are equivalent.
a,b
Number of states in minimal DFA = 2
p b q b
r
4. Given DFA accepts all strings containing 0 as
substring. a a
s
a,b
5. (d)
From state 00 to read input 0 q(dead state)
From state 00 to read input 1 01
From state 01 to read input 1 11
7. (c)
Minimal accepted string = 00
It will accept all the strings end with 00.
8. (c)
-NFA:
6. (a)
Partition algorithm:
(i) {p, q, r} {s, t}
Non-final Final
(ii) {p, q}, {r}, {s, t}
8.7
GATE Wallah CS & IT Topic wise PYQs
Theory of Computation
a b
→P S R
Q R S
9. (a) S P Q
Reachable states for the input string 0011: R Q P
We don’t have correct option
10. (b)
13. (a)
Complement of given machine:
L = a+
L = * −L
= a* – a+
= {} It will accept set of all strings that do not end with
ab.
8.8
GATE Wallah CS & IT Topic wise PYQs
Finite Automata and Transducer
DFA for L
15. (6 to 6)
Divisible by 2 strings = , aa, aaaa, aaaaaa, ….. 17. (d)
Divisible by 3 strings = , aaa, aaaaaa, aaaaaaaaa, If NFA (N) having ‘n’ states and DFA having ‘k’
….. states.
Divisible by 2 but not 3 strings = a2, a4, a8, a10, a12, Then, relation between k and n is using subset
….. construction algorithm is:
18. (8 to 8)
L = {w1aw2 | w1, w2 {a, b}*, |w1| = 2, |w2| > 3}
= (a + b)2 a (a + b)3 (a + b)*
Number of states = 6
DFA for L:
8.9
GATE Wallah CS & IT Topic wise PYQs
Theory of Computation
Accept w = abb
DFA for L:
To design DFA for minimum 1 state is needed.
8.10
GATE Wallah CS & IT Topic wise PYQs
Finite Automata and Transducer
Transition Table:
s b
0 1
0 0, 0 1, 0
t, y t, y
1 0, 0 1, 1
t, y t, y Input = 101
From state 00, by reading 3 length minimum input
t=b
it takes to 01.
y = sb
Hence, option (b) is correct.
❑❑❑
8.11
GATE Wallah CS & IT Topic wise PYQs
Design of springs
CHAPTER
2
Construction of Regular Expression 4. [MCQ] [GATE-2013 : 1M]
1. [MSQ] [GATE-2021 : 2M] Consider the languages L1 = ϕ and L2 = {a}. Which
Which of the following regular expressions one of the following represents L1L2* L1* ?
represent(s) the set of all binary numbers that are (a) {} (b) ϕ
divisible by three? Assume that the string is (c) a* (d) {, a}
divisible by three.
(a) (0 + 1(01* 0)* 1)* 5. [MCQ] [GATE-2012 : 1M]
(b) (0 + 11 + 10(1 + 00)* 01)* Given the language L = {ab, aa, baa}, which of the
following strings are in L*?
(c) (0*(1(01* 0)* 1)*)*
1. abaabaaabaa
(d) (0 + 11 + 11(1 + 00)* 00)* 2. aaaabaaaa
3. baaaaabaaaab
2. [MCQ] [GATE-2020 : 1M] 4. baaaaabaa
Which one of the following regular expressions (a) 1, 2 and 3 (b) 2, 3 and 4
represents the set of all binary strings with an odd (c) 1, 2 and 4 (d) 1, 3 and 4
number of 1 's?
(a) (0* 10* 10*) * 0* 1 6. [MCQ] [GATE-2010 : 2M]
(b) 10*(0* 10* 10*)* Let L = {w (0 + 1)* | w has even number of 1s},
(c) ((0 + 1)* 1(0 + 1)* 1)* 10* i.e., L is the set of all bit strings with even number
of 1s. Which one of the regular expressions below
(d) (0* 10* 10*)* 10*
represents L ?
(a) (0* 10* 1)* (b) 0*(10* 10*)*
3. [MCQ] [GATE-2016 : 1M]
(c) 0*(10* 1)* 0* (d) 0* 1(10* 1)* 10*
Which one of the following regular expressions
represents the language: the set of all binary strings
7. [MCQ] [GATE-2009 : 2M]
having two consecutive 0’s and two consecutive
Which one of the following languages over the
1’s?
alphabet {0,1} is described by the regular
(a) (0 + 1) * 0011(0 + 1)* + (0 + 1)* 1100(0 + 1) * expression: (0 + 1)* 0(0 + 1)* 0(0 + 1)* ?
(b) (0 + 1) *(00(0 + 1) * 11 + 11(0 + 1) * 00) (a) The set of all strings containing the substring 00
(0 + 1) * (b) The set of all strings containing at most two 0’s
(c) (0 + 1) * 00(0 + 1) * + (0 + 1) * 11(0 + 1) * (c) The set of all strings containing at least two 0's
(d) 00(0 + 1) * 11+11(0 + 1) * 00 (d) The set of all strings that begin and end with
either 0 or 1
8.12
GATE Wallah CS & IT Topic wise PYQs
Regular Expression
0
1 12. [NAT] [GATE-2016 : 1M]
The number of states in the minimum sized DFA that
1 p
s q accepts the language defined by the regular
expression (0 + 1)*(0 + 1)(0 + 1) * is______.
1
13. [MCQ] [GATE-2015 : 1M]
0 0
r Let L be the language represented by the regular
expression Σ* 0011 Σ* where Σ = {0, 1}.
What is the minimum number of states in DFA that
0, 1
recognizes L (complement of L)?
Which one of the following regular expressions (a) 4 (b) 5
correctly describes the language accepted by A? (c) 6 (d) 8
(a) 1(0*11)*
14. [NAT] [GATE-2015 : 2M]
(b) 0(0 + 1)*
The number of states in the minimal deterministic
(c) 1(0 + 11)* finite automaton corresponding to the regular
(d) 1(110*)* expression (0 + 1)*(10) is ______.
S
I. 0* 1(1 + 00* 1)*
II. 0* 1* 1 + 11* 0* 1
III. (0 + 1)* 1
(a) I and II only (b) I and III only
(c) II and III only (d) I, II and III
P Q R S
(a) 2 1 3 4
(b) 1 3 2 4
(c) 1 2 3 4
Q (d) 3 2 1 4
❑❑❑
8.14
GATE Wallah CS & IT Topic wise PYQs
Regular Expression
8.15
GATE Wallah CS & IT Topic wise PYQs
Theory of Computation
5. (c)
L = ab + aa + baa
L* = (ab + aa + baa)* 9. (c)
6. (b)
Even number of 1’s = 0* (0*1 0* 10*)0*
= (0* 1 0* 1)* 0* = 0*(10* 10*)*
8.16
GATE Wallah CS & IT Topic wise PYQs
Regular Expression
13. (b)
L = * 0011*
L = (0 + 1)* 0011(0 + 1)*
DFA for L:
DFA for L :
11. (4 to 4)
DFA:
14. (3 to 3)
Minimal string for regular expression = 10
k 2
2 = 2 = 4 where k is the position of the symbol. DFA Design for (0 + 1)*(10):
12. (2 to 2)
(0 + 1)* (0 + 1) (0 + 1)* = (0 + 1)+ Number of states = 3
8.17
GATE Wallah CS & IT Topic wise PYQs
Theory of Computation
16. (b)
I. 0*1(1 + 00*1)*
0*1 (( + 00*)1)*
0*1 (0*1)* Regular expression = ε + 0(10*1 + 10)*1
+
(0*1) S
II. 0* 1* 1 + 11* 0* 1 it will not generate 0101
string.
III. (0 + 1)* 1 is same as (0*1)+
Hence, I and III regular expressions are correct
with respective DFA.
❑❑❑
8.18
GATE Wallah CS & IT Topic wise PYQs
Design of springs
CHAPTER
3
Regular Grammar and Pumping Lemma Consider the language L1 (over alphabet 0) accepted
1. [MCQ] [GATE-2023 : 1M] by the following automaton.
The order of L1 is _____________.
Consider the context-free grammar G below
S → aSb | X 4. [MCQ] [GATE-2016 : 2M]
X → aX | Xb| a | b Language L1 is defined by the grammar:
Where S and X are non-terminals, and a and b are S1 → aS1b |
terminal symbols. The starting non-terminal is S. Language L2 is defined by the grammar:
Which one of the following statements is S2 → abS2 |
CORRECT? Consider the following statements:
P: L1 is regular
(a) The language generated by G is (a + b) *
Q: L2 is regular
(b) The language generated by G is a*(a + b)b*
Which of the following is TRUE?
(c) The language generated by G is a*b*(a + b) (a) Both P and Q are true.
(d) The language generated by G is not a regualar (b) P is true and Q is false.
language. (c) P is false and Q is true.
2. [MCQ] [GATE-2019 : 1M] (d) Both P and Q are false.
For Σ={a, b}, let us consider the regular language
L = {x | x = a2 + 3k or x = b10 +12k, k ≥ 0}. 5. [MCQ] [GATE-2016 : 1M]
Which one of the following can be a pumping length (the
Which of the following languages is generated by the
constant guaranteed by the pumping lemma) for L?
given grammar?
(a) 3 (b) 5
S → aS | bS |
(c) 9 (d) 24
3. [NAT] [GATE-2018 : 2M] (a) {an bm| n, m ≥ 0}
Given a language L, define Li as follows: (b) {w {a, b}*| w has equal number of a's and
b’s}
L0 = {}
(c) {an| n ≥ 0} {bn| n ≥ 0} {an bn| n ≥ 0}
L1 = Li – 1. L for all i > 0
(d) {a, b}*
The order of a language L is defined as the smallest
k such that Lk = Lk + 1.
6. [MCQ] [GATE-2015 : 2M]
Consider alphabet Σ = {0,1}, the null/empty string λ
and the sets of strings X0, X1, and X2 generated by
the corresponding non-terminals of a regular
grammar. X0, X1 and X2 are related as follows:
X0 = 1 X1
8.19
GATE Wallah CS & IT Topic wise PYQs
Theory of Computation
❑❑❑
8.20
GATE Wallah CS & IT Topic wise PYQs
Regular Language and Grammar
1. (b) 3. (2 to 2)
X = a*(a + b)b* L = + 0 (00)* for given FA.
S = an bn = an a* (a + b) b* bn = a* (a + b) b*
L0 = {}
4. (c)
• S1 → aS1b |
8.21
GATE Wallah CS & IT Topic wise PYQs
Theory of Computation
5. (d) 8. (a)
S → aS | bS | L1: {wxwR |w, x {a, b}+}
L = (a + b)* L1 = axa + bxb
= {a, b}* = a (a + b)+ a + b(a + b)+ b = Regular
Hence, option (d) is correct. L2: {an bm | n m}= Not Regular
L3: a*b*c* = Regular
Hence, L1 and L3 are Regular.
6. (c)
X2 → 0X1 |
X2 = 0X1 + 9. (a)
X1 → 0X1 | 1X2 L1 : n110 and n 011
X1 = 0X1 | 10X1 | 1 We can construct DFA for L1 with the help of cycle
X1 = (0 + 10)*1 to count number of occurrences of both patterns 110
X0 = 1X1 and 011. While counting one pattern, other pattern
X0 = 1(0 + 10)*1 will be either equal or one more or less compared to
other pattern. This can be remembered with the few
Hence, option (c) is correct.
states.
L2 : n000 and n111
We can not make DFA for L2. While counting 000,
there is no way to remember the count using DFA.
Hence, option (a) is correct.
7. (b)
(a) If L is Regular then L.LR is Regular.
(b) May/may not be Regular over Σ = {a, b}.
If L = a* then wwR = (aa)* is regular
If L = (a+b)* then wwR is not regular
10. (a)
(c) Prefix(Regular) is always Regular
(d) Suffix(Regular) is always Regular L1.L2 = a n1 bn2 n1 , n 2 0
8.22
GATE Wallah CS & IT Topic wise PYQs
Regular Language and Grammar
11. (a)
I. {anb2m | n 0, m 0} a*(bb)*
II. {anbm | n = 2m} CFL
III. {anbm | n m} CFL
IV. {xcy | x, y {a, b}*} (a + b)* c (a + b)*
Hence, option (a) is correct. 13. (b)
I. FALSE
Consider the following NFA. Here all states are
accepting states, but language accepted by NFA
is not *.
12. (d)
I. If L1 L2 is Regular then, L1 and L2 may/may
not be regular.
an bn (DCFL) a* b*(Regular) = Regular II. TRUE
A B is Regular, when A is empty language.
an bn (DCFL) (a + b)* (Regular) = Regular
Any = (Regular)
II. {}{ab} {a2 b2} … = {anbn} is not
regular
Infinite union is not closed under regular
language.
Hence, option (d) is correct.
❑❑❑
8.23
GATE Wallah CS & IT Topic wise PYQs
Design of springs
CHAPTER
4
Pushdown Automata 2. [NAT] [GATE-2021 : 2M]
1. [MCQ] [GATE-2023 : 2M] In a pushdown automaton P = (Q, Σ, Γ, δ, q0, F), a
Consider the pushdown automaton (PDA) P below, transition of the form,
which runs on the input alphabet {a, b}, has stack
alphabet {⊥, A}, and has three states {s, p, q}, with
s being the start state. A transition from state u to
state v, labelled c/X/γ, where c is an input symbol or where p, q Q, a Σ {}, and X, Y Γ {},
, X is a stack symbol, and γ is a string of stack represents
symbols, represents the fact that in state u, the PDA
(q, Y) (p,a,X)
can read c from the input, with X on the top of its
Consider the following pushdown automaton over
stack, pop X from the stack, push in the string γ on
the stack, and go to state v. In the initial the input alphabet = {a, b} and stack alphabet Γ =
configuration, the stack has only the symbol ⊥ in it. {#, A}.
The PDA accepts by empty stack.
8.24
GATE Wallah CS & IT Topic wise PYQs
Context Free Language and Context Free Grammar
8.25
GATE Wallah CS & IT Topic wise PYQs
Theory of Computation
S → aSa | bSb | a | b (d) The set of all strings over {0, 1} containing at
least two 0’s
The language generated by the above grammar over
the alphabet {a, b} is the set of
15. [MCQ] [GATE-2008 : 2M]
(a) All palindromes
Which of the following statements are true?
(b) All odd length palindromes
1. Every left – recursive grammar can be
(c) Strings that begin and end with the same
converted to a right – recursive grammar and
symbol
vice-versa
(d) All even length palindromes
2. All - productions can be removed from any
context – free grammar by suitable
Common data for question 12 and 13.
transformations
A CFG G is given with the following productions where
S is the start symbol, A is a non-terminal and a and b are 3. The language generated by a context-free
terminals. grammar all of whose productions are of the
S → aS | A form X → w or wY (where, w is a string of
terminals and Y is a non-terminal), is always
A → aAb | bAa |
regular
12. [MCQ] [GATE-2008 : 2M] 4. The derivation trees of strings generated by a
Which of the following strings is generated by the context-free grammar in Chomsky Normal
grammar above? Form are always binary trees
(a) aabbaba (b) aabaaba (a) 1, 2, 3 and 4
(c) abababb (d) aabbaab (b) 2, 3 and 4 only
(c) 1, 3 and 4 only
(d) 1, 2 and 4 only
8.26
GATE Wallah CS & IT Topic wise PYQs
Context Free Language and Context Free Grammar
Context Free Language Identification Which of the above statements is/are TRUE?
16. [MSQ] [GATE-2022 : 2M] (a) I only (b) II only
Consider the following languages: (c) I and III only (d) III only
L1 = {an wan | w {a, b}*}
20. [MCQ] [GATE-2020 : 2M]
L2 = {wxwR | w, x{a, b}* , |w|, |x| > 0}
Consider the following languages.
Note that wR is the reversal of the string w. Which of
the following is/are TRUE? L1 = {wxyx | w, x, y (0 + 1)+}
(a) L1 and L2 are regular L2 = {xy | x, y (a + b)*, |x| = |y|, x y}
(b) L1 and L2 are context – free Which one of the following is TRUE?
(c) L1 is regular and L2 is context – free (a) L1 is regular and L2 is context-free.
(d) L1 and L2 are context – free but not regular (b) L1is context-free but L2 is not context-free.
(c) Neither L1 nor L2 is context-free.
17. [MSQ] [GATE-2022 : 2M] (d) L1 is context-free but not regular and L2 is
Consider the following languages: context-free.
L1 = {ww | w {a, b}*}
L2 = {anbncm | m, n 0} 21. [MCQ] [GATE-2019 : 2M]
L3 = {ambncn | m, n 0} Which one of the following language over
= {a, b} is NOT context – free?
Which of the following statements is/are FALSE?
(a) {wwR | w{a, b}*}
(a) L1 is not context – free but L2 and L3 are
deterministic context – free. (b) {wan bn wR│w {a, b}*, n ≥ 0}
(b) Neither L1 nor L2 is context – free. (c) {wan wR bn | w {a, b}*, n ≥ 0}
(c) L2, L3 and L2 L3 all are context – free. (d) {an bi│i {n, 3n, 5n}, n ≥ 0}
(d) Neither L1 nor its complement is context – free.
22. [MCQ] [GATE-2018 : 2M]
18. [MSQ] [GATE-2021 : 2M] Consider the following languages:
For a string w, we define wR to be the reverse of w. I. {am bn cp dq |m + p = n + q,
For example, if w = 01101 then wR = 10110. where m, n, p, q ≥ 0}
Which of the following languages is/are context- II. {am bn cp dq |m = n and p = q,
free? where m, n, p, q ≥ 0}
(a) {w x wR xR | w, x {0, 1}*} III. {am bn cp dq |m = n = p and p ≠ q,
(b) {w wR x xR | w, x {0, 1}*} where m, n, p, q ≥ 0}
(c) {w x wR | w, x {0, 1}*} IV. {am bn cp dq |mn = p + q, where m, n, p, q ≥ 0}
(d) {w x xRwR | w, x{0, 1}*] Which of the languages above are context-free?
(a) I and IV only (b) I and II only
(c) II and III only (d) II and IV only
19. [MCQ] [GATE-2020 : 1M]
Consider the language L = {an | n 0} {an bn |
n 0} and the following statements
23. [MCQ] [GATE-2016 : 2M]
I. L is deterministic context-free Consider the following languages:
II. L is context-free but not deterministic L1 = {an bm cn + m : m, n ≥ 1}
context-free L2 = {an bn c2n : n ≥ 1} Which one of the following is
III. L is not LL(k) for any k. TRUE?
8.27
GATE Wallah CS & IT Topic wise PYQs
Theory of Computation
8.28
GATE Wallah CS & IT Topic wise PYQs
Context Free Language and Context Free Grammar
❑❑❑
8.29
GATE Wallah CS & IT Topic wise PYQs
Theory of Computation
8.30
GATE Wallah CS & IT Topic wise PYQs
Context Free Language and Context Free Grammar
0/1/, z → z; no operation
q1 :
10110010010
5. (d)
(a) abab
7. (b)
T → bT | b
T = b+
S → abScT | abcT
S = abS cb+ | abcb+
= {abn abcb+ (cb+)n | n > 0 }
8.31
GATE Wallah CS & IT Topic wise PYQs
Theory of Computation
(b) S → Ab | Bb | c
11. (b)
A → Bd |
B→e • S → aSa | bSb | a | b
There is not left recursion. This grammar will generate all odd length
palindrome strings.
(c) S → Aa | B
A → Bb |Sc |
B→d
S → A → S indirectly there is a left
recursion S to S.
8.32
GATE Wallah CS & IT Topic wise PYQs
Context Free Language and Context Free Grammar
8.33
GATE Wallah CS & IT Topic wise PYQs
Theory of Computation
OR 19. (c)
= {wxwR | w, x{a, b}+} I. L is deterministic context-free (True)
It is well known regular language. II. L is context-free but deterministic context-free
Every regular language is also CFL. (False)
Hence, option (a, b, c) are correct. Regular DCFL = DCFL
DPDA:
17. (b, c, d)
L1 = {ww | w {a, b}*} CSL
L2 = {an bn cm | m, n 0} an bn c* DCFL
L3 = {am bn cn | m, n 0} a* bn cn DCFL
• Every DCFL language is CFL also III. L is not LL(k) for any k. (True)
• DCFL DFCL
an bn c* a* bn cn
= an bn cn = CSL
L1 = ww = CFL 20. (a)
L1 = wxwy
Put minimum string in x = 0 or 1
• L1 = w0y0 + w1y1
( 0 + 1)+ 0 ( 0 + 1)+ 0 + ( 0 + 1)+ 1( 0 + 1)+ 1 is
18. (b, c, d) Regular
• L2 = CFL language
(a) Not CFL
(b) CFL
8.34
GATE Wallah CS & IT Topic wise PYQs
Context Free Language and Context Free Grammar
24. (b)
L1 = {am bn an bm | m, n ≥ 1}= CFL
L2 = {am bn am bn│m, n ≥ 1} = Not CFL 28. (b)
L3 = {am bn |m = 2n + 1} = CFL L1={ai bj ck |i = j, k ≥ 1} an bn c+ = DCFL
L2 = {ai bj |j = 2i, i ≥ 0} ak b2k = DCFL
Every DCFL is CFL.
• L1 L2 =
• L1 L2 = CFL
• L2 is a DCFL. So, DPDA possible.
25. (c)
Hence, option (b) is correct.
(a) The language L ={an bn | n ≥ 0} is regular.
False
(b) The language L = {an | n is prime } is regular.
False
8.35
GATE Wallah CS & IT Topic wise PYQs
Theory of Computation
30. (b, c, d)
L1 = Regular, L2 = CFL
31. (c)
34. (c)
L1 Regular
A. Regular CFL CFL
L2 CFL
B. Regular – CFL
(i) L1 L2 Reg CFL CFL
Regular CFL need not be regular
(ii) L1 . L2 Reg CFL CFL
C. * – Regular Regular
(iii) L1 – L2 Reg – CFL Reg CFL CSL D. * – CFL need not be regular
(iv) L1 L2 Reg CFL CFL Hence, option (c) is correct.
8.36
GATE Wallah CS & IT Topic wise PYQs
Context Free Language and Context Free Grammar
❑❑❑
8.37
GATE Wallah CS & IT Topic wise PYQs
Design of springs
CHAPTER
5
Turing Machine (a) Both 2* and * is countable
1. [MCQ] [GATE-2019 : 2M] (b) 2* is countable and * is uncountable
Consider the following sets: (c) 2* is uncountable and * is countable
S1: Set of all recursively enumerable languages (d) Both 2* and * are uncountable
over the alphabet {0, 1} 4. [MCQ] [GATE-2011 : 1M]
S2: Set of all syntactically valid C programs Which of the following pairs have DIFFERENT
expressive power
S3: Set of all languages over the alphabet {0, 1}
(a) Deterministic finite automata (DFA) and Non-
S4: Set of all non-regular languages over the
deterministic finite automata (NFA)
alphabet 0, 1}
(b) Deterministic push down automata (DPDA) and
Which of the above sets are uncountable? Non-deterministic push down automata (NPDA)
(a) S1 and S2 (b) S3 and S4 (c) Deterministic single-tape Turing machine and
(c) S2 and S3 (d) S1 and S4 Non-deterministic single – tape Turing machine
(d) Single-tape Turing machine and multi-tape
2. [MCQ] [GATE-2017 : 2M] Turing machine
Let A and B be finite alphabets and let # be a symbol 5. [MCQ] [GATE-2011 : 2M]
outside both A and B. Let f be a total function from Consider the languages L1, L2 and L3 are given
A* to B*. We say f is computable if there exists a below:
Turing machine M which given an input x in A*, L1 = {0p 1q│p, q N},
always halts with f(x) on its tape. Let Lf denote the L2 = {0p 1q│p, q N and p = q} and
language {x # f(x)|x A*}. Which of the following L3 = {0p 1q 0r | p, q, r N and p = q = r}
statements is true? Which of the following statements is NOT TRUE?
(a) f is computable if and only if Lf is recursive. (a) Push Down Automata (PDA) can be used to
(b) f is computable if and only if Lf is recursively recognize L1 and L2
enumerable. (b) L1 is a regular language
(c) All the three languages are context free
(c) If f is computable then Lf is recursive, but not
(d) Turing machines can be used to recognize all
conversely.
the languages
(d) If f is computable then Lf is recursively
6. [MCQ] [GATE-2008 : 1M]
enumerable, but not conversely.
Which of the following is true for the language {ap |
p is a prime number}?
3. [MCQ] [GATE-2014 : 1M] (a) It is not accepted by a Turning Machine
Let be a finite non-empty alphabet and let 2* be (b) It is regular but not context-free
the power set of *. Which one of the following is (c) It is context-free but not regular
TRUE? (d) It is neither regular nor context-free, but
accepted by a Turing machine
8.38
GATE Wallah CS & IT Topic wise PYQs
Turing Machine (Recursive and RELs)
8.39
GATE Wallah CS & IT Topic wise PYQs
Theory of Computation
❑❑❑
8.40
GATE Wallah CS & IT Topic wise PYQs
Turing Machine (Recursive and RELs)
2. (a, d)
f
A* ⎯
⎯⎯⎯
⎯→ B* 4. (b)
a1 → f (a1) = b1 • DFA ≡ NFA
a2 → f (a2) = b2 • DPDA NPDA
a3 → f (a3) = b3 • DTM ≡ NTM whether it is a single tape or
a4 → f (a4) = b4 multi tape.
Lf = {a1# f(a1), a2 #, f(a2)……. }
• Lexicographical order is possible. So, Lf is
recursive.
8.41
GATE Wallah CS & IT Topic wise PYQs
Theory of Computation
5. (c) 9. (d)
L1 = {0 1 │p, q N} 0 1 Regular
p q * *
• L1 = {0p1q0r | p, q, r ≥ 0}
L2 = {0p1q│p, q N and p = q} and DCFL = 0*1*0* is Regular language
L3 = {0p1q0r |p, q, r N and p = q = r} CSL • L2 = {0p1q0r | p, q, r ≥ 0 p ≠ r}
Hence, option (c) is correct.
= DCFL language
• L1 L2 = Regular DCFL = DCFL
• DCFL = DCFL
• Regular = Regular
6. (d)
• {ap | p is a prime number} it is a CSL language.
Every CSL is recursive and RE.
Hence, option (d) is correct.
10. (c)
List-I List-II
7. (a, c, d) A. Checking that
identifier are declared
3. L = wcw|w ( a|b )
*
(a) The intersection of two redular languages is
regular. before their use
Reg Reg Reg True B. Number of formal 1. L = a n bm cn d m | n 1,m 1
(b) The intersection of two context-free languages parameters in the
is context-free. declaration of a
CFL CFL CSL False function agrees with
(c) The intersection of two recursive languages is the number of actual
recursive. parameters in a use of
Rec Rec Rec True that function
(d) The intersection of two recusively enumerable C. Arithmetic 2. X → X b X | X c X | d X f | g
languages is recursively enumerable. expressions with
REL REL REL True matched pairs of
parentheses
D. Palindromes 4. X → bXb | cXc |
8. (d)
L1 = {aP |p is a prime number} Not CFL
L2 = {an bm c2m | n ≥ 0, m ≥ 0} DCFL
L3 = {an bn c2n | n ≥ 0} Not CFL
L4 = {an bn |n ≥ 1} DCFL 11. (b, c, d)
(a) Every subset of a recursively enumerable
language is recursive. FALSE
Because subset is not closed under any
language.
8.42
GATE Wallah CS & IT Topic wise PYQs
Turing Machine (Recursive and RELs)
(b) If a language L and its complement L are both Hence, option (d) is correct.
recursively enumerable, then L must be
recursive. TRUE
(c) CFL = CSL
Every CSL is recursive and recursive
enumerable.
15. (d)
(d) Regular Regular = Regular
L1 : CFL
Every Regular language is DCFL, CFL,
Recursive and RE. L1 : RE but not Recursive
I. CFL = CSL
Every CSL is recursive and recursive
enumerable.
II. RE but not Recursive = NOT RE
12. (d)
(a) Emptiness for DFA is decidable (Recursive). III. CFL = CSL (may/may not be CFL) but it will
(b) Totality for DFA is decidable (Recursive). be CSL
(c) Emptiness for PDA is decidable (Recursive). IV. CFL RE = CSL RE = RE
(d) Totality for PDA is undecidable (Not
Recursive).
16. (c)
8.43
GATE Wallah CS & IT Topic wise PYQs
Theory of Computation
20. (d)
L and L are recursively enumerable if and only if L
is recursive.
18. (c) Hence, option (d) is correct.
• L1 = {am bm can bn | m, n ≥ 0}
= CFL
• L2 = {aibjck | i, j, k ≥ 0}
=a*b*c* = Regular
• L = L1 L2
= am bm c = DCFL
❑❑❑
8.44
GATE Wallah CS & IT Topic wise PYQs
Design of springs
CHAPTER
6
Undecidability Which one of the following options is correct?
1. [MSQ] [GATE-2022 : 2M] (a) Both L1 and L2 are decidable.
Which of the following is/are undecidable? (b) L1 is decidable and L2 is undecidable.
(a) Given two Turing machines M1 and M2, decide (c) L1 is undecidable and L2 is decidable.
if L(M1) = L(M2). (d) Both L1 and L2 are undecidable.
(b) Given a Turing machine M, decide if L(M) is
regular. 4. [MCQ] [GATE-2020 : 2M]
Which of the following languages are undecidable?
(c) Given a Turing machine M, decide if M accepts
all strings. Note that 〈M〉 indicates encoding of the Turing
machine M.
(d) Given a Turing machine M, decide if M takes
more than 1073 steps on every string. L1 = {〈M〉|L(M) = ϕ}
L2 = {〈M, w, q〉|M on input w reaches state q in
2. [MCQ] [GATE-2021 : 2M] exactly 100 steps}
Consider the following two statements about L3 = {〈M〉|L(M) is not recursive}
regular languages:
L4 = {〈M〉|L(M) contains at least 21 members)
S1: Every infinite regular language contains an
(a) L1, L3 and L4 only (b) L2, L3 and L4 only
undecidable language as a subset.
S2: Every finite language is regular. (c) L1 and L3 only (d) L2 and L3 only
Which one of the following choices is correct?
5. [MCQ] [GATE-2018 : 2M]
(a) Only S1 is true
Consider the following problems. L(G) denotes the
(b) Only S2 is true language generated by a grammar G. L(M) denotes
(c) Both S1 are S2 are true the language accepted by a machine M.
(d) Neither S1 nor S2 is true I. For an unrestricted grammar G and a string w,
whether wL(G).
3. [MCQ] [GATE-2021 : 2M] II. Given a Turing Machine M, whether L(M) is
regular.
For a Turing machine M, 〈M〉 denotes an encoding
of M. Consider the following two languages. III. Given two grammars G1 and G2, whether L(G1)
= L(G2).
L1 = {〈M〉|M takes more than 2021 steps on all
IV. Given an NFA N, whether there is a
inputs}.
deterministic PDA P such that N and P accept
L2 = {〈M〉|M takes more than 2021 steps on some
the same language.
input}.
Which one of the following statements is correct?
8.45
GATE Wallah CS & IT Topic wise PYQs
Theory of Computation
(a) Only I and II are undecidable L2 = {M|M takes at least 2016 steps on all inputs}.
(b) Only III is undecidable L3 = {M|M accepts }.
(c) Only II and IV are undecidable Where for each Turning machine M, M denotes a
(d) Only I, II and III are undecidable specific encoding of M. Which one of the following
is TRUE?
6. [MCQ] [GATE-2017 : 2M] (a) L1 is recursive and L2, L3 are not recursive.
Let L(R) be the language represented by regular (b) L2 is recursive and L1, L3 are not recursive.
expression R. Let L(G) be the language generated by (c) L1, L2 are recursive and L3 is not recursive.
a context free grammar G. Let L(M) be the language (d) L1, L2, L3 are recursive .
accepted by a Turing machine M.
Which of the following decision problems are 9. [MCQ] [GATE-2015 : 1M]
undecidable? Consider the following statements:
I. Given a regular expression R and a string w, is 1. The complement of every Turning decidable
w L(R)? language is Turning decidable.
II. Given a context-free grammar G, is L(G) = ϕ? 2. There exists some language which is in NP but
is not Turing decidable.
III. Given a context-free grammar G, is L(G) = Σ*
3. If L is a language in NP, L is Turing decidable.
for some alphabet Σ?
Which of the above statements is/are True?
IV. Given a Turing machine M and a string w, is (a) Only 2 (b) Only 3
w L(M)?
(c) Only 1 and 2 (d) Only 1 and 3
(a) I and IV only (b) II and III only
(c) II, III and IV only (d) III and IV only 10. [MCQ] [GATE-2014 : 2M]
Which one of the following problems is
7. [MCQ] [GATE-2016 : 1M] undecidable?
Which of the following decision problems are (a) Deciding if a given context-free grammar is
undecidable ambiguous.
I. Given NFAs N1 & N2, is L(N1) L(N2) = ? (b) Deciding if a given string is generated by a
given context-free grammar.
II. Given a CFG G = (N, , P, S) and a string x
(c) Deciding if the language generated by a given
*, does x L(G)? context-free grammar is empty.
III. Given CFGs G1 and G2 is L(G1) = L (G2)? (d) Deciding if the language generated by a given
IV. Given a TM M, is L(M) = Φ? context-free grammar is finite.
(a) I and IV only
(b) II and III only 11. [MCQ] [GATE-2014 : 2M]
Let M be the encoding of a Turing machine as a
(c) III and IV only
string over = {0, 1}. Let L = {M| M is a Turing
(d) II and IV only
machine that accepts a string of length 2014}. Then,
L is
8. [MCQ] [GATE-2016 : 2M] (a) decidable and recursively enumerable
Consider the following languages: (b) undecidable but recursively enumerable
L1 = {M|M takes at least 2016 steps on some (c) undecidable and not recursively enumerable
input}. (d) decidable but not recursively enumerable
8.46
GATE Wallah CS & IT Topic wise PYQs
Undecidability and Reducibility
❑❑❑
8.47
GATE Wallah CS & IT Topic wise PYQs
Theory of Computation
5. (d)
3. (a)
I. Membership problem for an unrestricted
L1 = {〈M〉|M takes more than 2021 steps on all
grammar is Undecidable.
inputs} Decidable.
Verify every string in length 0 to 2021. II. Given a Turing Machine M, whether L(M) is
L2 = {〈M〉|M takes more than 2021 steps on some regular. Non-trivial problem for Turing
input}Decidable. machine is Undecidable.
8.48
GATE Wallah CS & IT Topic wise PYQs
Undecidability and Reducibility
6. (d)
I. Given a regular expression R and a string w, 9. (d)
is w L(R)?
Membership problem for Regular is
Decidable.
II. Given a context-free grammar G, is L(G) = ϕ?
Emptines? • Decidable complement is always Decidable.
Membership, finiteness and emptiness • Every NP problem is always Decidable.
problems for CFL are Decidable.
III. Given a context-free grammar G is L(G) = Σ*
for some alphabet Σ?
Totality problem CFL is Undecidable.
10. (a)
IV. Given a Turing machine M and a string w, is
w L(M)? • Checking ambiguity for grammar is always
Undecidable.
Membership problem for Turing machine is • Membership problem for CFL is Decidable
Undecidable. (using CYK algorithm).
• Emptiness problem for CFL is Decidable.
• Finiteness problem for CFL is Decidable.
7. (c)
I. Dis-jointness problem for FA is Decidable.
II. Membership problem for CFG is Decidable.
11. (b)
III. Equivalence problem for CFG is Undecidable.
IV. Emptiness problem for TM is Undecidable. • L is undecidable but partially decidable (RE).
Hence, option (c) is correct. Hence, option (b) is correct.
8.49
GATE Wallah CS & IT Topic wise PYQs
Theory of Computation
13. (c)
• NTM is equivalent to DTM
16. (c)
• RELs are not closed under complement. X: Recursive
• Recursive languages are closed under both Y: RE but not Recursive
intersection and complement.
• Y W
• RELs are closed under both union and
intersection. = RE but not Recursive W
Hence, option (c) is correct. = NOT RE W
So, W can not be RE
• Z X
= Z Recursive
14. (d) = Z Recursive
1. These kind of problems are non-trivial. So, it is So, Z must be Recursive
Undecidable.
2. If L is a context-free language, then, is L also
context-free. It is Undecidable.
3. If L is a regular language, then, is L also
regular. Regular is closed under complement. 17. (d)
So, it is Decidable. Given A ≤ m B
4. If L is a recursive language, then, is L also • If A ≤ m recursive then, A will be recursive.
recursive. It is Decidable. • If Undecidable ≤ m B then, B must be
Undecidable.
• If A ≤ m RE then, A will be RE.
• If A ≤ m NOT RE then, A may/may not be
NOT RE.
15. (b) Hence, option (d) is false statement in given data.
1. Whether the intersection of two regular
languages is infinite.
Infiniteness problem for Regular is Decidable.
2. Whether a given context-free language is
regular. Undecidable
❑❑❑
8.50
GATE Wallah CS & IT Topic wise PYQs