Which of the following languages are context-free?
View worked solution
Answer: B
To determine which of the given languages are context-free, we analyze each language individually:
1. Language
In , the comparisons are nested (LIFO structure):
- The inner 's are matched with the inner 's ( with ).
- The outer 's are matched with the outer 's ( with ).
We can easily design a Pushdown Automaton (PDA) using a single stack: push 's, push 's, pop 's for the next set of 's, and then pop 's for the final set of 's.
Alternatively, we can write a Context-Free Grammar (CFG) for :
Since a CFG exists, is context-free.
2. Language
In , the comparisons are overlapping/cross-dependent (FIFO structure):
- The first block of 's must match the second block of 's ().
- The first block of 's must match the second block of 's ().
A single stack cannot maintain both of these independent, overlapping relationships simultaneously. Thus, is not context-free (it is a classic context-sensitive language).
3. Language
For , the number of 's is exactly twice the number of 's plus one. We can construct a CFG for this language as follows:
Since we can generate using a CFG, is context-free.
Thus, only and are context-free languages.
Free practice · Your answers on this page are not saved.
