Consider the CFG with as the non-terminal alphabet, as the terminal alphabet, as the start symbol and the following set of production rules:
Which of the following strings is generated by the grammar?
View worked solution
Answer: C
By analyzing the production rules, we can determine the language generated by each non-terminal:
- generates strings with an equal number of 's and 's.
- generates strings with one more than 's.
- generates strings with one more than 's.
We can verify this property from the rules:
- : Since has one more than , prepending results in an equal number of 's and 's. Similarly, prepending to results in an equal number of 's and 's.
- : Each alternative guarantees exactly one more than .
- : Each alternative guarantees exactly one more than .
Now, let's count the number of 's and 's in each option:
- (A) : 's, 's (not equal)
- (B) : 's, 's (not equal)
- (C) : 's, 's (equal)
- (D) : 's, 's (not equal)
Thus, only option C can be generated by the grammar. The derivation for is:
Free practice · Your answers on this page are not saved.
