Skip to content
Official PYQ · 2010

GATE CS 2010 Q40 — Context-free Grammars and Push-down Automata

Explain with AI

Consider the languages

L1={0i1j ∣i≠j},L1=\{0^i1^j\ \mid i \neq j\},

L2={0i1j∣i=j},L2=\{0^i1^j\mid i=j\},

L3={0i1j∣i=2j+1},L3=\{0^i1^j \mid i=2j+1\},

L4={0i1j∣i≠2j}L4=\{0^i1^j \mid i\neq2j\}

Choose one option
View worked solution

Answer: D

All four languages are context-free because we can construct either a Context-Free Grammar (CFG) or a Pushdown Automaton (PDA) for each of them:

  • L2={0i1j∣i=j}L_2 = \{0^i 1^j \mid i = j\}: This is the standard matching language. A PDA can push 00's onto the stack and pop them for each 11. Thus, L2L_2 is context-free.
  • L1={0i1j∣i≠j}L_1 = \{0^i 1^j \mid i \neq j\}: This can be written as the union of two context-free languages: {0i1j∣i>j}∪{0i1j∣i<j}\{0^i 1^j \mid i > j\} \cup \{0^i 1^j \mid i < j\}. Since context-free languages are closed under union, L1L_1 is context-free.
  • L3={0i1j∣i=2j+1}L_3 = \{0^i 1^j \mid i = 2j + 1\}: We can easily write a CFG for this language: S→00S1∣0S \to 00S1 \mid 0 Since a CFG exists, L3L_3 is context-free.
  • L4={0i1j∣i≠2j}L_4 = \{0^i 1^j \mid i \neq 2j\}: Similar to L1L_1, this can be expressed as the union of two context-free languages: {0i1j∣i>2j}∪{0i1j∣i<2j}\{0^i 1^j \mid i > 2j\} \cup \{0^i 1^j \mid i < 2j\}. Thus, L4L_4 is context-free.

Therefore, all the given languages are 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