Question

Which of the following languages are context-free?

L1={ambnanbm∣m,n≥1}L2={ambnambn∣m,n≥1}L3={ambn∣m=2n+1}\begin{aligned} L_1 & = \{a^m b^n a^n b^m \mid m, n \ge 1\} \\ L_2 & = \{a^m b^n a^m b^n \mid m, n \ge 1\} \\ L_3 & = \{a^m b^n \mid m = 2n + 1\} \end{aligned}
Choose one option
Official answer and solution
Official answer
B
From
Official GATE 2015 answer key

Solution

Analyze each language using Pushdown Automata capabilities and the CFL pumping lemma.

  1. Language L1={ambnanbm∣m,n≥1}L_1 = \{a^m b^n a^n b^m \mid m, n \ge 1\}:
    This exhibits nested (LIFO) matching:
    • Push mm copies of aa onto the stack.
    • Push nn copies of bb onto the stack.
    • Match and pop bb's with the subsequent nn copies of aa.
    • Match and pop aa's with the final mm copies of bb.
      A PDA can completely verify this using a single stack. Hence, L1L_1 is context-free.
  1. Language L2={ambnambn∣m,n≥1}L_2 = \{a^m b^n a^m b^n \mid m, n \ge 1\}:
    This has cross-serial dependencies (the first ama^m must match the second ama^m, and the first bnb^n must match the second bnb^n). By the Pumping Lemma for Context-Free Languages, L2L_2 cannot be accepted by any PDA. Hence, L2L_2 is not context-free.
  1. Language L3={ambn∣m=2n+1}L_3 = \{a^m b^n \mid m = 2n + 1\}:
    Strings are of the form a2n+1bna^{2n+1} b^n. For each bb, there are exactly two aa's (plus one extra initial aa). A PDA can push one symbol for every two aa's (or push all aa's and pop two for each bb). Hence, L3L_3 is deterministic context-free.

Thus, L1L_1 and L3L_3 only are context-free (Option B).

Final answer

B

Common trap

Mistaking L1 for non-context-free due to four variable blocks, whereas its nested mirror structure matches the LIFO operation of a PDA stack.

The answer is the one in the official GATE answer key. The solution is this site's own explanation.

Source

Paper
GATE 2015 Computer Science and Information Technology (CS) Session 3
Question
42 of 65, printed as CS Q.32
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.