GATE Computer ScienceHardGATE CS (PYQ pattern)
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 (that is, n_a − n_b ≤ 2 for every prefix)?
- A. 14
- B. 32
- C. 16
- D. 8
Correct answer: C. 16
The grammar generates Dyck words (a = up, b = down). Height ≤ 2: such a word is a sequence of blocks a·(ab)ᵏ·b, k ≥ 0, each of length 2k + 2. With 5 a-b pairs this is the number of compositions of 5 into positive parts, 2⁴ = 16.
More Theory of Computation questions
- 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
- The language generated by S → TT, T → aTb | ε is