Question

Consider the following context-free grammar over the alphabet Σ={a,b,c}\Sigma = \{a, b, c\} with SS as the start symbol:

S→abScT∣abcTS \to abScT \mid abcT
T→bT∣bT \to bT \mid b

Which one of the following represents the language generated by the above grammar?

Choose one option
Official answer and solution
Official answer
B
From
Official GATE 2017 answer key

Solution

Derive strings from the start symbol SS to find the structural pattern of the generated language.

Consider the production rules for non-terminal TT:

T→bT∣bT \to bT \mid b

Starting from TT, we have:

T  ⟹  b,T  ⟹  bb,T  ⟹  bbb,…T \implies b, \quad T \implies bb, \quad T \implies bbb, \quad \dots

Thus, TT generates b+b^+ (any non-empty sequence of bb's, i.e., bmb^m with m≥1m \ge 1).

Now consider the productions for SS:

S→abScT∣abcTS \to abScT \mid abcT
  • If we apply the base rule S→abcTS \to abcT once (n=1n = 1), we obtain:
S  ⟹  abcT  ⟹  abcbm1(m1≥1)S \implies abcT \implies abcb^{m_1} \quad (m_1 \ge 1)
  • If we apply the recursive rule S→abScTS \to abScT once and then the base rule (n=2n = 2):
S  ⟹  abScT2  ⟹  ab(abcT1)cT2=(ab)2cT1cT2  ⟹  (ab)2cbm1cbm2(m1,m2≥1)S \implies ab S c T_2 \implies ab (abc T_1) c T_2 = (ab)^2 c T_1 c T_2 \implies (ab)^2 c b^{m_1} c b^{m_2} \quad (m_1, m_2 \ge 1)
  • Applying the recursive rule n−1n - 1 times followed by the base rule yields:
S  ⟹  (ab)n−1S(cT)n−1  ⟹  (ab)ncT1cT2…cTnS \implies (ab)^{n-1} S (c T)^{n-1} \implies (ab)^n c T_1 c T_2 \dots c T_n

Each TiT_i independently derives any string in b+b^+, so each mi≥1m_i \ge 1 is chosen independently.

Thus, the generated language is:

{(ab)ncbm1cbm2…cbmn∣n,m1,m2,…,mn≥1}\{(ab)^n c b^{m_1} c b^{m_2} \dots c b^{m_n} \mid n, m_1, m_2, \dots, m_n \ge 1\}

Notice that Option C requires all exponents of bb to be identical (mm), which is not true since each TiT_i derives independently. Hence, Option B is correct.

Final answer

B

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 1
Question
10 of 65, printed as CS Q.10
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.