Consider the following languages:
Which one of the following is TRUE?
View worked solution
Answer: B
To determine which of the languages are context-free, we analyze each one individually:
1. Analysis of
We can rewrite the condition for the number of 's as . Since the 's appear first, followed by 's, and then 's, we can match the 's with the 's first, and then with the 's.
PDA Intuition (LIFO Stack):
- Push all 's onto the stack.
- Push all 's onto the stack.
- For each incoming , pop a symbol from the stack. The first 's will pop the 's, and the subsequent 's will pop the 's.
- If the stack becomes empty precisely when the input is fully consumed, the string is accepted.
Since this can be processed using a single stack, is a Context-Free Language (CFL).
Context-Free Grammar (CFG) for :
Here, generates and generates , resulting in . Thus, is context-free.
2. Analysis of
In , there are two independent comparisons that must be maintained simultaneously:
- The number of 's must equal the number of 's.
- The number of 's must be twice the number of 's (or 's).
A single stack cannot keep track of both comparisons. If we use the stack to match 's and 's, the stack becomes empty before we can verify the count of 's.
Using the Pumping Lemma for CFLs:
- Let be the pumping length. Choose the string .
- Any partition with and cannot contain all three symbols (, , and ).
- If contains only 's and 's, pumping it changes the counts of and but leaves the count of unchanged, violating the relation.
- If contains only 's and 's, pumping it changes the counts of and but leaves the count of unchanged, violating the relation.
Thus, is not context-free.
Therefore, is context-free while is not context-free.
Free practice · Your answers on this page are not saved.
