The GATE Grind

GATE 2010 CS (CS1) – Question 50

Theory of Computation · Context-Free Grammars and Pushdown Automata · 2 marks · Multiple choice

For nonnegative i,j, let $L_1=\{0^i1^j:i\ne j\}$, $L_2=\{0^i1^j:i=j\}$, $L_3=\{0^i1^j:i=2j+1\}$ and $L_4=\{0^i1^j:i\ne2j\}$. Which is true?

  1. Only L₂ is context-free
  2. Only L₂,L₃ are context-free
  3. Only L₁,L₂ are context-free
  4. All are context-free

Practise this question in The GATE Grind →

Show answer and explanation

Correct answer: (D) All are context-free

Explanation

A pushdown automaton can compare zeros and ones one-for-one for L₂ and two-for-one with one extra zero for L₃. For L₁, split into i<j and i>j; each comparison is context-free and their union is context-free. Similarly split L₄ into i<2j and i>2j using two-for-one stack comparison. Thus all four are context-free, D.

More Context-Free Grammars and Pushdown Automata questions

All Context-Free Grammars and Pushdown Automata questions →