Basic TOC Regular - Sloution
Basic TOC Regular - Sloution
Basic TOC Regular - Sloution
BASIC
THEORY OF COMPUTATION
Years Marks
2015 5
2016 9
2017 10
2018 8
2019 5
2020 9
2021 Set-1 8
2021 Set-2 10
THEORY OF COMPUTATION FOR GATE SYLLABUS
Chomsky classification of grammar.
Regular languages
Regular expression
Regular grammar
Finite Automata (DFA/NFA)
Conversion from NFA to DFA
Minimization of DFA
Closure Properties
Mealy /Moore machine
Pumping Lemma for regular language
Context free language
Properties
Context –free grammar
PDA (Push down-automata)
Chomsky Normal Form
Greibach Normal Form
CYK algorithm
Pumping Lemma for Context Free Language
Turing Machine
TM Construction
Turing decidable Language (Recursive language)
Turing Machine recognizable(Recursively enumerable language)
Undecidable / decidable problem.
Countable / uncountable sets.
Book Reference:
An Introduction to formal languages and automata by “PETER LINZ”
An introduction to Automata Theory, Language & computation by
“Ullmann, Hopcraft&Motwani”
TABLE OF CONTENTS
Q4. What is the highest type number that can be assigned to the following grammar?
S → aA | bB
A → aB | bC
B → aB | bB
C → aC | bC | λ
Q26. Consider the following grammar G with start symbol S over the alphabet Σ = {a, b}
S → aSaa | B
B → bB | λ
The language generated by G is
L1 = {anbna2m |n, m ≥ 0} L2 = {anb2m |n, m ≥ 0}
L3 = {anbma2n |n, m ≥ 0} L4 = {anbma2m |n, m ≥ 0}
(A)L1 (B) L2
(C)L3 (D)L4
Can be deived
Q37. Which of the following is not in the set of strings denoted by the regular expression R = (a*
b c*)*?
(A) aabc (B) bacd
(C) abcbc (D) babbc
(D) none
Q56. The regular expression (b*ab*ab*)* represents the language
(A) L = {w : w *, na(w) is divisible of 2 }
(B) every b is followed by at least one a
(C) L = {w : w * na(w) >= 2 }
(D) None of these.
Q60. Let = {0, 1}, and language over, L = {*| contains odd number of 1‟s}. Which
Of the following regular expression best describes the given language?
(A) 0*(10*10*)*10* (B) 0*1(11)* 0*
(C) 0*1*0*1*0*1 (D) 1(11)*
Q62. Let = {0, 1}, and language over, L = {*| is a binary number divisible by 4}.
Which of the following regular expression best describes the given language?
(A) (0+1)*00 (B) (0+1)*0
(C) (0+1)* 000 (D) (0+1)* 100
Q72. How many of the regular expression(s) which matches all strings of 0‟s and 1‟s that
do not contain the substring 011? ____________
(1) ((011)0*1*)* (2) (0*1)+0* + 1*0*
(3) (01|010|100|110)* (4) (0+1)*0*|1*0*
Answer: 1
Solution: ((∅*∩ a) ∪ (∅∪ b*)) ∩ ∅* = (∅ ∪ b*) ∩ 𝜆 = 𝜆. So, the cardinality = 1.
Q75. How many strings are there in the language defined by regular expression?____________
((∅*∪ b) ∩ (b*∪∅))
Answer: 2
Solution: ((∅*∪ b) ∩ (b*∪∅)) = {λ ∪ b} ∩ b* = {λ ∪ b}. So, the cardinality = 2.
Q76. How many strings of length less than 5 contains the language described by the regular
expression 0*1(0 + 1)* 01*? ______________
Q77. Let L be the language generated by regular expression ((a + b)*b(a + ab)*). How many
strings of length less than four are there in L? ______
Answer: 11
Solution: Required number of strings of length less than four
= (21 − 1) + (22 − 1) + (23 − 1) = 1 + 3 + 7 = 11
Solution:
S→Aab S→Aab S→Aab
S→Bab S→Aabab S→Aabab
S→aab --- S→Babab S→Aababab
(1) S→aabab S→Bababab
S→aabab---(2) S→aab(abab) ----(3)
So expression is: aab(ab)*
Answer: B
Q79. Consider the following grammar G:
S →AabB, A→ b | bA | λ, B → aB | aa | λ
Which of the following regular expression is equivalent to the language generated by G?
(A) b*abaa* (B) a*abb*
(C) b*aba* (D) b+aba+
If string S is accepted by this DFA, which of the following strings cannot be a suffix of S?
(A)111 (B) 111001
(C) 11011 (D) 0010111
Answer: B
Solution:
(A) Yes; because 111 is a suffix of 0111 and it is accepted by given DFA
(B) No; because after two zeroes we need two 1.
(C) Yes; because 11011 is a suffix of 011011 and it is accepted by given DFA.
(D) Yes; because 0010111 is a suffix of 00010111and it is accepted by given DFA.
Q92. Let the language accepted by G is L(D) then complement of L(D) is equivalent to
(A) 1+ (B) 1*
(C) 1* + 0* (D) 1(0+1)*
Data for next twenty questions: Consider the following two DFA‟s D1 and D2:
It is given the language accepted by D1 and D2 are L (D1) and L (D2), respectively.
Q94. [MSQ]
If L (D) = L(D1) ∪ L(D2), then which of the following regular expression is/are
equivalent to L(D)?
(A) (0 + 1)* (B) (01 + 10)(0 + 1)*
(C) (0*1 + 1*0) (0 + 1)* (D) (0 + 1)+
Q97. If L(D) = L(D1).L(D2), then the regular expression for L(D) is equivalent to
(A) 0*11*0 (0 + 1)* (B) 0*1(0+1)*1*0(0+1)*
(C) (0 + 1)* (D) (0 + 1)+
Q98. If L(D) = L(D1)R.L(D2)R, then the regular expression for reverse of L(D) is
(A) (0 + 1)* (B) (0 + 1)*1*0(0 + 1)*10*
(C) 0*1(0 + 1)*1*0(0 + 1)* (D) (0 + 1)*01*(0 + 1)*10*
The regular expression for complement of L(D) is 0* + 1*. So, correct answer is C.
Q101. [MSQ]
If L(D) = L(D1)*∪ L(D2)*, then which of the following regular expression is/are
equivalent to L(D)?
(A) (01 + 10)*
(B) (0 + 1) *
(C) 0*1*(0+1)*
(D) none of these
Q104. Minimum how many states are required to construct the DFA for 𝐿(𝐷1) ∩ 𝐿(𝐷2)? ____
Q106. Minimum how many states are required to construct the DFA for 𝐿(𝐷1). 𝐿(𝐷2)? ____
Q109. [MSQ]
Which of the following Grammars accept the language L(D1) ∩ L(D2)?
(A) S 0X1A | 1Y0A, X 0X | λ, Y 1Y | λ, A 0A | 1A | λ
(B) S XY, X 0A1 | 1B0, A 0A | λ, B 1B | λ, Y 0Y | 1Y | λ
(C) S 0S | 1S | 0 | 1
(D) None of the above
If the language accepted by M is L(M) then the regular expression for reverse of L(M)
is
(A) (a + b)*{λ + a + aa + aab + aaba + aabbab}
(B) (aabab)(a + b)*
(C) babaa (a + b)*
(D) None of the above
Which of the following option(s) is/are true about -closure of different states of
given NFA?
(C) (D)
∈ −𝑐𝑙𝑜𝑠𝑢𝑟𝑒 𝑝 = 𝑝, 𝑞, 𝑟 None of these
∈ −𝑐𝑙𝑜𝑠𝑢𝑟𝑒 𝑞 = 𝑞
∈ −𝑐𝑙𝑜𝑠𝑢𝑟𝑒 𝑟 = 𝑟
Q119. [MSQ]
Consider the following FSA: (Where state „3‟ is final state) :
(A) 0*1*
(B) 1*0*
(C) (1+0)* 1*(0+1)*
(D) (1+0)1*0(0+1)*
Q123. How many of the following regular expressions that denotes a subset of the language
recognized by the given DFA? ___________
(1) 0*(11)*0*
(2) 0*1(10*1)*1
(3) 0*1(10*1)*10∗
(4) 0*1(10*1)0(100)*
(5) (0*1(10*1)*10* + 0*)*
Similarly, There is another path to reach final states. First we move from q1 to q2 then
q2 to q4. After that, we have two loop (q4q2, q2q4)* and (q4q3, q3q2, q2q4)* then we
will traverse q4q5 edge to reach final state q5.
So, its regular expression will be a(bb + bab)*a. So, i & ii are correct.
(A) a*(a+b)b
(B) a*(a+b)ba*
(C) a*{((a+b)b)*a* + λ}
(D) (a +(a+b)b)*
(A) All strings of the form 0+w, where w contains an even number of ones.
(B) All strings of the form 000+w, where w contains an even number of ones.
(C) All strings of the form 00+w, where w contains an odd number of ones.
(D) All strings of the form 00+w, where w contains an even number of ones.
Solution:
Option (a):
All string of the form 0w, where w contain an even number of one‟s is false because
string contain at least two zero‟s.
Option (b) is false. all string contain at least 3a‟s this also false, because automata
generate string at least two zero‟s and even number of ones .
So option d is correct.
Answer: D
(A) L= {w| w has number of „a‟ divisible of 4 and number of „b‟ divisible of 3}
(B) L= {w| w has exactly two a‟s and at least two b‟s}
(C) L= {w | w has exactly two a‟s and number of b‟s divisible by 2}
(D) L= {w | w has at least two a‟s and number of b‟s divisible by 2}
(A)L= {w| w has an even number of a‟s and one or two b‟s}
(B)L= {w| w has an even number of a‟s and at least two b‟s}
(C)L= {w| w has an at least two a‟s and one or two b‟s}
(D)L= {w| w has an at least two a‟s and one or two b‟s}
If L(D) is language accepted by DFA D, then which of the following language is exactly
equivalent to L(D)?
(A) All the strings containing substring 100101
(B) All the strings start with 10 and end with 01
(C) All the strings start with 100 and end with 101
(D) All the strings of length greater than or equal to six.
(A) (00+11)+
(B) All the strings containing 00 and 11 as substring
(C) All the strings end with 00 or 11
(D) All the strings of length greater than or equal to two
Solution: (a)
(b)
(c)
(d)
Answer: C
Let the language accepted by DFA1 is L1 and that of DFA2 is L2. Which of the following
is true?
(A) L1 L2
(B) L2 L1
(C) L1= L2
(D) L1 ≠ L2
Q138. Consider the following language:L = {w ∈ {a, b}∗| every a‟s in w is followed immediately
by the string bb}. Minimum number of states in a deterministic finite state automaton for
L is __________
Q141. How many number of states are required to construct the minimized DFA for following
languages over {a, b}whose languages of accepted strings (exactly) are:
(i) {a, aa, aaa, aaaa}. ________
(ii) all strings not in {a, aa, aaa, aaaa}. ____________
(iii) all strings whose length is divisible by 2 or 3. ___________
(iv) all strings matching the regular expression (aa|b)*+(bb|a)*.____
(v) all strings not matching the regular expression (*)*_________
Q142. Consider the following DFA D over the alphabet = {a, b, c}:
The number of states in the equivalent minimized DFA will be? ____________
The number of states in the equivalent minimized DFA will be? ___________
Answer: 3
Solution: We will apply minimization algorithm:
𝜋0 = 𝑞𝜆 , 𝑞0 , 𝑞1 , 𝑞00 , 𝑞01 , 𝑞10 , 𝑞11 .
𝜋1 = 𝑞𝜆 , 𝑞0 , 𝑞00 , 𝑞10 , {𝑞01 ,𝑞1 } 𝑞11 .
𝜋2 = 𝑞𝜆 , 𝑞0 , 𝑞00 , 𝑞10 , {𝑞01 ,𝑞1 } 𝑞11 .
𝜋3 = 𝑞𝜆 , 𝑞0 , 𝑞00 , 𝑞10 , {𝑞01 ,𝑞1 } 𝑞11 .
So, minimized DFA contains 3 states.
The number of states in the equivalent minimized DFA will be? _________
a b
𝑞0 𝑞1 𝑞2
𝑞2 𝑞2 𝑞2 𝑞3
𝑞1 𝑞1 𝑞3 𝑞1
NFA
a b c
→𝑞0 𝑞1- 𝑞2 -
𝑞- 1 - 𝑞1
𝑞- 2 - 𝑞2
Q151. Minimum numbers of states required to construct the equivalent DFA of the following
NDFA? __________
Solution:
Now 𝑞1 also become final, because 𝑞𝐹 is final and definition said that if any state of
closure contain final state that 𝑞1 is also become final.
NFA:
Answer is 1
Q152. S Supposewe apply minimization to the following DFA over {a, b}:
So answer is C
Q153. Suppose that there are two DFA's D1 and D2. DFA D1 has 7 states out of which 3
states are final states. DFA D2 has 6 states out of which 4 states are final states. In the
product DFA for the intersection of their languages, maximum how many final states
Will be there?
(A) 12 (B) 9
(C) 3 (D) 1
Solution: In product automata of two DFA.
Maximum number state is final = number of state final in Ist DFA* number of state final
in IInd DFA = 3*4 = 12 and maximum number of state occurred, when all state make pair
with each other.
Answer: A
Q155. Suppose we have a DFA D = (Q, Σ, δ, q0, F) and know that D accepts every string.
What can we infer about D?
(A) Every state in D is a final state.
(B) There is at least 1 state in D that is not final.
(C) Every reachable state from q0 in D is a final state.
(D) There is only 1 character in the alphabet.
Answer is B
Q159. Which of the following languages over Σ = {a, b} is/are not regular?
(i) {ambn|m, n N};
(ii) {ambn |m n};
(iii) { ambn| m + n 4};
(iv) {w*|wL}; where L is some given language which is regular.
(v) {w*|wL}; where L is some given language which is not regular.
(A) i and iii only (B) i, iii and iv only
(C) ii and v only (D) ii, iv and v only
Solution: (i) is regular { ambn |m,n N}
a*b* (Regular expression for it)
ii. { ambn |mn}
for this we can‟t design DFA ,NFA for it .
So it is not regular.
iii. { ambn |m+n4}
So (i) is regular
(iii) also regular.
L3= { w1w2 |w1{a}* and w2 {b}* }
It is regular , it said that
(v) It is regular number of a‟s = number of b‟s , and that is no more than 128 . so it is
finite.
Answer is A
Solution:
Regular expression for it
(0+1)+00(0+1)+
(0+1)+11(0+1)+
so this language is regular.
So L1 is regular language.
L2: is non- regular.
because by NDFA/DFA, we can not ensure that |u||v|.
So L2 is not regular.
L3:- It is not regular.
wwR v {Here we can not ensure that first w, than reverse of w, than other string .
Answer: A
Q194. Let L1 and L2 are two languages over and it is given that L1.L2 is non-regular
languages. Then which of the following statement is not always true?
(A) 𝐿1 is not regular.
(B) L1 ∪ 𝐿1 is regular.
(C) L1, L2 ⊆ Σ*
(D) L1∪L2 contain infinitely many strings.
Answer: - (A)𝐿1 is not regular.
BASIC THEORY OF COMPUTATION Page 184
Solution:
(a) It is not always true.
L1.L2 =non-regular
(a*b*).{anbn| n>=0}= Non regular
a∗ b ∗ = Regular (its complement is regular).
So, option (a) is not always true.
(b) L1L1 is always regular.
If L1= anbn then L1L1 = anbnan b n = (a+b)*
So, it is always regular.
(c) It is true ; because every language is subset of *.
(d)If L1L2 contain infinite string is always true. Because L1.L2 = non-regular so at least
one language is infinite.
Answer: A
Q195. Let L= 01* + 10*. Which of the following is regular expression of LR (reverse of L)?
(A)0*1 + 1*0 (B) 1*0 + 01*
(C) 1*0 + 0*1 (D) (10)* + (01)*
Answer: - (C) 1*0 + 0*1
Solution:
L= 01* + 10*
LR = 1*0+0*1 = 0*1 + 1*0
Answer: C
Q196. The set of non-regular languages is closed under which of the following operations?
(A) Complement (B) Union
(C) Intersection (D) Concatenation
Answer: - (A) Complement
Solution:
(a) Non- regular language is closed under complement, because complement of non-
regular is always non-regular.
(b) {ambn | m n} {ambn |n m} = a*b*
So, union of two non-regular languages may be regular. Sometimes it may not be
regular.
Q197. Let L1 = {anbncm | n, m>=0} and L2 = {anbmcm | n, m>=0} then what is𝐿1𝐿2 ?
(A) L1U 𝐿2 (B)* - {anbncn | n>=0}
(C) {anbncn | n>=0} (D) a*b*c*
Answer: - none
Solution:
L1 = {anbncm|n, m>=0 } = {abc, aabbc….}and L2= {anbmcm|n, m>=0 {abc, abbcc}
Q198. The right quotient of a language L1 with respect to L2 is defined as L1/L2 = {x: yL2,
xyL1} Let L1 = L(a*ba+) and L2 = {aba*} then what will be the L1/L2?
(A)a* (B)a+
(C)a*b (D)a+b
Q200. Let L1 = {a, ab, c, d, λ}, L2 = {d} and L3 = L1.L2. Which string is not in L3?
(A) a (B)abd
(C) cd (D) d
Which of the following grammar generates the language accepted by NFA given above?
(A) S →1S/0A, A→1A/0B/0C, B→0C, C→1B/0C
(B) S →1S/0A, A→1A/0B, B→0C/, C→1B/0C
(C) S →1S/0A, A→1A/0B/0C, B→0C/, C→1B/0C/
(D) S →1S/0A, A→1A/0B/0C, B→0C/, C→1B/0C
Which of the following is a left linear grammar for the language accepted by M?
(A) S 1S0|
(B) S 10S|
(C) S 1A|, A0S
(D)S A0| , AS1
Answer :-C
For next three questions suppose h is the homomorphism from {0,1,2} to {a,b} defined by
h(0) = a; h(1) = ab; h(2) = ba.
Q217. What is h(21120)
(A) baababbaa (B) bababbaa
(C) bbaababbaa (D) abaababbaa
Q222. [MSQ]
Consider the language L = {aibj | j < i}. Which of the following string can be used in
a pumping lemma proof that L is not regular? [Assume n is pumping length]
(A) anbn (B) a2nbn (C) a2n+1b2n (D) (ab)na
Answer: B, C
Solution: Pumping lemma: For any regular language L, there exists an integer n, such
that for all x ∈ L with |x| ≥ n, there exists u, v, w ∈ Σ∗, such that x = uvw, and
(1) |uv| ≤ n
(2) |v| ≥ 1
(3) for all i ≥ 0: uviw ∈ L
Options (A) and (D) are not correct because both strings don‟t belong to L.
Option (B): Given string x= a2nbn
Case I: If u = 𝜆, v = an, w = anbn then uviw L for i =0.
Case II: If 𝑢 = 𝑎𝑛−𝑘 , 𝑣 = 𝑎𝑘 𝑘 ≥ 1 , 𝑤 = 𝑎𝑛 𝑏𝑛 𝑡ℎ𝑒𝑛 𝑢𝑣 𝑖 𝑤 𝐿; 𝑓𝑜𝑟 𝑖 = 0, 𝑛 = 1, 𝑘 = 1
So, this is correct string to proof L is non-regular.
Option C: Given string 𝑥 = 𝑎2𝑛+1 𝑏𝑛
Case I: If 𝑢 = 𝜆, 𝑣 = 𝑎𝑛 , 𝑤 = 𝑎𝑛+1 𝑏𝑛 𝑡ℎ𝑒𝑛 𝑢𝑣 𝑖 𝑤 𝐿 𝑓𝑜𝑟 𝑎𝑙𝑙 𝑖 = 0
Case II: If 𝑢 = 𝑎𝑛−𝑘 , 𝑣 = 𝑎𝑘 (𝑘 ≥ 1), 𝑤 = 𝑎𝑛+1 𝑏𝑛 , 𝑡ℎ𝑒𝑛 𝑢𝑣 𝑖 𝑤 𝐿 𝑓𝑜𝑟 𝑎𝑙𝑙 𝑖 = 0
So, this is incorrect string to proof L is non-regular.
So, option (B)& (C)are correct.
Q226. Let L be the regular language (11)*0*1* and L' = {(11)n10m1m | n, m>= 0}. Then L L' is
(A) regular by closure under union
(B) not regular because it contains 0m1m
(C) regular because you can always pump by setting v to be the leading 1 or 11
(D) not regular because L' is not regular, because 10p1p cannot be pumped in L'
Answer : D