Question
Consider the following languages over the alphabet .
Let and .
Which of the following are context-free languages?
I.
II.
Official answer and solution
- Official answer
- A
- From
- Official GATE 2017 answer key
Solution
Apply context-free language closure properties under union and intersection.
We are given two languages over :
Both and are deterministic context-free languages (DCFLs):
- For , a pushdown automaton pushes 's, pops on matching 's, and accepts while reading any number of 's.
- For , a PDA skips 's, pushes 's, and pops on matching 's.
Statement I: . Context-free languages are closed under union. If is the start symbol for and for , a new start symbol with rule generates . Hence, is a context-free language.
Statement II: . The intersection requires both conditions to hold simultaneously:
It is a classic result that is not context-free (provable via the Pumping Lemma for CFLs). Hence, is not a context-free language.
Thus, only I is a context-free language.
A
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
- 38 of 65, printed as CS Q.38
- 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.