GATE Computer ScienceModerateGATE CS (PYQ pattern)
Which one of the following context-free grammars (start symbol S, terminals a, b) is ambiguous?
- A. S → aSbS | bSaS | ε
- B. S → aSbS | ε
- C. S → AB; A → aA | a; B → bB | b
- D. S → aSb | bSa | ε
Correct answer: A. S → aSbS | bSaS | ε
The string "abab" has 2 distinct parse trees under it. In each of the other grammars every string of length ≤ 8 has exactly one parse tree (and each is a standard unambiguous pattern).
More Theory of Computation questions
- For the grammar S → SS | SSS | a, how many distinct parse trees does the string aaaaa (five a's) have?
- For the grammar S → aS | Sb | aSb | c, how many distinct parse trees does the string aacbb have?
- For the grammar S → SaS | SS | b, how many distinct parse trees does the string bbabb have?
- For the grammar E → E + E | E E | a (no precedence or associativity rules), the string a+aa+aa has 14 parse trees. In how many of them is…
- For the grammar S → SS | aSb | ab, how many distinct parse trees does the string ababab have?
- The grammar S → aSb | bSa | SS | ε generates how many strings of length exactly 8?