Question
Consider the following languages:
I.
II.
III.
IV.
Which of the languages above are context-free?
Official answer and solution
- Official answer
- B
- From
- Official GATE 2018 answer key
Solution
Test each language using pushdown automaton mechanics and closure properties.
Evaluate each language:
- I. : Rewrite as . A PDA can push 's onto the stack, pop an for each (or push 's if ), then push 's (or cancel 's), and finally match with 's. Since a single stack suffices to verify the balance condition across the entire string, language I is context-free.
- II. : This language is the concatenation of two independent CFLs: and . Since CFLs are closed under concatenation, language II is context-free.
- III. : Requiring three independent counts to be equal () cannot be checked by a pushdown automaton (analogous to the classic non-CFL ). Language III is not context-free.
- IV. : Involves multiplication of counts, which cannot be recognized by any pushdown automaton. Language IV is not context-free.
Hence, only I and II are context-free, matching option B.
Final answer
B
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2018 Computer Science and Information Technology (CS)
- Question
- 45 of 65, printed as CS Q.35
- 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.