GATE Computer ScienceHardGATE CSE · ISRO

Which of the following languages over {0, 1} is regular?

  1. A. { w : the number of 0s equals the number of 1s }
  2. B. { w : the number of occurrences of the substring 01 equals the number of occurrences of 10 }
  3. C. { 0^n 1^m 0^n : n, m ≥ 0 }
  4. D. { 0^p : p is a prime number }

Correct answer: B. { w : the number of occurrences of the substring 01 equals the number of occurrences of 10 }

Occurrences of 01 and 10 alternate, so their counts are equal exactly when w is empty or starts and ends with the same symbol, which is regular. The others fail the pumping lemma.

More Theory of Computation questions

Exams that ask this topic