The grammar S → aB / bA A → a / aS / bAA B → b / bS / aBB
2012
The grammar
S → aB / bA
A → a / aS / bAA
B → b / bS / aBB
- A.
Generates an equal number of a’s and b’s
- B.
Generates an inherently ambiguous language
- C.
Generates more a’s than b’s
- D.
Generates an unequal number of a’s and b’s
Attempted by 110 students.
Show answer & explanation
Correct answer: A
The grammar ensures balanced terminals. S produces equal a's and b's by combining A (one extra a) with B (one extra b). Base cases A→a and B→b establish the offset, while recursive rules maintain equality.
A video solution is available for this question — log in and enroll to watch it.