Context Free Grammar: GATE CS Previous Year Questions

Context Free Grammar · Theory of Computation

33 questions · asked in 12 of 27 years (2000–2026)

MCQ 26 · MSQ 5 · NAT 21-mark 15 · 2-mark 18

2000Questions per year2026

Questions 21–25 of 33

Q21GATE 20082 marksMCQ−0.67 if wrong
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 terminals.

S→aS∣AA→aAb∣bAa∣ϵ\begin{array}{l} S \rightarrow a S \mid A \\ A \rightarrow a A b|b A a| \epsilon \end{array}

For the string "aabbaab" how many steps are required to derive the string and how many parse trees are there?

Q22GATE 20082 marksMCQ−0.67 if wrong
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 terminals.

S→aS∣AA→aAb∣bAa∣ϵ\begin{array}{l} S \rightarrow a S \mid A \\ A \rightarrow a A b|b A a| \epsilon \end{array}

Which of the following strings is generated by the grammar above?

Q23GATE 20082 marksMCQ−0.67 if wrong
Consider a CFG with the following productions.

S→AA∣BS \to AA \mid B
A→0A∣A0∣1A \to 0A \mid A0 \mid 1
B→0B00∣1B \to 0B00 \mid 1

S is the start symbol, A and B are non-terminals and 0 and 1 are the terminals. The language generated by this grammar is:

Q24GATE 20082 marksMCQ−0.67 if wrong
Which of the following statements are true?

I. Every left-recursive grammar can be converted to a right-recursive grammar and vice-versa

II. All ε\varepsilon-productions can be removed from any context-free grammar by suitable transformations

III. The language generated by a context-free grammar all of whose productions are of the form x →\rightarrow w or x →\rightarrow wY (where, w is a string of terminals and Y is a non-terminal), is always regular

IV. The derivation trees of strings generated by a context-free grammar in Chomsky Normal Form are always binary trees

Q25GATE 20061 markMCQ−0.33 if wrong
In the context-free grammar below, S is the start symbol, a and b are terminals, and ϵ\epsilon denotes the empty string.
S→aSAb∣ϵS \to aSAb \mid \epsilon
A→bA∣ϵA \to bA \mid \epsilon
The grammar generates the language

Keep practising

Topics in Theory of Computation

All CS topics ›