GATE Computer ScienceVery hardGATE CS · ISRO

How many distinct strings of length at most 6 (including the empty string) are generated by the grammar S → ( S ) | S S | ε?

  1. A. 5
  2. B. 13
  3. C. 9
  4. D. 15

Correct answer: C. 9

The language is all balanced parenthesis strings; the counts by length 0, 2, 4, 6 are 1, 1, 2, 5, so 9.

More Compiler Design questions

Exams that ask this topic