Consider the following grammar G:
Let and denote the number of a’s and b’s in a string respectively.
The language over generated by is
View worked solution
Answer: C
We can analyze the grammar by tracking how the number of 's, denoted by , changes during derivations. The grammar is right-linear, which can be modeled as a state transition diagram where , , and represent states, and -transitions do not change the state:
- From state , generating an transitions to state ().
- From state , generating an transitions to state ().
- From state , generating an transitions back to state () or terminates with an ().
Thus, the states track the number of 's modulo 3:
- State corresponds to .
- State corresponds to .
- State corresponds to .
A derivation can only terminate in one of two ways:
- Using , which occurs when the count of 's is a multiple of 3 ().
- Using , which adds one final to a state where , resulting in .
Since -productions (, , ) do not change the state, there is no restriction on the number of 's. Thus, the language generated is .
Free practice · Your answers on this page are not saved.
