Consider the following languages over the alphabet . Let and .
Which of the following are context-free languages?
View worked solution
Answer: A
To determine which of the given languages are context-free, let us analyze and individually:
- is a Context-Free Language (CFL). A Pushdown Automaton (PDA) can push 's onto the stack, pop them when reading 's to ensure their counts match, and then read any number of 's without modifying the stack.
- is also a CFL. A PDA can skip the initial 's, push 's onto the stack, and pop them when reading 's to ensure their counts match.
Now, let us evaluate the given statements:
Statement I:
Context-free languages are closed under union. Since both and are CFLs, their union is guaranteed to be a CFL.
Intuition: A non-deterministic PDA can make an initial -transition to either the PDA for or the PDA for .
Statement II:
Let us find the intersection of the two languages:
The language is a well-known non-context-free language (which can be formally proven using the Pumping Lemma for CFLs). A single stack cannot simultaneously keep track of two independent comparisons (matching 's with 's, and then matching 's with 's).
Therefore, only I is a context-free language.
Free practice · Your answers on this page are not saved.
