GATE Computer ScienceHardGATE CS (PYQ pattern)

Consider I. {aⁿbᵐcⁿdᵐ | n, m ≥ 1}, II. {aⁿbᵐcᵐdⁿ | n, m ≥ 1}, III. {wwᴿ | w ∈ {a,b}*}, IV. {ww | w ∈ {a,b}*}. Which of these languages are context-free?

  1. A. I and II only
  2. B. II and III only
  3. C. III and IV only
  4. D. I, II and III only

Correct answer: B. II and III only

II is nested (aⁿ ... dⁿ around bᵐcᵐ) and III is a palindrome language, so both are accepted by PDAs. I and IV need crossing (non-nested) comparisons of two unbounded counts or of w with itself, which a single stack cannot do, so they are not context-free.

More Theory of Computation questions

Exams that ask this topic