Which of the following regular expressions represent(s) the set of all binary…

2021

Which of the following regular expressions represent(s) the set of all binary numbers that are divisible by three? Assume that the string ϵ is divisible by three.

  1. A.

    \((0+1(01^*0)^*1)^*\)

  2. B.

    \((0+11+10(1+00)^*01)^*\)

  3. C.

    \((0^*(1(01^*0)^*1)^*)^*\)

  4. D.

    \((0+11+11(1+00)^*00)^*\)

Attempted by 116 students.

Show answer & explanation

Correct answer: A, B, C

Answer: The correct regular expression is (0+1(01*0)*1)*.

Reasoning:

  • Work modulo 3: reading a binary string is equivalent to computing its integer value modulo 3. A minimal DFA for remainders modulo 3 has three states (remainders 0, 1, 2) and transitions on bits 0 and 1.

  • Accepting loops from remainder 0 to remainder 0 generate exactly those substrings that contribute a value divisible by 3. There are two simple kinds of such substrings:

    • The single symbol 0 (this leaves the remainder 0).

    • Strings that start and end with 1 and whose interior consists of zero-or-more repetitions of the substring 01*0. Such a block has the shape 1(01*0)*1 and evaluates to a number divisible by 3.

  • Concatenating any number of these blocks preserves divisibility by 3 because if each block's numeric value is divisible by 3, then multiplying a divisible-by-3 value by any power of two still leaves it divisible by 3, so the sum (which corresponds to concatenation) is divisible by 3. The Kleene star over the union of these blocks therefore generates exactly the set of binary strings whose numeric value is divisible by 3, including the empty string ϵ.

Why the other given regular expressions fail:

  • The expression (0+11+10(1+00)^*01)^* uses a different internal block shape 10(1+00)^*01. That subpattern does not correspond to the DFA loops 1(01*0)*1 and therefore the overall expression does not match exactly the same set of remainder-0 strings; its internal choices alter lengths and residues in ways that break the exact characterization.

  • The expression (0^*(1(01^*0)^*1)^*)^* nests Kleene stars and allows runs of zeros and repetitions in positions that change how blocks concatenate. This extra flexibility changes which strings are generated and so the language is not guaranteed to be exactly the multiples-of-three language.

  • The expression (0+11+11(1+00)^*00)^* again uses a different block form 11(1+00)^*00 that is not the same as 1(01*0)*1; the trailing 00 and the internal (1+00)^* choice change block lengths and residues, so the set of generated strings differs from the desired language.

Summary: (0+1(01*0)*1)* is the canonical regular expression obtained from the DFA decomposition into loops that return remainder 0. The other listed expressions change the internal block structure or use extra stars and therefore fail to produce exactly the same language.

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Gate Guidance By Sanchit Sir