Question
Consider the context-free grammars over the alphabet given below. and are non-terminals.
The language is
Official answer and solution
- Official answer
- B
- From
- Official GATE 2017 answer key
Solution
Find the languages generated by grammars and , compute their set intersection, and classify the resulting language.
Grammar has productions:
Here generates any string in , and each application of adds matched 's and 's. Thus:
Grammar has productions:
Similarly, generates , and each application of adds matched 's at the beginning and 's at the end. Thus:
Now consider the intersection :
- If , any string in starts with 'a'. But any string in with starts with 'b'.
- If , strings in are purely of the form .
- If , strings in are purely of the form .
Therefore, the only strings common to both languages are those with and :
The language is infinite and regular (recognized by a single-state DFA with a loop on ). Hence, the intersection is not finite but regular.
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
- 37 of 65, printed as CS Q.37
- 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.