GATE Computer ScienceVery hardGATE CS (PYQ pattern)

The grammar S → aSBC | aBC; CB → BC; aB → ab; bB → bb; bC → bc; cC → cc generates { aⁿbⁿcⁿ : n ≥ 1 }. How many derivation steps does EVERY derivation of aaabbbccc take?

  1. A. 9
  2. B. 15
  3. C. 12
  4. D. 11

Correct answer: C. 12

Any derivation uses S → aSBC twice and S → aBC once (3 steps), giving aaaBCBCBC. Each CB → BC removes exactly one C-before-B inversion, and BCBCBC has 2 + 1 = 3 such pairs (3 steps). Then each of the 6 variables is turned into a terminal by exactly one rule (6 steps). Total 12.

More Theory of Computation questions

Exams that ask this topic