GATE / CS ARCHIVE

GATE CSE 2006 / QUESTION 32

Ambiguous grammar for a regular language

Theory of Computation · Context-Free Grammars & Languages · Full GATE CSE 2006 paper

GATE 2006, Q32 2 marks · MCQ
Report issue

Context-Free Grammars & Languages

Question 32, GATE 2006: Grammar G has productions S→SS | ab | ba | ε. Consider I: G is ambiguous; II: G generates every string with equal counts of a and b; III: the language of G can be accepted by a deterministic PDA. Which statements are true?
Options:
(A) I only
(B) I and III only
(C) II and III only
(D) I, II and III
Tap to enlarge
Your answer
Answer & solution

Answer: B (no official key was published)

1. The grammar generates exactly(ab+ba)*: SS concatenates its two-letter blocks and ε contributes nothing. It is ambiguous, for example ab has both S→ab and S→SS→abS→ab, with different parse trees.

2. It does not generate aabb, although that string has equal a/b counts. The generated language is regular and therefore accepted by a deterministic PDA (even a DFA).

3. Statements1 and 3 hold, B; the PDA accepts the language, not the grammar object.

4. Teaching check: Equal counts are necessary for this grammar but not sufficient: concatenating ab and ba blocks cannot produce aabb. The ε production together with S→SS also allows redundant decompositions, so even a very short generated word has multiple parse trees.

Original paper, page 4