Question
Consider the following context-free grammar over the alphabet with as the start symbol:
Which one of the following represents the language generated by the above grammar?
Official answer and solution
- Official answer
- B
- From
- Official GATE 2017 answer key
Solution
Derive strings from the start symbol to find the structural pattern of the generated language.
Consider the production rules for non-terminal :
Starting from , we have:
Thus, generates (any non-empty sequence of 's, i.e., with ).
Now consider the productions for :
- If we apply the base rule once (), we obtain:
- If we apply the recursive rule once and then the base rule ():
- Applying the recursive rule times followed by the base rule yields:
Each independently derives any string in , so each is chosen independently.
Thus, the generated language is:
Notice that Option C requires all exponents of to be identical (), which is not true since each derives independently. Hence, Option B is correct.
B
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2017 Computer Science and Information Technology (CS) Session 1
- Question
- 10 of 65, printed as CS Q.10
- 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.