1.
Number of trivial substrings in “GATE2013” are:
(a) 37
(b) 35
(c) 2
(d) 36
Solution: (c)
Explanation:
For any string, there will always be only 2 trivial substrings, ϵ and the given string itself. and
the given string itself.
2. Let the string be defined over symbols a and b then what will be the number of states in
minimal DFA, if every string starts and ends with different symbols?
(a) 5
(b) 4
(c) 3
(d) None
Solution: Option (a)
Explanation:
3. The total number of substrings present in “GATE” is:
(a) 7
(b) 10
(c) 11
(d) 8
Solution: Option (c)
Explanation:
L = {ε, G, A, T, E, GA, AT, TE, GAT, ATE, GATE}ε, G, A, T, E, GA, AT, TE, GAT, ATE, GATE}
Total number of substrings in a string of length n is
(n(n+1)/2) +1
4. Let Σ = {ε, G, A, T, E, GA, AT, TE, GAT, ATE, GATE}a, b}, what are the number of states in minimal DFA, length of every string
congruent to mod 5.
(a) 2
(b) 3
(c) 5
(d) None
Solution: Option (c)
5. A minimal DFA that is equivalent to a NDFA has:
(a) Always more states
(b) Exactly 2n states
(c) Always less no. of states
(d) Sometimes more states
Solution: Option (d)
Explanation:
Example which shows that number of states in NFA is greater than DFA.
Consider this NFA which accept (a+b)*.
Its corresponding minimal DFA is:
Hence number of states can be more in NFA
6. Consider following Regular Expression:
(i) a*b*b (a+ (ab)*)* b*
(ii) a*(ab + ba)* b*
What is length of shortest string which is in both (i) & (ii)?
(a) 2
(b) 3
(c) 4
(d) None
Solution: Option (d)
Explanation:
The shortest string is b generated by both the regular expressions.
7.
S→AB
A→BB| a
B→AB| b
Choose incorrect statement?
A. aabbb can be derived from above grammar
B. aabb can be derived from above grammar
C. ababab can be derived from above grammar
D. abbb can be derived from above grammar
Solution: Option (b)
Explanation:
The string “aabb” cannot be derived from the given grammar.
8. One of the following Regular Expressions is not the same as others. Which one?
(a) (a* + b*a*)*
(b) (a*b* + b*a*)* (a*b*)*
(c) ((ab)* + a*)*
(d) (a + b)* a*b*a*b*
Solution: Option (c)
Explanation:
abb cannot be generated by C, whereas it is generated by all other regular expressions.
Another method to approach this:
(a) (a*+ b*a*)* , assume a* is epsilon then it is equal to (a*+b*)* == (a+b)* // as this is
identity of regular expression.
(b) (a*b*+b*a*)*(a*b*)* // assume all highlighted one is epsilon so this is again equal to
(a+b)*
(d) (a+b)*a*b*a*b* // assume all highlighted one is epsilon so this is again equal to
(a+b)*
But (c) ((ab)*+a*)* here you cannot make it equal to (a+b)* hence this is odd one.
9. The complement of CFL:
(a) Recursive
(b) Recursive enumerated
(c) Not RE
(d) The empty set
Solution: Option (a)
Explanation:
CFL is not closed under complement means complement of a CFL may or may not be
CFL. Please don't assume that complement of CFL will never be CFL.
Hence If L is CFL then its complement L' may or may not be CFL.
As every CFL is CSL also, so we can assume CFL as CSL.
As CSL is closed under complement so complement of CSL must be CSL
Hence complement of CFL must be CSL in worst case.
As every CSL is recursive so complement of CFL is recursive also.
In options CSL is not given hence recursive is correct option.
10. The language of primes in unary is:
(a) Regular
(b) CFL
(c) DCFL
(d) Context Sensitive
Solution: Option (d)
Explanation:
The language of primes in unary is {ε, G, A, T, E, GA, AT, TE, GAT, ATE, GATE}1p | p is prime}. Finite automata cannot recognize this
language as it has no memory. PDA also cannot recognize this as there is no pattern in the
strings that can be remembered using one stack. LBA can accept this, so it is a context
sensitive language.
Solution: Option (a)
Explanation:
12. What are the number of states needed in minimal DFA, that accepts (1+1111)*, with 1 as
alphabet.
(a) 5
(b) 4
(c) 1
(d) None
Solution: Option (c)
Explanation:
The regular expression (1+1111)* generate strings {ϵ,1,11,111,1111,………}
Hence the language generated by regular expression is 1* and the minimal DFA require 1
state only.
13. Consider the grammar:
S → aSbS| bSaS| ε,
The smallest string for which the grammar has two derivation trees:
(a) abab
(b) aabb
(c) bbaa
(d) aaabbb
Solution: Option (a).
14. Consider the following languages:
L1 = {ε, G, A, T, E, GA, AT, TE, GAT, ATE, GATE}anbn (n ≥ 0)}
L2 = Complement (L1)
Choose appropriate options regarding languages L1 and L2
(a) L1 & L2 are context free
(b) L1 is CFL but L2 is RL
(c) L1 is CFL and L2 is CSL
(d) None
Solution: Option (a)
Explanation:
L1 and L2 both are CFL.
The complement means (a+b)*- L
So complement will have
{ε, G, A, T, E, GA, AT, TE, GAT, ATE, GATE}am bn | m≠n} ∪ {ε, G, A, T, E, GA, AT, TE, GAT, ATE, GATE}b(a+b)*} ∪ {ε, G, A, T, E, GA, AT, TE, GAT, ATE, GATE}(a+b)*a} U {ε, G, A, T, E, GA, AT, TE, GAT, ATE, GATE}(a+b)*b (a+b)* a(a+b)*}
15. The language L= {ε, G, A, T, E, GA, AT, TE, GAT, ATE, GATE}aN bN | 0 < N < 327th Prime number} is
(a) Regular
(b) Not context sensitive
(c) Not recursive
(d) None
Solution: Option (a)
Explanation:
Since this is finite language, it is regular.
16. Let Σ = {ε, G, A, T, E, GA, AT, TE, GAT, ATE, GATE}a}, assume language, L = {ε, G, A, T, E, GA, AT, TE, GAT, ATE, GATE}a2012.K | K > 0}, what is minimum number of states
needed in a DFA to recognize L?
(a) 22012 + 1
(b) 2013
(c) 22013
(d) None
Solution: Option (b)
Explanation:
17. The following CFG,
S→ aB| bA
A→ a| aS| bAA
B→ b| bS| aBB generates strings with
(a) Odd number of a's & odd number of b’s
(b) Even number of a's & even number of b's
(c) Equal number of a’s & b’s
(d) Odd number of a’s & even number of b’s
Solution: Option (c)
Explanation:
Grammar generates string: “aabb” hence (a) is wrong.
Grammar generates string: “ab” hence (b) is wrong.
Grammar generates string: “aabb” which has even number of “a” hence (d) is wrong.
18. What type of grammar is this most accurately described as?
S→ b| aD
D→ a| aDD
(a) A regular grammar
(b) CFG
(c) CSG
(d) Type-0
Solution: Option (b)
Explanation:
(a) This cannot be regular because regular grammars are of the form A → a, A → aB
(b) It is CFG because all the productions satisfy the constraints, they are of the form A → γ
where γ is a string of terminals and/or non-terminals.
(c) It can be CSG because all the productions are of the form αAβ → αγβ, where α, β, γ are Aβ → αAβ → αγβ, where α, β, γ are γβ, where αAβ → αγβ, where α, β, γ are , β, γ are
strings Aβ → αAβ → αγβ, where α, β, γ are Aβ → αAβ → αγβ, where α, β, γ are γβ, where αAβ → αγβ, where α, β, γ are , β, γ are stringsγβ, where αAβ → αγβ, where α, β, γ are Aβ → αAβ → αγβ, where α, β, γ are γβ, where αAβ → αγβ, where α, β, γ are , β, γ are
strings, β, γ are strings of terminals and/or non-terminals.
(d) It can be Type – 0 or unrestricted grammar, because all productions are of the form αAβ → αγβ, where α, β, γ are Aβ
→ αAβ → αγβ, where α, β, γ are γβ, where αAβ → αγβ, where α, β, γ are , β, γ are strings → β (no restrictions).
But it can be most accurately described as CFG.
19. Consider the following NFA M over the alphabet {ε, G, A, T, E, GA, AT, TE, GAT, ATE, GATE}0,1}.
Let M1 be the NFA obtained by interchanging final and non-final states of M. Let the
language accepted by M be L and that accepted by M1 be L1. Choose correct statement:
(a) L1 = L
(b) L1 ∩ L2 = Φ
(c) L1 ⊆ L2
(d) L1 = (0 + 1) *
Solution: Option (d)
Explanation:
By interchanging final and non-final states, we get L1 = (0 + 1) ∗.
The initial state is final state and it has self loop of 0 and 1, so it accepts (0+1)*
20. Let M = (Q, Σ, δ, S, F) and M’= (Q, Σ, δ, S, Q – F) where M accepts L and M’ accepts L1
and M is NFA, what could be the relation between L and L’ ?
(a) L and L’ are complement to each other
(b) L and L’ are similar to each other
(c) L and L’ relation cannot be predicted
(d) None of the above
Solution: Option (c)
Explanation:
M is an NFA where set F is final state and M' we have Q-F final state, means all the non-final
state in NFA M are final states in NFA, M'.
In other words this question says that if we complement an NFA (change all non-final states
into final states and vice versa) which accept language L, then do we get automata which
accept L' ?
The answer is no in NFA it’s not true while if M is DFA then it is true. The reason is NFA
don't have dead states so even though if we change all non-final states in NFA but the dead
state will be not present hence some string which is supposed to accept in L' will be missed.
If M is a DFA and if language accepted by DFA is L then if we make every non final state as
final state and every final state as non-final state then the DFA after modification will accept
L' (i.e. complement of L)
But M is an NFA and changing final state to non-final state and vice versa will not work here,
hence L and L' don't have any relation.
COMMON DATA QUESTIONS: Q.21, Q.22 AND Q.23, Q.24
21.
The DFA above accepts:
(a) The set of all strings containing two consecutive 1’s
(b) (0+1)*
(c) Set of all strings not containing two consecutive 1’s
(d) Set of all strings containing two consecutive 0’s
Solution: Option (b)
22. The minimal DFA of the above machine has:
(a) 1 State
(b) 5 States
(c) 3 States
(d) 2 States
Solution: Option (a)
Explanation:
The minimal DFA for (0+1)* has 1 state which is given below:
23. Consider the grammar given below where the flowers are non-terminals and animals are
terminals:
X → XX| aX| bX| ϵ
where a represents tiger and b represents lion, X represents Flowers. The grammar generates
(a) twice as many tigers as lions
(b) any number of tigers and lions
(c) more tigers than lions
(d) unequal number of tigers and lions
Solution: Option (b)
Explanation:
X-> XX | aX | bX | ϵ
It generates language (a+b)*
Here "a" is tiger and "b" represents lion
As we can see that any number of a's and b's are generated hence the option B "any
number of tigers and lions" is the correct answer.
24. The string for which the grammar has maximum of two derivation trees is:
(a) lion tiger lion
(b) lion tiger
(c) tiger lion
(d) None of the above
Solution: Option (d)
For all strings there are more than two derivation trees hence none of the above is
answer
For example: derivation trees for lion tiger lion equivalent string is "bab"