Question
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.
Official answer and solution
- Official answer
- A, B and C
- From
- Official GATE 2021 answer key
Solution
Use the standard 3-state remainder DFA for binary numbers modulo 3 and derive equivalent regular expressions via state elimination.
The DFA recognizing binary strings divisible by 3 has states (remainder 0, start and accept state), (remainder 1), and (remainder 2):
- From : on 0 goes to ; on 1 goes to
- From : on 0 goes to ; on 1 goes to
- From : on 0 goes to ; on 1 goes to
Deriving expression via state elimination:
- Eliminate state :
State has a self-loop on 1 ().
The path from through and back to is .
Thus, at , the self-loop is .
From , transitioning to on 1 gives the path expression from through back to .
Combining with the self-loop on 0 at , the overall regular expression is:This matches option A.
- Equivalence of Option C:
Using the regular identity , setting and gives . Thus, option C represents the exact same language and is correct.
- Eliminate state first:
- From , paths to directly: 0 and .
- Paths between and : gives , and gives .
- Self loop at : 1 (direct) or (via ), giving .
- Connecting from through back to gives .
- Combined with direct loops at , the expression is:
This precisely matches option B.
Option D has the term instead of , which produces invalid strings that are not multiples of 3 (for instance, , which is not divisible by 3). Therefore, option D is incorrect.
A, B, C
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2021 Computer Science and Information Technology - Session 2 (CS2)
- Question
- 57 of 65, printed as CS Q.47
- Section
- Computer Science and Information Technology
Report an error in this question
GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.