GATE / CS ARCHIVE

GATE CSE 1998 / QUESTION 4

Minimal DFA for multiples of five

Theory of Computation · Finite Automata · Full GATE CSE 1998 paper

GATE 1998, Q4 Descriptive
Report issue

Finite Automata

Question 4, GATE 1998: Design a minimum-state DFA for binary strings whose numeric value, ignoring leading zeros, is divisible by five.
Tap to enlarge
Answer & solution

Answer: Five remainder states if ε represents 0; six if an empty representation is excluded. (no official key was published)

Maintain the remainder r of the binary prefix modulo 5. Appending bit b changes a value v into 2v+b, so the transition is δ(qr,b)=q_((2r+b) mod 5). The start and sole accepting state is q0, using the conventional value 0 for ε.

State     input 0   input 1
q0        q0        q1
q1        q2        q3
q2        q4        q0
q3        q1        q2
q4        q3        q4

This transition table fully specifies the DFA. Leading zeros loop at q0, and zero is divisible by five. Induction on prefix length proves the invariant that state qr means the prefix value is congruent to r. Consequently the final state is accepting exactly for multiples of five.

For minimality, all five states are reachable: ε, 1, 10, 11 and 100 reach q0 through q4. Given distinct remainders r and s, choose v in {0,1,2,3,4} with 8r+v≡0 mod 5 and append its three-bit binary representation, including leading zeros. From qr the result is accepting. From qs its remainder differs by 8(s−r), which is nonzero modulo 5 because 8 is invertible modulo 5. Thus every pair is distinguishable, establishing a five-state lower bound.

The source says strings in {0,1}* but does not define the value of ε. If a binary numeral must contain at least one symbol, add a new nonaccepting start state s with 0→q0 and 1→q1. It is distinct from q0 by ε and from every other remainder state by the suffix argument, so this alternative language needs six states. The five-state answer uses the explicitly stated conventional interpretation.

Original paper, page 6