GATE Computer ScienceVery hardGATE CSE · UGC NET

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

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

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

Between consecutive blocks the substrings 01 and 10 alternate, so their counts are equal exactly when w is empty or its first and last symbols are equal — a regular condition (checked exhaustively up to length 14). The other three need unbounded counting and are not regular.

More Theory of Computation questions

Exams that ask this topic