All mock tests are FREE till 31 December — register to save your progress
Paper 2 CS · UNIT 08 · MOCK TEST

Mock 4 – Context-Free Grammars & PDA (Part 1)

Unit 8: Theory of Computation and Compilers · 30 questions · about 36 minutes. Press End Mock any time to see your score and the correct answers.

All 10 topic-wise mocks in this unit
0 / 30 answered 00:00
Q1. Match the LIST-I with LIST-II.
LIST-I (Language)LIST-II (Type of Language)
A. L₁ = {aⁿbᵐ | n, m ≥ 0}I. Unrestricted
B. L₂ = {aⁿbᵐ | (n − m) ≥ 0}II. Context Sensitive
C. L₃ = {aⁿbⁿcⁿdⁿ | n ≥ 1}III. Regular
D. L₄ = {aⁿbᵐcᵐdⁿ | n, m ≥ 0}IV. Context Free
Choose the correct answer from the options given below:
Q2. Which of the following statements is incorrect?

Consider the following Context Free Grammar (G):

S → A B
B → + A B | ε
A → C D
D → * C D | ε
C → [ S ] | x

Variable = { S, A, B, C, D }

Terminals = { +, *, [, ], x }

Q3. Identify the correct statement from the following.

Consider the following Context Free Grammar (G):

S → A B
B → + A B | ε
A → C D
D → * C D | ε
C → [ S ] | x

Variable = { S, A, B, C, D }

Terminals = { +, *, [, ], x }

Q4. The I0 state of the canonical LR(0) set of the SLR(1) parser of this CFG has how many productions?
Q5. Which of the following Grammars is/are only Context Free (i.e. context-free but not regular grammars)?
GrammarProductions
AS → Ab
aS → aA
A → a
BS → Ab
A → Sa
A → a
CS → AS
S → aA
A → a
DS → Ab
S → aA
A → a
ES → Sb
A → Aa
A → ε
Q6. Which of the following CFG(s) is/are in Chomsky Normal Form? (All capital letters are variables & lower case letters are terminals)
A. S → ABC | AB, A → a, B → b, C → d
B. X → RT | TR, T → t, R → XT | r
C. P → qP | sQ, Q → r | s
D. M → MN | MP, N → nm | n, P → p
Choose the correct answer from the options given below:
Q7. Consider the grammar:
S → A
A → $B$ | id
B → B, A | A
If I₀ = CLOSURE({[S → ·A]}), then how many items will be in the set GOTO(I₀, $)?
Q8. Consider the grammar:
T → Qx
Q → RS
R → y | ε
S → z | ε
Here x, y, z are terminals and T, Q, R, S are non-terminals. What will be the FOLLOW set of the non-terminal R?
Q9. Which of the following properties correctly describe a Regular Grammar?
(A) All production rules are of the form A → xB or A → x, where A and B are non-terminal symbols and x is a terminal symbol.
(B) Regular grammars are more powerful than context-free grammars and can express any type of language.
(C) There is a direct correspondence between regular grammars and finite automata.
(D) Regular grammars can generate languages that are not recognised by any type of automata.
Choose the correct answer from the options given below:
Q10. Which of the following are context-free languages?
(A) {wⁱ xʲ yᵏ zˡ | i + k = j + l, where i, j, k, l ≥ 0}
(B) {wⁱ xʲ yᵏ zˡ | i = j, k = l, where i, j, k, l ≥ 0}
(C) {wⁱ xʲ yᵏ zˡ | i = j = k and k ≠ l, where i, j, k, l ≥ 0}
(D) {wⁱ xʲ yᵏ zˡ | i = j = k + l, where i, j, k, l ≥ 0}
(E) {wⁱ xʲ yᵏ zˡ | i = j = l and k ≠ l, where i, j, k, l ≥ 0}
Q11. The maximum yield length of the following CNF CFG is
S → AB
A → CD
B → e
C → a
D → b
Q12. Consider the language L = {w ∈ {a, b, c}* : nₐ(w) + n_b(w) = n_c(w)}. L is
Q13. Consider the following statements:
A. A context-free language is generated by an LR(0) grammar if and only if it is accepted by a deterministic pushdown automaton and has the prefix property.
B. If M1 is a single-tape TM simulating a multitape TM M, then the time taken by M1 to simulate n moves is O(n³).
C. A pushdown automaton behaves like a Turing machine when it has one auxiliary memory.
D. L = {aⁿbⁿcⁿ : n ≥ 1} is not context-free but is context-sensitive.
Choose the correct answer from the options given below:
Q14. An ambiguous grammar is one which has:
A. More than one derivation
B. More than one leftmost derivation
C. More than one rightmost derivation
D. More than one parse tree
E. More than one syntax tree
Choose the correct answer from the options given below:
Q15. The grammar
stmt → if expr then stmt else stmt | if expr then stmt
suffers from:
Q16. Consider the following statements:
A. For every regular language, we can design a Turing machine.
B. For every context-free language, we can design a Turing machine.
Which of the following is correct?
Q17. Which of the following is (are) correct about the regular expression a a* b b* c c* d d*?
1. The language for the given expression is L = {anbncmdm | n ≥ 1, m ≥ 1} ∪ {anbmcmdn | n ≥ 1, m ≥ 1}
2. The context-free grammar for the given expression is:
S → AB | C
A → aAb | ab
B → cBd | cd
C → aCd | aDd
D → bDc | bc
3. The language generated by this expression is an equal number of a's, followed by an equal number of b's, followed by an equal number of c's, followed by an equal number of d's.
Choose the correct answer from the options given below:
Q18. What is the safest order for simplifying a context-free grammar?
Q19. The reduced grammar equivalent to the grammar whose production rules are given below is
S → AB | CA
B → BC | AB
A → a
C → aB | b
Q20. Consider the production rules of grammar G:
S → AbB
A → aAb | λ
B → bB | λ
Which language L is generated by G?
Q21. Consider the grammar S → SbS | a and the string abababa. Consider the statements: the string has
(A) two parse trees
(B) two leftmost derivations
(C) two rightmost derivations
Which of the following is correct?
Q22. Consider the following statements about context-free languages (CFL):
Statement I: CFLs are closed under homomorphism.
Statement II: CFLs are closed under complement.
Which of the following is correct?
Q23.

Which of the following Grammars is/are only Context Free?

Figure
Q24.

Match List I with List II. List I: A. Type 3 Grammar, B. Type 2 Grammar, C. Type 1 Grammar, D. Type 0 Grammar. List II: I. V → (V ∪ Σ)*; II. λVβ → λ(V ∪ Σ)*β, where λ, β ∈ (V ∪ Σ)*; III. (V ∪ Σ)* → (V ∪ Σ)*; IV. V → VΣ | Σ

Q25.

Match List I with List II. List I: A. Type-0 grammar, B. Type-1 grammar, C. Type-2 grammar, D. Type-3 grammar. List II: I. Linear grammar; II. GNF; III. x → y, |x| ≤ |y|, x, y ∈ (V ∪ T)*; IV. Recursively enumerable.

Q26.

Consider the Grammar:

T → Qx

Q → RS

R → y ∣ ϵ

S → z ∣ ϵ Here x, y, z are terminals and T, Q, R, S are non- terminals. What will be the follow set of the non-terminal R?

Q27.

Which of the following is a context-free language? (A) {wⁱ xʲ yᵏ zˡ | i + k = j + l, i, j, k, l ≥ 0} (B) {wⁱ xʲ yᵏ zˡ | i = j, k = l} (C) {wⁱ xʲ yᵏ zˡ | i = j = k and k ≠ l} (D) {wⁱ xʲ yᵏ zˡ | i = j = k + l} (E) {wⁱ xʲ yᵏ zˡ | i = j = l and k ≠ l}

Q28.

Which of the following is -free grammar?

Q29.

The item generated by the production is :

Q30.

Which of the following is (are) correct? 1. The language for the given expression is L = {aⁿbⁿcᵐdᵐ | n ≥ 1, m ≥ 1} ∪ {aⁿbᵐcᵐdⁿ | n ≥ 1, m ≥ 1}. 2. A context-free grammar for it is S → AB | C, A → aAb | ab, B → cBd | cd, C → aCd | aDd, D → bDc | bc. 3. The language has equal numbers of a's, b's, c's and d's in that order.