GATE Computer ScienceHardGATE CS (PYQ pattern)
The grammar S → aSb | bSa | SS | ε generates how many strings of length exactly 8?
- A. 70
- B. 14
- C. 35
- D. 140
Correct answer: A. 70
Surprisingly it generates every string with equally many a's and b's, so the count is C(8,4) = 70. The Catalan number 14 would count only Dyck-type strings.
More Theory of Computation questions
- The grammar S → aSbS | ε generates 42 strings of length 10. In how many of them does no prefix contain more than two a's in excess of b's…
- For the grammar S → aSbb | aaSb | ε, how many distinct parse trees does a⁶b⁶ have?
- The language generated by S → aSb | aSbb | ε is
- The grammar S → aSb | Sb | b generates { aⁿbᵐ : m > n ≥ 0 }. How many distinct parse trees does the string aabbbb have?
- The language generated by S → aSb | bSa | SS | ε is
- The language generated by S → aSbS | ε is