GATE Computer ScienceHardGATE CS (PYQ pattern)

Which of the following languages is context-free?

  1. A. The complement of { w w : w ∈ {a, b}* }
  2. B. The language { w w : w ∈ {a, b}* } itself
  3. C. The language { aⁿbⁿcⁿ : n ≥ 0 } itself
  4. D. The language { aᵖ : p is a prime number }

Correct answer: A. The complement of { w w : w ∈ {a, b}* }

The complement of {ww} is context-free (a word is outside it iff its length is odd or it has positions i and i + n/2 with different symbols, which a PDA can guess), although {ww} itself is not: another proof that CFLs are not closed under complement.

More Theory of Computation questions

Exams that ask this topic