GATE Computer ScienceHardGATE CS (PYQ pattern)

Which one of the following languages is regular?

  1. A. { w ∈ {0, 1}* : #0(w) = #1(w) }
  2. B. { w ∈ {0, 1}* : #01(w) = #10(w) }
  3. C. { 0ⁿ1ᵐ : n ≠ m }
  4. D. { w wᴿ : w ∈ {0, 1}* }

Correct answer: B. { w ∈ {0, 1}* : #01(w) = #10(w) }

Occurrences of 01 and 10 alternate, so their counts differ by at most 1 and they are equal exactly when the first and last symbols are equal: a 5-state DFA. The other three languages are non-regular by pumping.

More Theory of Computation questions

Exams that ask this topic