Question
Which of the following languages are context-free?
Official answer and solution
- Official answer
- B
- From
- Official GATE 2015 answer key
Solution
Analyze each language using Pushdown Automata capabilities and the CFL pumping lemma.
- Language :
This exhibits nested (LIFO) matching:- Push copies of onto the stack.
- Push copies of onto the stack.
- Match and pop 's with the subsequent copies of .
- Match and pop 's with the final copies of .
A PDA can completely verify this using a single stack. Hence, is context-free.
- Language :
This has cross-serial dependencies (the first must match the second , and the first must match the second ). By the Pumping Lemma for Context-Free Languages, cannot be accepted by any PDA. Hence, is not context-free.
- Language :
Strings are of the form . For each , there are exactly two 's (plus one extra initial ). A PDA can push one symbol for every two 's (or push all 's and pop two for each ). Hence, is deterministic context-free.
Thus, and only are context-free (Option B).
Final answer
B
Common trap
Mistaking L1 for non-context-free due to four variable blocks, whereas its nested mirror structure matches the LIFO operation of a PDA stack.
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2015 Computer Science and Information Technology (CS) Session 3
- Question
- 42 of 65, printed as CS Q.32
- 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.