Skip to content
Official PYQ · 2023

GATE CS 2023 Q29 — Context-free Grammars and Push-down Automata

Explain with AI

Consider the context-free grammar GG below
S→aSb∣XX→aX∣Xb∣a∣b,\begin{array}{l} S \rightarrow a S b \mid X \\ X \rightarrow a X \mid X b \mid a \mid b, \end{array}
where SS and XX are non-terminals, and aa and bb are terminal symbols. The starting non-terminal is SS.

Which one of the following statements is CORRECT?\text{CORRECT}?

Choose one option
View worked solution

Answer: B

To find the language generated by the grammar GG, we analyze the non-terminals step-by-step.

Step 1: Analyze the language generated by XX
The production rules for XX are: X→aX∣Xb∣a∣bX \rightarrow a X \mid X b \mid a \mid b Any derivation from XX must terminate with either aa or bb. We can prepend any number of aa's and append any number of bb's. Thus, XX generates all strings of the form aibja^i b^j where i+j≥1i + j \ge 1 (i.e., at least one terminal is present, and all aa's precede all bb's). L(X)=a∗(a+b)b∗L(X) = a^* (a+b) b^*

Step 2: Analyze the language generated by SS
The production rules for SS are: S→aSb∣XS \rightarrow a S b \mid X This means SS wraps strings from L(X)L(X) with an equal number of aa's on the left and bb's on the right: L(G)={akwbk∣w∈L(X),k≥0}L(G) = \{ a^k w b^k \mid w \in L(X), k \ge 0 \} Substituting w=aibjw = a^i b^j (where i+j≥1i+j \ge 1): akwbk=akaibjbk=ak+ibj+ka^k w b^k = a^k a^i b^j b^k = a^{k+i} b^{j+k} Let m=k+im = k+i and n=j+kn = j+k. Since i+j≥1i+j \ge 1 and k≥0k \ge 0, we have m+n≥1m+n \ge 1. Conversely, for any m,n≥0m, n \ge 0 with m+n≥1m+n \ge 1, we can simply choose k=0k = 0, which yields i=mi = m and j=nj = n (where i+j≥1i+j \ge 1). Thus, all such strings are generated: L(G)={ambn∣m+n≥1}=a∗(a+b)b∗L(G) = \{ a^m b^n \mid m+n \ge 1 \} = a^* (a+b) b^*

Since this language is regular and matches option B, the correct statement is B.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Context-free Grammars and Push-down Automata questions