Minimum-State DFA for Joint Modulo Counts

Minimum-State DFA for Joint Modulo Counts

Verified Sources
Sep 12, 2026

DFA Minimization (Myhill–Nerode & State Equivalence)

We consider the language over Σ={0,1}\Sigma=\{0,1\}:

L={w{0,1}#0(w)0(mod3) and #1(w)0(mod5)}.L=\{w\in\{0,1\}^*\mid \#0(w)\equiv 0\pmod 3 \ \text{and}\ \#1(w)\equiv 0\pmod 5\}.

Here #0(w)\#0(w) and #1(w)\#1(w) denote the number of 00’s and 11’s in ww.

The key idea is that a DFA only needs to remember:

  • the remainder of #0(w)\#0(w) modulo 33 and
  • the remainder of #1(w)\#1(w) modulo 55.

We will build a DFA via product construction and then argue that it is minimal (so the number of states matches the correct option among (i) 15, (ii) 11, (iii) 10, (iv) 9).

Important concepts:

  • DFA
  • Myhill-Nerode
  • Product construction
  • Congruence modulo

Constructing a DFA that tracks remainders

Define two DFAs:

  1. A DFA A0A_0 over {0,1}\{0,1\} that tracks #0(w)mod3\#0(w)\bmod 3.

    • It has states {0,1,2}\{0,1,2\} representing the current remainder of #0\#0.
    • On input symbol:
      • reading a 00 increments the remainder mod 33,
      • reading a 11 leaves the remainder unchanged.
  2. A DFA A1A_1 over {0,1}\{0,1\} that tracks #1(w)mod5\#1(w)\bmod 5.

    • It has states {0,1,2,3,4}\{0,1,2,3,4\} representing the current remainder of #1\#1.
    • On input symbol:
      • reading a 11 increments the remainder mod 55,
      • reading a 00 leaves the remainder unchanged.

Then LL is the intersection of:

  • strings where #0(w)0(mod3)\#0(w)\equiv 0\pmod 3 and
  • strings where #1(w)0(mod5)\#1(w)\equiv 0\pmod 5.

So the DFA for LL is the product automaton whose state is the pair:

(r0,r1){0,1,2}×{0,1,2,3,4},(r_0,r_1)\in \{0,1,2\}\times\{0,1,2,3,4\},

meaning r0#0(w)(mod3)r_0\equiv \#0(w)\pmod 3 and r1#1(w)(mod5)r_1\equiv \#1(w)\pmod 5.

That yields exactly 35=153\cdot 5=15 states before minimization.

Mermaid view of product tracking:

Step-by-step: DFA for the language

  1. 1
    Step 1

    Let r0=#0(w)mod3r_0=\#0(w)\bmod 3 and r1=#1(w)mod5r_1=\#1(w)\bmod 5.

  2. 2
    Step 2

    Use states (r0,r1){0,1,2}×{0,1,2,3,4}(r_0,r_1)\in\{0,1,2\}\times\{0,1,2,3,4\} (total 1515).

  3. 3
    Step 3

    Start at (0,0)(0,0) because the empty string has zero 00’s and zero 11’s.

  4. 4
    Step 4

    On input 00: (r0,r1)((r0+1)mod3, r1)(r_0,r_1)\mapsto ((r_0+1)\bmod 3,\ r_1).

  5. 5
    Step 5

    On input 11: (r0,r1)(r0, (r1+1)mod5)(r_0,r_1)\mapsto (r_0,\ (r_1+1)\bmod 5).

  6. 6
    Step 6

    Accept exactly when (r0,r1)=(0,0)(r_0,r_1)=(0,0), i.e., both counts are divisible.

  7. 7
    Step 7

    The construction yields 1515 states; next we prove no fewer are possible.

Why the minimum DFA has 15 states (no merging possible)

To prove minimality, we show that all 1515 remainder-pairs represent distinct equivalence classes under the Myhill–Nerode relation.

Let two strings xx and yy reach different pairs:

(r0(x),r1(x))(r0(y),r1(y)).(r_0(x),r_1(x))\neq (r_0(y),r_1(y)).

We will produce a distinguishing suffix zz such that exactly one of xz,yzxz, yz is in LL.

Case 1: r0(x)r0(y)r_0(x)\neq r_0(y)

So r0(x){0,1,2}r_0(x)\in\{0,1,2\} differs from r0(y)r_0(y) modulo 33. Choose a suffix consisting only of 00’s:

z=0t,where tr0(x)(mod3).z = 0^{\,t},\quad \text{where } t\equiv -r_0(x)\pmod 3.

Then:

  • For xzxz: the number of additional 00’s makes #0(xz)0(mod3)\#0(xz)\equiv 0\pmod 3.
  • For yzyz: since r0(y)≢r0(x)(mod3)r_0(y)\not\equiv r_0(x)\pmod 3, adding the same tt cannot make both remainders zero simultaneously; thus #0(yz)≢0(mod3)\#0(yz)\not\equiv 0\pmod 3.

Because zz contains no 11’s, the #1()mod5\#1(\cdot)\bmod 5 part is unchanged for both. Hence exactly one of xzxz and yzyz lies in LL.

Case 2: r1(x)r1(y)r_1(x)\neq r_1(y)

Symmetric argument using a suffix only of 11’s:

z=1s,where sr1(x)(mod5).z = 1^{\,s},\quad \text{where } s\equiv -r_1(x)\pmod 5.

Then xzxz fixes #1(xz)0(mod5)\#1(xz)\equiv 0\pmod 5, but yzyz fails because the modulo-5 remainder differs, while the #0\#0 modulo-3 remainder is unchanged.

Therefore, if two states (remainder pairs) differ in either component, they are distinguishable by some suffix, so they cannot be merged.

Conclusion: the constructed product DFA is already minimal, with exactly

35=153\cdot 5 = 15

states.

Candidate options vs. minimal state count

The minimal DFA state count equals 3×5=15.

Pro Tip: Tracking counts is enough

For languages defined by congruences of symbol counts, a minimal DFA often comes from storing those remainders. Here it’s (#0mod3,#1mod5)(\#0 \bmod 3, \#1 \bmod 5), so the state count multiplies.

Common pitfall: assuming fewer states by intuition

Even if the accepting condition seems simple, different remainder pairs are distinguishable (via padding with only 0’s or only 1’s). So you cannot merge them without breaking correctness.

FAQ and edge cases

Course Roadmap: From language to minimal DFA

Interpret the language

1

Acceptance requires #00(mod3)\#0\equiv 0\pmod3 and #10(mod5)\#1\equiv 0\pmod5."

Build remainder DFAs

2

Create A0A_0 (mod 3) and A1A_1 (mod 5) over the same alphabet."

Use product construction

3

Form states (r0,r1)(r_0,r_1); accepting state is (0,0)(0,0)."

Prove minimality

4

Use Myhill–Nerode: show all remainder pairs are distinguishable."

Quick self-check deck

1 / 4
Question · Term

What does the product DFA state (r0,r1) mean?

Click to reveal
Answer · Definition

It encodes r0#0(w)(mod3)r_0\equiv \#0(w)\pmod3 and r1#1(w)(mod5)r_1\equiv \#1(w)\pmod5 after reading input ww.

Knowledge Check

Question 1 of 4
Q1Single choice

For the language where #0 is divisible by 3 and #1 is divisible by 5, the DFA needs to track which information?