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 1–5 of 33

Q1GATE 2026 (Session 1)1 markMSQ
Consider the following grammar where SS is the start symbol, and aa and bb are terminal symbols.

S→aSbS | bS | ϵS \rightarrow a S b S \text { | } b S \text { | } \epsilon

Which of the following statements is/are true?

One or more options are correct.

Q2GATE 2026 (Session 1)2 marksMSQ
Consider the following context-free grammar GG.

S→abaABAbbaA→aaBBAb∣bBabaaB→aBb∣ab\begin{array}{l} S \rightarrow a b a A B A b b a \\ A \rightarrow a a B B A b \mid b B a b a a \\ B \rightarrow a B b \mid a b \end{array}

In the above grammar, SS is the start symbol, aa and bb are terminal symbols, and AA and BB are non-terminal symbols.

Let L(G)L(G) be the language generated by the grammar GG. For a string s∈L(G)s \in L(G), let n1(s)n_{1}(s) be the number of aa 's in ss and n2(s)n_{2}(s) be the number of bb 's in ss.

Which of the following statements is/are true?

One or more options are correct.

Q3GATE 2026 (Session 2)2 marksMSQ
Let Σ={a,b,c,d}\Sigma=\{a, b, c, d\} and let L={aibjckdℓ∣i,j,k,ℓ≥0}L=\left\{a^{i} b^{j} c^{k} d^{\ell} \mid i, j, k, \ell \geq 0\right\}.

Which of the following constraints ensure(s) that the language LL is context-free?

One or more options are correct.

Q4GATE 2025 (Session 2)2 marksMCQ−0.67 if wrong
Given a Context-Free Grammar GG as follows:

S→Aa∣bAc∣dc∣bdaS \to A a \mid b A c \mid d c \mid b d a
A→dA \to d

Which ONE of the following statements is TRUE?

Q5GATE 2025 (Session 2)2 marksMSQ
Consider two grammars G1G1 and G2G2 with the production rules given below:

G1:S→ifE then S∣ifE then S else S∣aG1: S \to \text{if} E \text{ then } S \mid \text{if} E \text{ then } S \text{ else } S \mid a
E→bE \to b

G2:S→ifE then S∣MG2: S \to \text{if} E \text{ then } S \mid M
M→ifE then M else S∣cM \to \text{if} E \text{ then } M \text{ else } S \mid c
E→bE \to b

where if,then,else,a,b,cif,then,else,a,b,c are the terminals.

Which of the following option(s) is/are CORRECT?

One or more options are correct.

Keep practising

Topics in Theory of Computation

All CS topics ›