Question

Identify the language generated by the following grammar, where SS is the start variable.

S→XYX→aX∣aY→aYb∣ϵ\begin{aligned} S &\to XY \\ X &\to aX \mid a \\ Y &\to aYb \mid \epsilon \end{aligned}
Choose one option
Official answer and solution
Official answer
C
From
Official GATE 2017 answer key

Solution

Find the language generated by each non-terminal and concatenate their languages.

Analyze the production rules of the grammar:

  1. Non-terminal XX has productions X→aX∣aX \to aX \mid a. This generates the regular language a+a^+ (i.e., aka^k with k≥1k \ge 1).
  2. Non-terminal YY has productions Y→aYb∣ϵY \to aYb \mid \epsilon. This generates equal numbers of aa's and bb's: {anbn∣n≥0}\{a^n b^n \mid n \ge 0\}.
  3. The start production is S→XYS \to XY. Therefore, any string generated by SS is of the form:
w=ak⋅anbn=ak+nbnwhere k≥1,n≥0w = a^k \cdot a^n b^n = a^{k+n} b^n \quad \text{where } k \ge 1, n \ge 0

Let m=k+nm = k + n. Since k≥1k \ge 1 and n≥0n \ge 0, we have m≥n+1m \ge n + 1, which is equivalent to m>nm > n, with n≥0n \ge 0.

Thus, the generated language is {ambn∣m>n,n≥0}\{a^m b^n \mid m > n, n \ge 0\}, which matches option C.

Final answer

C

Common trap

Overlooking that Y→ϵY \to \epsilon allows n=0n = 0, which yields strings like a1,a2,…a^1, a^2, \dots where n=0n = 0.

The answer is the one in the official GATE answer key. The solution is this site's own explanation.

Source

Paper
GATE 2017 Computer Science and Information Technology (CS) Session 2
Question
16 of 65, printed as CS Q.16
Section
Computer Science and Information Technology

Report an error in this question

GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.