Introduction

Two states of a DFA are equivalent when no string leads from one to an accept state and from the other to a reject state. Merging equivalent states yields the unique (up to renaming) minimal DFA for the language: fewest states among all DFAs for that language. The skills are running the table-filling (distinguishability) algorithm, reading the minimized diagram, and using Myhill-Nerode to prove a lower bound on the number of states.

Prerequisites

Core concepts

Distinguishable states

States pp and qq are distinguishable if there exists a string zz such that exactly one of δ^(p,z)\hat{\delta}(p,z) and δ^(q,z)\hat{\delta}(q,z) is accepting. Otherwise they are equivalent (indistinguishable).

Base case: if exactly one of p,qp,q is accepting, they are distinguished by ε\varepsilon.

Inductive step: if for some symbol aa, the states δ(p,a)\delta(p,a) and δ(q,a)\delta(q,a) are already distinguishable, then pp and qq are distinguishable (prepend aa to the distinguishing continuation).

Table-filling algorithm

For states ordered q1,…,qnq_1,\ldots,q_n, maintain a triangular table of pairs {qi,qj}\{q_i,q_j\} with i>ji>j.

  1. Mark every pair where one state is accepting and the other is not.
  2. Repeat until no change: if an unmarked pair (p,q)(p,q) has, for some aa, the pair (δ(p,a),δ(q,a))(\delta(p,a),\delta(q,a)) marked, mark (p,q)(p,q).
  3. Unmarked pairs are equivalent. Merge each equivalence class into one state; transitions and acceptance lift to classes. Remove states unreachable from the start if any remain.

The result is the minimal DFA. Hopcroft's algorithm computes the same partition faster (O(∣Σ∣nlg⁡n)O(|\Sigma|n\lg n) time) but table-filling is the easier one to run by hand.

For a language L⊆Σ∗L \subseteq \Sigma^*, define x≡Lyx \equiv_L y iff for every z∈Σ∗z \in \Sigma^*, xz∈L⇔yz∈Lxz \in L \Leftrightarrow yz \in L. This is an equivalence relation, and it is right-invariant: x≡Lyx \equiv_L y implies xa≡Lyaxa \equiv_L ya.

Myhill-Nerode theorem. The following are equivalent: (1) LL is regular; (2) ≡L\equiv_L has finitely many classes (finite index); (3) LL is a union of classes of some right-invariant equivalence of finite index. Moreover, the number of classes of ≡L\equiv_L equals the number of states of the minimal complete DFA for LL, and the minimal DFA is unique up to renaming of states.

Consequences used in exams:

  • Lower bound. To prove every DFA for LL needs at least kk states, exhibit kk pairwise distinguishable strings: for every pair xi,xjx_i, x_j give a zz with xiz∈L⇔xjz∉Lx_i z \in L \Leftrightarrow x_j z \notin L.
  • Non-regularity. An infinite set of pairwise distinguishable strings proves LL is not regular. For {anbn}\{a^n b^n\}, the strings aia^i and aja^j (i≠ji \ne j) are separated by z=biz = b^i. This proof works even for languages where the pumping lemma is awkward, and it is the only one of the two that can also prove regularity (finite index).
  • Describing the classes. For "ends with 01" over {0,1}\{0,1\} the three classes are: strings ending in 01; strings ending in 0; all other strings (including ε\varepsilon and strings ending in 11). Each class is one state of the minimal DFA.

How it works

Worked table for a redundant even-aa machine

Alphabet {a}\{a\}. States EE (start, accept), OO (reject), E2E_2 (accept) with transitions E→aOE \xrightarrow{a} O, O→aE2O \xrightarrow{a} E_2, E2→aOE_2 \xrightarrow{a} O. States EE and E2E_2 are both accepting and move to OO on aa; OO is rejecting. Table marks (E,O)(E,O) and (E2,O)(E_2,O) immediately; (E,E2)(E,E_2) never marks. Merge {E,E2}\{E,E_2\} into one accept state. Minimal DFA has 2 states.

Partition refinement table for DFA minimization
Figure 1. Distinguishability table for states E, O, E2 of the redundant even-number-of-a DFA; pair E-E2 stays unmarked and merges, while pairs with O are marked.

Already-minimal example

DFA for strings ending with 0: states AA (start), BB (accept); A→0BA\xrightarrow{0}B, A→1AA\xrightarrow{1}A, B→0BB\xrightarrow{0}B, B→1AB\xrightarrow{1}A. Pair (A,B)(A,B) marked by ε\varepsilon. Minimal already: 2 states.

Algorithms and pseudocode

Text
TABLE-FILL(M)
1  mark all pairs {p,q} with (p in F) xor (q in F)
2  repeat
3      for each unmarked pair {p,q}
4          for each a in Sigma
5              if {delta(p,a), delta(q,a)} is marked
6                  mark {p,q}; break
7  until no new marks
8  return unmarked pairs as equivalences

Time O(∣Σ∣n3)O(|\Sigma|n^3) worst-case for this repeated-scan loop, where n=∣Q∣n=|Q|: there are O(n)O(n) propagation rounds and O(∣Σ∣n2)O(|\Sigma|n^2) work per round. A dependency/worklist implementation can achieve O(∣Σ∣n2)O(|\Sigma|n^2).

Text
MINIMIZE(M)
1  remove states unreachable from q0
2  equiv <- TABLE-FILL(M)
3  classes <- partition Q by equiv
4  return the quotient DFA on classes

Mathematical explanation

Uniqueness

Any two minimal DFAs for the same language are isomorphic: the Myhill-Nerode classes determine both. Minimization finds that canonical machine.

Why the algorithm terminates with the Myhill-Nerode partition

Marked pairs are exactly the distinguishable ones: soundness by induction on the length of a shortest distinguishing string; completeness because if p≢qp \not\equiv q, a shortest distinguisher of length kk forces a mark after kk rounds.

Worked examples

Example 1: mergeable accept states

As above: three-state even-aa machine minimizes to two states. Distinguishing string for EE vs OO is ε\varepsilon; for EE vs E2E_2 none exists.

Example 2: lower bound via Myhill-Nerode

Language L={w∈{0,1}∗∣∣w∣≡0(mod3)}L = \{ w \in \{0,1\}^* \mid |w| \equiv 0 \pmod 3 \}. Strings ε,0,00\varepsilon, 0, 00 are pairwise distinguishable:

  • ε\varepsilon and 00 distinguished by ε\varepsilon (first in LL, second not).
  • ε\varepsilon and 0000 distinguished by 00 (ε0=0∉L\varepsilon 0 = 0 \notin L, 00⋅0=000∈L00\cdot 0 = 000 \in L).
  • 00 and 0000 distinguished by 00: 0000 rejects, whereas 000000 accepts.

Hence every DFA needs at least 3 states; the standard mod-3 length DFA meets the bound.

Example 3: strings ending with 01

The 4-state progress DFA of the DFA note is not minimal. Its states ε\varepsilon and 1 are equivalent: both are rejecting, and both go to 0 on 0 and to 1 on 1, so the pair is never marked. The other pairs are marked: 01 against any other state by ε\varepsilon, then 0 against ε\varepsilon and against 1 because on input 1 they go to the marked pairs (01, 1). Minimal size is 3, matching the three Myhill-Nerode classes listed above.

Example 4: full table on a 4-state machine

States A (start), B, C (accept), D (accept). Alphabet {0,1}. Transitions:

01
ABA
BAC
CDA
DCA

First mark pairs mixing accept and reject: (A,C), (A,D), (B,C), (B,D). Unmarked: (A,B), (C,D).

Check (A,B): on 0 go to (B,A) unmarked; on 1 go to (A,C) which is marked. So mark (A,B).

Check (C,D): on 0 go to (D,C) unmarked; on 1 go to (A,A) same state. No mark from this round. Next round still no new marks from (C,D). So C and D merge.

Quotient: states {A}, {B}, {C,D}. The only merge is between the two accept states.

Example 5: partition refinement (kk-equivalence) on a 6-state DFA

States AA (start) to FF, accepting {B,E}\{B, E\}:

Stateon 0on 1
ABE
BDF
CBE
DED
EFC
FBE

Two states are kk-equivalent if no string of length at most kk distinguishes them. Refine until a round changes nothing.

  • P0P_0 (accepting or not): {A,C,D,F}\{A, C, D, F\}, {B,E}\{B, E\}.
  • P1P_1: in the first block, A,C,FA, C, F go to ({B,E},{B,E})(\{B,E\}, \{B,E\}) but DD goes to ({B,E},{A,C,D,F})(\{B,E\}, \{A,C,D,F\}), so DD splits off. BB and EE both go to the non-accepting block on both symbols and stay together. P1={A,C,F},{D},{B,E}P_1 = \{A, C, F\}, \{D\}, \{B, E\}.
  • P2P_2: BB goes to ({D},{A,C,F})(\{D\}, \{A,C,F\}) and EE to ({A,C,F},{A,C,F})(\{A,C,F\}, \{A,C,F\}), so they split. P2={A,C,F},{B},{D},{E}P_2 = \{A, C, F\}, \{B\}, \{D\}, \{E\}.
  • P3=P2P_3 = P_2: stop.

The minimal DFA has 4 states, {A,C,F}\{A,C,F\} becoming the start state. Note that BB and EE are 1-equivalent but not 2-equivalent. A distinguishing string of length 2 is 01: B→0D→1DB \xrightarrow{0} D \xrightarrow{1} D rejects, while E→0F→1EE \xrightarrow{0} F \xrightarrow{1} E accepts. (The string 00 does not work: it leads from BB to EE and from EE to BB, both accepting.)

Table filling and partition refinement agree. Both compute the Myhill-Nerode partition of the reachable states; table filling marks pairs, refinement splits blocks. Refinement is faster to write for 6 or more states.

Example 6: unreachable state

Add a state E with self-loops that is never reached from A. Table-filling might still compare E to others, but MINIMIZE first deletes E by reachability DFS/BFS from the start. The minimal DFA never includes unreachable states. Always remove them before reporting the state count.

Important properties and observations

  • Minimization requires a complete DFA; apply subset construction first if you start from an NFA.
  • Equivalent states must agree on acceptance and on the classes of all successors.
  • All non-accepting sinks are equivalent and merge into one dead state; a dead state is never equivalent to a state from which an accepting state is reachable.
  • If no accepting state is reachable, the minimal complete DFA has exactly 1 state (a rejecting sink); if every reachable state accepts, it has 1 accepting state.
  • NFAs have no unique minimal form. Two different minimal NFAs can accept the same language, and minimizing an NFA is computationally hard in general. Minimization questions are about DFAs.
  • Equivalence of two DFAs is decided by minimizing both and comparing up to renaming, or by running table filling on their disjoint union and checking whether the two start states are equivalent.
  • Minimal DFA is unique up to renaming; minimal RE is not unique.

Common misconceptions.

  • "Any two accept states may merge." Only if they are indistinguishable.
  • "Minimization can change the language." It must not; always verify on a few strings.
  • "Unreachable states affect minimality counts in Myhill-Nerode." Remove them first; Nerode classes count only what the language needs.

GATE examination perspective

  • FILL THE TABLE IN ORDER. Mark accept/reject pairs first; iterate until stable.
  • DRAW THE MERGED MACHINE. One state per class; copy transitions using representatives.
  • LOWER BOUNDS. Give pairwise distinguishing continuations; do not assume a particular DFA.
  • COUNT AFTER REMOVING UNREACHABLE STATES. Unreachable states inflate raw state counts.
  • IDENTICAL ROWS MERGE AT ONCE. States with the same acceptance and identical rows (here AA, CC, FF) are equivalent; spotting them shortens the work.
  • kk-EQUIVALENCE QUESTIONS. "How many classes after round 1" asks for P1P_1, not the final partition; read which round is asked.
  • COMPLETE FIRST. Add the dead state before minimizing a partial DFA; an omitted sink can change the count and must be included before minimization; the change is not always exactly one.
  • MYHILL-NERODE PROVES BOTH WAYS. Finite index proves regularity, infinite index proves non-regularity; the pumping lemma only does the second.

Summary

Sources

  1. J. E. Hopcroft, R. Motwani, J. D. Ullman, Introduction to Automata Theory, Languages, and Computation, 3rd ed., Pearson Addison-Wesley, Section 4.4 (equivalence and minimization of automata: testing equivalence of states, testing equivalence of regular languages, minimization of DFAs, why the minimized DFA cannot be beaten).
  2. M. Sipser, Introduction to the Theory of Computation, 3rd ed., Cengage Learning: Section 1.1 (finite automata) and Section 1.4 (nonregular languages).
  3. P. Linz, An Introduction to Formal Languages and Automata, 6th ed., Jones & Bartlett Learning: Section 2.4 (reduction of the number of states in finite automata).

Next steps