Sie sind auf Seite 1von 16

Consider the DFAs M and N given above.

The number of states in a minimal


DFA that accepts the language L(M) ∩ L(N) is __________

(A) 0
(B) 1
(C) 2 Explanation: In DFA M: all strings must end with ‘a’.
In DFA N: all strings must end with ‘b’.
(D) 3
So the intersection is empty.
For an empty language, only one state is required in DFA. The state is non-accepting
and remains on itself for all characters of alphabet.
The number of states in the minimum sized DFA that accepts the language
defined by the regular expression (0+1)*(0+1)(0+1)* is __________________

The minimum number of states is 2.


Which one of the following regular expressions represents the language: the set of all binary
strings having two consecutive 0s and two consecutive 1s?

Key: (B)
Exp: (a) contains 00 & 11 consecutively which is not the required condition.
(c) Doesn’t guaranty that both 00 & 11 will be present in the string.
(d) Says string should start with 11 & ends with 00 or vice versa.
Consider the following two statements:
I. If all states of an NFA are accepting states then the language accepted by
the NFA is Σ∗ .
II. There exists a regular language A such that for all languages B, A ∩ B is
regular.

Answer: (B)

Explanation:
Statement I : False, Since there is no mention of transition between states. There may be a case, where
between two states there is no transition defined.

Statement II: True, Since any empty language (i.e., A = Φ ) is regular and its intersection with any other
language is Φ. Thus A ∩ B is regular.
Consider the following languages: L1 = {anbmcn : m, n >= 1} L2 =
{anbnc2n : n >= 1} Which one of the following is TRUE?

L1 = {anbmcn |m, n ≥ 1} is context free language because it is derived by the following CFG: S− > aSc|aBc; B− > bB|b
L2 = {anbnc2n |n ≥ 1} is not a context free language, this can be proved using pumping lemma. Intuitively, a pushdown
automaton can’t remember number of as for the third set of characters coming, i.e. c. This language is very similar to
{anbncn |n ≥ 1} which is known to be a non-CFL. Hence, correct answer would be (B) L1 is context-free while L2 is not
context-free. L2 is not context free. no. of b's will match with no. of a's leaving c's to be matched with no one..so L2
cant be context free.
Which of the following languages is generated by the given grammar?
S → aS|bS| ε

Key: (D)
Exp: Given grammar generates all strings of a’s and b’s including null string
Hence L= (a+b)*
Consider the following context-free grammars:

Which one of the following pairs of languages is generated by G1 and G2, respectively

Answer: (D)
Explanation: In G1, there will be at least 1 b becase S->B and B->b. But no of A’s can be 0 as well and no
of A and B are independent.
In G2, either we can take S->aA or S->bB. So it must have atleast 1 a or 1 b.
So option D is correct.
Language L1 is defined by the grammar: S1 → aS1b|ε
Language L2 is defined by the grammar: S2 → abS2|ε
Consider the following statements:
P: L1 is regular
Q: L2 is regular

Which one of the following is TRUE?


(A) Both P and Q are true
(B) P is true and Q is false
(C) P is false and Q is true
(D) Both P and Q are false
Which one of the following grammars is free from left recursion?
Answer: (B)

Explanation: Grammar A has direct left recursion because of the production rule: A →Aa.
Grammar C has indirect left recursion because of the production rules:S→Aa and A→Sc
Grammar D has indirect left recursion because of production rules : A→Bd and B→ Ae
Grammar B doesn’t have any left recursion (neither direct nor indirect).
A student wrote two context-free grammars G1 and G2 for generating a single C-
like array declaration. The dimension of the array is at least one. For example,
int a[10][3];

The grammars use D as the start symbol, and use six terminal symbols int ; id [ ]
num.

Grammar G1
D → int L;
L → id [E Which of the grammars correctly generate the
E → num] declaration mentioned above?
E → num] [E (A) Both G1 and G2
(B) Only G1
Grammar G2 (C) Only G2
D → int L; (D) Neither G1 nor G2
L → id E
E → E[num]
E → [num] Answer : A
Consider the transition diagram of a PDA given below with input alphabet Σ = {a , b} and
stack alphabet Γ = {X , Z}. Z is the initial stack symbol. Let L denote the language
accepted by the PDA.

Answer: D
Answer: (D)

Das könnte Ihnen auch gefallen