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

Answer: A. Generates an equal number of a’s and b’sThe 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…

  1. A.

    Generates an equal number of a’s and b’s

  2. B.

    Generates an inherently ambiguous language

  3. C.

    Generates more a’s than b’s

  4. D.

    Generates an unequal number of a’s and b’s

Attempted by 229 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.

Explore the full course: Mppsc Assistant Professor Computer Science Paper 2

Loading lesson…