Question
Consider the following context-free grammars:
Which one of the following pairs of languages is generated by and , respectively?
Official answer and solution
- Official answer
- D
- From
- Official GATE 2016 answer key
Solution
Determine the set of strings generated by each grammar by analyzing the production rules from the start symbol.
Analysis of grammar :
- : The non-terminal generates one or more 's, i.e., .
- : The start symbol generates zero or more 's followed by a derivation from . Thus, .
Analysis of grammar :
- : Non-terminal generates zero or more 's, i.e., .
- : generates zero or more 's followed by or , which simplifies to .
- :
- The branch generates , which is all strings of 's and 's with at least one ().
- The branch generates , which is all strings with only 's and at least one ().
- The union contains all strings of the form where at least one of or is strictly positive (). Note that the empty string cannot be generated by .
Comparing the languages:
This matches option D.
D
Overlooking that requires at least one , and requires at least one , so is not generated by .
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2016 Computer Science and Information Technology (CS) Session 1
- Question
- 52 of 65, printed as CS Q.42
- Section
- Computer Science and Information Technology
Report an error in this question
GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.