Skip to content
Official PYQ · 2006

GATE CS 2006 Q84 — Parsing (LL, LR)

Explain with AI

Which one of the following grammars generates the language L={aibj∣i≠j}L=\left \{ a^{i}b^{j}\mid i\neq j \right \}?

Choose one option
View worked solution

Answer: D

The given language is L={aibj∣i≠j}L = \{ a^i b^j \mid i \neq j \}. This language can be partitioned into two disjoint cases:

  1. Case 1 (i>ji > j): More aa's than bb's. This can be written as am(akbk)a^m (a^k b^k) where m≥1m \ge 1 and k≥0k \ge 0.
  2. Case 2 (i<ji < j): More bb's than aa's. This can be written as (akbk)bn(a^k b^k) b^n where n≥1n \ge 1 and k≥0k \ge 0.

Let us analyze the grammar in Option D:

  • C→aCb∣εC \rightarrow aCb \mid \varepsilon generates equal number of aa's and bb's: L(C)={akbk∣k≥0}L(C) = \{a^k b^k \mid k \ge 0\}.
  • A→aA∣aA \rightarrow aA \mid a generates one or more aa's: L(A)=a+={am∣m≥1}L(A) = a^+ = \{a^m \mid m \ge 1\}.
  • B→Bb∣bB \rightarrow Bb \mid b generates one or more bb's: L(B)=b+={bn∣n≥1}L(B) = b^+ = \{b^n \mid n \ge 1\}.

Using these, the start symbol S→AC∣CBS \rightarrow AC \mid CB generates:

  • AC⇒amakbk=am+kbkAC \Rightarrow a^m a^k b^k = a^{m+k} b^k (where m+k>km+k > k, representing i>ji > j).
  • CB⇒akbkbn=akbk+nCB \Rightarrow a^k b^k b^n = a^k b^{k+n} (where k+n>kk+n > k, representing i<ji < j).

Thus, Option D correctly generates the language LL.

Why other options are incorrect:
Options A, B, and C can all generate the string abab (where i=j=1i = j = 1), which is not in LL. For example, in Option C: S→AC→εC→aCb→abS \rightarrow AC \rightarrow \varepsilon C \rightarrow aCb \rightarrow ab.

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

Published
Report a correction
Keep exploringMore Parsing (LL, LR) questions