Consider the following languages:
Which of the above languages are context-free?
View worked solution
Answer: B
To determine which of the given languages are context-free, we analyze each one individually:
- Language I:
The condition can be rewritten as . We can track this relation using a single stack (PDA):
- Push for each , pop for each . If the stack becomes empty and more 's arrive, push a placeholder for excess 's.
- Push for each (or pop if excess 's are on the stack).
- Pop for each .
Since a single stack is sufficient to verify the net difference, is context-free.
- Language II:
This language can be written as the concatenation of two context-free languages:
Since context-free languages are closed under concatenation, is context-free.
- Language III:
This requires matching three independent variables simultaneously (), which is a classic non-context-free structure (similar to ). Thus, is not context-free.
- Language IV:
The constraint involves multiplication of independent variables (), which cannot be tracked by a pushdown automaton. Thus, is not context-free.
Therefore, only languages I and II are context-free.
Free practice · Your answers on this page are not saved.
