Skip to content
Official PYQ · 2019

GATE CS 2019 Q31 — Context-free Grammars and Push-down Automata

Explain with AI

Which one of the following languages over Σ={a,b}\Sigma=\{a, b\} is NOT context-free?

Choose one option
View worked solution

Answer: C

To determine which language is NOT context-free, let us analyze each option:

  • Option A: {wwR∣w∈{a,b}∗}\{ww^R \mid w \in \{a, b\}^*\} is a classic context-free language (even-length palindromes) generated by the CFG: S→aSa∣bSb∣ϵS \to aSa \mid bSb \mid \epsilon.
  • Option B: {wanbnwR∣w∈{a,b}∗,n≥0}\{wa^nb^nw^R \mid w \in \{a,b\}^*, n \geq 0\} has nested dependencies. The outer part w…wRw \dots w^R and the inner part anbna^n b^n can both be processed using a single stack in LIFO order. It is generated by the CFG: S→aSa∣bSb∣AS \to aSa \mid bSb \mid A A→aAb∣ϵA \to aAb \mid \epsilon Thus, it is context-free.
  • Option C: {wanwRbn∣w∈{a,b}∗,n≥0}\{wa^nw^Rb^n \mid w \in \{a,b\}^* , n \geq 0\} contains overlapping (cross-serial) dependencies. We must match ww with wRw^R, and ana^n with bnb^n. Since wRw^R appears before bnb^n, a single stack cannot maintain the count of ana^n while simultaneously matching ww with wRw^R. This requires two independent comparisons, which is beyond the capability of a Pushdown Automaton. Hence, this language is not context-free.
  • Option D: {anbi∣i∈{n,3n,5n},n≥0}\{ a^nb^i \mid i \in \{n, 3n, 5n\}, n \geq 0\} is the union of three context-free languages: {anbn}∪{anb3n}∪{anb5n}\{a^nb^n\} \cup \{a^nb^{3n}\} \cup \{a^nb^{5n}\}. Since context-free languages are closed under union, this language is context-free.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Context-free Grammars and Push-down Automata questions