G27
Self-checkedTier 1 12 min readtoc.dfa-minimisation

DFA minimisation

Reducing a DFA to the smallest equivalent DFA: remove unreachable states, make the machine complete, merge equivalent states found by partition refinement (Moore) or by the table-filling algorithm, with the distinguishing string of every pair; the minimal DFA is unique up to renaming, the dead state counts, the state counts GATE asks for, and what minimisation does not do (NFAs).

Why it exists

The subset construction and the product construction produce DFAs with more states than necessary. A smaller DFA is cheaper to store, easier to compare with another DFA, and, most important for GATE, the smallest DFA of a language is unique, so "the number of states of the minimal DFA" is a well-defined number that questions ask for. Minimisation is also how two DFAs are tested for equivalence.

Prerequisites

You need DFAs and the subset construction (subset construction); counting minimal states for common languages is practised in DFA design patterns.

Precise definitions

Let D=(Q,Σ,δ,q0,F)D = (Q, \Sigma, \delta, q_0, F) be a DFA and extend δ\delta to strings as δ∗\delta^*.

  • Two states p,qp, q are equivalent, written p≡qp \equiv q, if for every string w∈Σ∗w \in \Sigma^*: δ∗(p,w)∈F  ⟺  δ∗(q,w)∈F\delta^*(p, w) \in F \iff \delta^*(q, w) \in F.
  • They are distinguishable if some string ww (a distinguishing string) is accepted from exactly one of them. ≡\equiv is an equivalence relation.
  • A state is reachable if some string leads to it from q0q_0.
  • The minimal DFA of LL is a complete DFA for LL with the fewest states. Its states are the equivalence classes of the reachable states of any complete DFA for LL: [q]→a[δ(q,a)],[q0] start,[q] accepting iff q∈F.[q] \xrightarrow{a} [\delta(q, a)], \quad [q_0] \text{ start}, \quad [q] \text{ accepting iff } q \in F.
  • Theorem. The minimal DFA is unique up to renaming of states, and no DFA for LL has fewer states. (The deeper reason is the Myhill-Nerode theorem: the states correspond to the classes of strings with the same future; see Myhill-Nerode.)

Convention. A complete DFA has a transition for every symbol from every state, so the dead state counts as a state. If a question says "minimum number of states of a DFA", count the dead state when the language needs one (this is the usual textbook and GATE convention; if a question explicitly allows a partial DFA the answer is one less). Needs verification against the wording of each question.

How it works

The procedure

  1. Remove unreachable states (search from q0q_0). They never matter.
  2. Make the DFA complete (add a dead state if some transition is missing).
  3. Partition refinement (Moore). Start with two groups: accepting and non-accepting. Repeat: two states stay in the same group only if for every symbol they move into the same group (of the previous round). Stop when a round splits nothing.
  4. Merge each group into one state. Transitions and the accepting set are inherited from any member (they are the same for all members).

Why this is right: after round kk, two states are in the same group exactly when no string of length at most kk distinguishes them. Round 00 uses the empty string; round k+1k + 1 prepends one symbol. At most ∣Q∣−1|Q| - 1 rounds split anything, because every round that splits increases the number of groups, which cannot exceed ∣Q∣|Q|.

Example 1: a DFA with a useless parity bit

The first DFA below recognises "ends with 0101" but also remembers whether the number of symbols read is even or odd (states qieq_i e and qioq_i o), and has a state uu that nothing leads to. It has 77 states, 66 reachable.

A DFA for 'ends with 01' with a useless parity bit (7 states, one unreachable): start

Simulated, not typed
10100101101010q0eq0oq1eq1oq2eq2ou

Double circle = accepting state. Arrow from nowhere = start state.

input0101
state{q0e}

Step 0

Start in the start state q0e. The machine reads the input from left to right, one symbol at a time, and every symbol moves it along exactly one edge.

0 / 5
computed by script: the machine is simulated or the sets are constructed by scripts/toc_lib.py, one step at a time. python3 scripts/gen-toc2-traces.py

Run the rounds. After the unreachable state is dropped, round 00 separates the accepting states {q2e,q2o}\{q_2 e, q_2 o\} from the rest. Round 11 looks at where the states of the big group go on 00 and on 11 and splits it into {q0e,q0o}\{q_0 e, q_0 o\} and {q1e,q1o}\{q_1 e, q_1 o\}. Round 22 changes nothing, so we stop with three groups.

Minimisation by partition refinement: start

Computed by a script, not typed
roundgroups of states (states in one group are not yet told apart)number of groups
round 0
round 1
round 2

Step 0

Start with two groups (accepting and not). Repeatedly split a group when two of its states have a symbol that leads them into different groups. When nothing splits, the groups are the states of the minimal DFA.

0 / 3
computed by script: the machine is simulated or the sets are constructed by scripts/toc_lib.py, one step at a time. python3 scripts/gen-toc2-traces.py

Merging the groups gives the minimal DFA: three states, the usual DFA for "ends with 0101".

The minimal DFA of the same language (3 states): start

Simulated, not typed
100110{q0e,q0o}{q1e,q1o}{q2e,q2o}

Double circle = accepting state. Arrow from nowhere = start state.

input0101
state{{q0e,q0o}}

Step 0

Start in the start state {q0e,q0o}. The machine reads the input from left to right, one symbol at a time, and every symbol moves it along exactly one edge.

0 / 5
computed by script: the machine is simulated or the sets are constructed by scripts/toc_lib.py, one step at a time. python3 scripts/gen-toc2-traces.py

The table-filling algorithm and distinguishing strings

The same result can be found by marking pairs of states. Make a triangular table of all pairs of reachable states.

  1. Mark a pair when exactly one of the two states is accepting (the empty string distinguishes them). These are the level-00 pairs.
  2. Mark a pair {p,q}\{p, q\} at level k+1k + 1 if for some symbol aa the pair {δ(p,a),δ(q,a)}\{\delta(p, a), \delta(q, a)\} was marked at level kk (so aa followed by that pair's distinguishing string distinguishes pp and qq).
  3. Repeat until nothing new is marked. The pairs left unmarked are equivalent.

The level of a marked pair is the length of the shortest distinguishing string. The unmarked pairs are then merged into groups (equivalence is transitive, so the groups are well defined).

The table-filling algorithm on the same DFA: start

Computed by a script, not typed
q0eq0oq1eq1oq2e
q0o
q1e
q1o
q2e
q2o

Step 0

Table of all pairs of reachable states. A cell will be filled when the two states are distinguishable (some string is accepted from one and rejected from the other). The number written is the length of the shortest such string.

0 / 3
computed by script: the machine is simulated or the sets are constructed by scripts/toc_lib.py, one step at a time. python3 scripts/gen-toc2-traces.py

In this table the pairs {q0e,q0o}\{q_0 e, q_0 o\}, {q1e,q1o}\{q_1 e, q_1 o\} and {q2e,q2o}\{q_2 e, q_2 o\} stay empty: the parity bit never changes the future of a string, because "ends with 0101" does not depend on the length.

Equivalence of two DFAs

To test whether two DFAs accept the same language: (a) minimise both and compare the minimal DFAs (they must have the same number of states, the same start, the same transitions up to renaming); or (b) put both machines side by side, run table filling on the combined set of states and see whether the two start states end up equivalent; or (c) search the product automaton for a reachable pair of states of which exactly one is accepting.

Cost

Moore's algorithm takes at most ∣Q∣−1|Q| - 1 rounds of O(∣Q∣⋅∣Σ∣)O(|Q| \cdot |\Sigma|) work: O(∣Q∣2∣Σ∣)O(|Q|^2 |\Sigma|). Hopcroft's algorithm needs O(∣Σ∣ ∣Q∣log⁡∣Q∣)O(|\Sigma| \, |Q| \log |Q|). (Textbook results, quoted.)

What minimisation does not do

  • It is for DFAs. A minimal NFA is not unique, and finding a smallest NFA is a hard problem (quoted, not proved here); an NFA is usually made small by design, not by an algorithm.
  • It does not change the language.
  • A DFA can already be minimal even if it looks large; the "ends with 0101" machine on three states is minimal because its three states have different futures.

Worked examples

EX 1Which states can be merged

Easy

A complete DFA has states 1,2,31, 2, 3, start 11, accepting {3}\{3\}. Round 00 gives {1,2}\{1, 2\} and {3}\{3\}. If 1→a21 \xrightarrow{a} 2, 2→a12 \xrightarrow{a} 1, 1→b31 \xrightarrow{b} 3, 2→b32 \xrightarrow{b} 3, then on aa both stay in {1,2}\{1, 2\} and on bb both go to {3}\{3\}: no split, so 1≡21 \equiv 2 and the minimal DFA has 22 states. Check with a distinguishing-string test: no string separates 11 and 22 since aa swaps them and bb sends both to 33.

EX 2Counting minimal states of common languages

Easy

Over {a,b}\{a, b\} the minimal DFAs (complete, dead state counted) have: "length divisible by 44": 44 states; "ends with abab": 33; "contains no aaaa": 33 (the third state is the dead state reached after aaaa); "at least two aa or at least one bb": 33; "the second symbol is aa": 44 (start, after the first symbol, accepting, dead); "the number of aa is divisible by 33 and the number of bb is odd": 3⋅2=63 \cdot 2 = 6. These numbers were recomputed from the definition of the futures.

EX 3Eight states to five

Medium

DFA over {0,1}\{0, 1\}, start AA, accepting {C}\{C\}:

stateon 00on 11
AABBFF
BBGGCC
CCAACC
DDCCGG
EEHHFF
FFCCGG
GGGGEE
HHGGCC

Step 1: DD is unreachable (no transition enters DD), remove it: seven states. Step 2: round 00: {C}\{C\} and {A,B,E,F,G,H}\{A, B, E, F, G, H\}. Round 11 (look at the group of the targets): A→(B,F)A \to (B, F) = (rest, rest); B→(G,C)B \to (G, C) = (rest, CC); E→(H,F)E \to (H, F) = (rest, rest); F→(C,G)F \to (C, G) = (CC, rest); G→(G,E)G \to (G, E) = (rest, rest); H→(G,C)H \to (G, C) = (rest, CC). So the rest splits into {A,E,G}\{A, E, G\}, {B,H}\{B, H\} and {F}\{F\}. Round 22 (groups now {A,E,G}\{A, E, G\}, {B,H}\{B, H\}, {C}\{C\}, {F}\{F\}): A→(B,F)A \to (B, F) lands in ({B,H}\{B, H\}, {F}\{F\}), E→(H,F)E \to (H, F) lands in the same pair of groups, but G→(G,E)G \to (G, E) lands in ({A,E,G}\{A, E, G\}, {A,E,G}\{A, E, G\}). So GG leaves the group, giving {A,E}\{A, E\}, {B,H}\{B, H\}, {C}\{C\}, {F}\{F\}, {G}\{G\}. Round 33 changes nothing. The minimal DFA has 55 states. A distinguishing string for AA and GG is 0101: from AA it goes A→B→CA \to B \to C (accepted), from GG it goes G→G→EG \to G \to E (rejected); this is why the pair is marked at level 22 in table filling, while {A,E}\{A, E\} and {B,H}\{B, H\} stay unmarked.

EX 4Minimise after the subset construction

Medium

For the NFA of "contains 0000 or 1111" the subset construction gave 55 states; two of them, {a,s,t}\{a, s, t\} and {b,s,t}\{b, s, t\}, have the same future (both are accepting-trap states), so minimisation gives 44 (subset construction). This two-step pipeline, subset construction then minimisation, is how a regular expression becomes a small scanner DFA.

EX 5Typical questions

GATE level

(a) "A DFA has nn states; after minimisation how many can remain?" Any number from 11 to nn. (b) "Is the minimal DFA unique?" Yes, up to renaming. (c) "Which is true of equivalent states?" They have the same future: no string distinguishes them; they need not be "equal-looking". (d) "Complement of a minimal DFA": swapping accepting and non-accepting states of a complete minimal DFA gives a minimal DFA of the complement, with the same number of states. (e) "Minimal DFA for LL and for its complement" have the same number of states. (f) "Does the DFA obtained by the subset construction need minimisation?" Not always, but it may (the example above). (g) "The minimal DFA of a finite language" has a dead state and is acyclic apart from the dead state's loops.

Cheat box

Cheat box

  • Equivalent states: no string distinguishes them. Distinguishable: some string is accepted from exactly one.
  • Steps: remove unreachable, complete, refine partition (accepting versus not first, then by target groups), merge.
  • Table filling: mark accepting versus non-accepting; mark {p,q}\{p, q\} if some symbol leads to a marked pair; unmarked pairs are equivalent. Level = length of the shortest distinguishing string.
  • Minimal DFA is unique up to renaming; it has the fewest states; dead state counts (complete DFA).
  • Complement keeps the minimal size; the same language has one minimal DFA but many DFAs.
  • Moore: O(n2∣Σ∣)O(n^2 |\Sigma|); Hopcroft: O(∣Σ∣nlog⁡n)O(|\Sigma| n \log n). NFAs have no unique minimal form.

Traps and GATE patterns

Connections

The subset construction produces the DFAs that minimisation reduces (subset construction); the minimal DFA is the object counted by the Myhill-Nerode theorem (Myhill-Nerode); closure constructions such as product and reversal create DFAs whose minimal sizes are asked in GATE (closure properties); scanner generators minimise their DFAs (lexical analysis).

PYQs

14 previous year questions from your book. I re-solved each one myself (14 by running or simulating, 0 by reasoning only); the book's key is shown next to my answer. All PYQs

GATE 2025 · Set 1 · NAT · 2 marksQ8 · page 198 of the book
Consider a finite state machine (FSM) with one input X
and one output f, represented by the given state transition
table. The minimum number of states required to realize
this FSM is ________. (Answer in integer)
GATE 2025 · Set 2 · NATQ11 · page 198 of the book
Let Σ = {1,2,3,4}. For x ∈ Σ* , let prod(x) be the product of
symbols in x modulo 7. We take prod(ε) =1,where ε is the
null string .
For example, prod(124) = (1 × 2 × 4) mod 7 = 1.
Define L = {x ∈ Σ* | prod(x) = 2}.
The number of states in a minimum state DFA for L is
___________. (Answer in integer)
GATE 2024 · Set 1 · MSQ · 2 marksQ12 · page 198 of the book
Consider the 5-state DFA M accepting the language L(M) ⊂
(0 + 1) * shown below. For any string w ∈ (0 + 1) * let n0(w)
be the number of 0 ' s in w and n1(w) be the number of 1's
in w.

Which of the following statements is/are FALSE?
  • (a)States 2 and 4 are distinguishable in M
  • (b)States 3 and 4 are distinguishable in M
  • (c)States 2 and 5 are distinguishable in M
  • (d)Any string w with n0 (w) = n1(w) is in L(M).
GATE 2023 · NAT · 2 marksQ19 · page 199 of the book
Consider the language L over the alphabet {0, 1}, given
below: L = {w ∈ {0, 1}* | w does not contain three or more
consecutive 1's}. The minimum number of states in a
Deterministic Finite-State Automaton (DFA) for L is _____.

THEORY OF COMPUTATION
GATE 2020 · NAT · 2 marksQ22 · page 200 of the book
Consider the following language.
L = {x ε {a,b}* | number of a's in x is divisible by 2 but
not divisible by 3}. The minimum number of states in a
DFA that accepts L is _______.
GATE 2019 · NAT · 2 marksQ27 · page 200 of the book
Let    Σ      be
the
set
of
all
bijections
from {1, ... ,5} to {1, ... ,5}, where id denotes the identity
function, i.e. id(j) = j, ∀j. Let ∘ denote composition on
functions.
For
a
string x= x1x2 ... xn∈Σn, n≥0,
let π(x) = x1 ∘x2 ∘⋯∘xn. Consider the language L=
{x∈Σ*|π(x) = id}. The minimum number of states in
any DFA accepting L is _______

THEORY OF COMPUTATION
GATE 2017 · MCQ · 1 markQ30 · page 201 of the book
The minimum possible number of states of a deterministic
finite automaton that accepts the regular language
L = {w1aw2 | w1, w2 ∈ {a,b}*, |w1| = 2,|w2| ≥ 3} is
_________
  • (a)8
  • (b)9
  • (c)10
  • (d)11
year not read yetQ33 · page 201 of the book
Consider
the
language
L
given
by
the
regular
expression (a+b)*b(a+b) over
the
alphabet
{a,b}.
The smallest number of states needed in deterministic finite-
state automaton (DFA) accepting L is _________
GATE 2016 · Set 2 · NAT · 1 markQ38 · page 202 of the book
The number of states in the minimum sized DFA that
accepts the language defined by the regular expression
(0+1)*(0+1)(0+1)*is_________.
GATE 2015 · Set 1 · MCQ · 2 marksQ39 · page 202 of the book
Consider the DFAs M and N given above. The number of
states in a minimal DFA that accepts the language
 L(M) ∩ L(N) is __________.
  • (a). 1
  • (b). 2
  • (c). 3
  • (d). 4
GATE 2015 · Set 2 · MCQ · 2 marksQ41 · page 202 of the book
The number of states in the minimal deterministic finite
automaton corresponding to the regular expression
 (0 + 1) * (10) is __________
  • (a)3
  • (b)4
  • (c)5
  • (d)6
GATE 2013 · Set 1 · MCQ · 2 marksQ49 · page 203 of the book
Consider the DFA given.

Which of the following are FALSE?
1. Complement of L(A) is context-free.
2. L(A) = L((11*0+0)(0 + 1)*0*1*)
3. For the language accepted by A, A is the minimal
DFA.
4. A accepts all strings over {0, 1} of length at least 2.
  • (a)1 and 3 only
  • (b)2 and 4 only
  • (c)2 and 3 only
  • (d)3 and 4 only
GATE 2011 · MCQ · 2 marksQ53 · page 204 of the book
A deterministic finite automation (DFA) D with alphabet
Σ = {a, b} is given below.

Which of the following finite state machines is a valid
minimal DFA which accepts the same language as D?
  • (a). THEORY OF COMPUTATION
  • (b).
  • (c).
  • (d).
GATE 2011 · MCQ · 2 marksQ54 · page 205 of the book
Definition of a language L with alphabet {a} is given as
following. L = {ank | k > 0, and n is a positive integer
constant} What is the minimum number of states needed
in a DFA to recognize L?
  • (a)k+1
  • (b)n+1
  • (c)2 n+1
  • (d)2 k+1

Self-check

Question 1

A complete DFA has 66 reachable states and its round-00 partition is {q1,q2}\{q_1, q_2\} against {q3,q4,q5,q6}\{q_3, q_4, q_5, q_6\}. Can the minimal DFA have more than 66 states?

Show answer

No. The minimal DFA has at most as many states as the reachable part of the DFA, so at most 66.

Question 2

Why must unreachable states be removed before the partition is refined?

Show answer

They are not states of the minimal DFA (no string leads to them). Keeping them could add groups that do not belong to the machine.

Question 3

What does the number written in a table-filling cell mean?

Show answer

The length of the shortest string that is accepted from one of the two states and rejected from the other.

Question 4

A complete minimal DFA for LL has mm states. How many states does the minimal DFA for the complement of LL have?

Show answer

mm: swap accepting and non-accepting states; the pairs remain distinguishable (the same strings distinguish them).

Question 5

The minimal DFA for "the number of aa is divisible by 33 and the number of bb is odd" has how many states?

Show answer

66: the 3⋅23 \cdot 2 combinations of the two remainders are pairwise distinguishable.

Revision card

One-screen revision

  • Remove unreachable, complete, split by acceptance, then by target groups until stable, merge.
  • Table filling marks distinguishable pairs; level = shortest separating string; unmarked pairs are equivalent.
  • Minimal DFA unique up to renaming; dead state counts; complement keeps the size.
  • Not for NFAs.

References

  • ·Hopcroft, Motwani, Ullman, Introduction to Automata Theory, Languages, and Computation (3rd edition), Section 4.4 (equivalence and minimisation of automata, the table-filling algorithm)
  • ·Sipser, Introduction to the Theory of Computation (3rd edition), Problem 1.52 and the Myhill-Nerode discussion (minimal DFA)
  • ·Aho, Lam, Sethi, Ullman, Compilers: Principles, Techniques, and Tools (2nd edition), Section 3.9.6 (minimising the number of states of a DFA)

Verification

scripts/enum-checks/toc_regular.py: on 400 random DFAs (up to 5 states) the minimal DFA is equivalent to the original, has exactly as many states as there are distinct futures among the reachable states (all suffixes shorter than n tried), has every pair of states separated, and the table-filling level of every pair equals the length of the SHORTEST separating string found by breadth-first search; on 200 more, a DFA and a bigger equivalent DFA (the product with itself) have the same minimal DFA up to renaming. The seven-state and eight-state examples and every state count quoted in the worked examples were recomputed from futures. Running times and the statement about NFA minimisation are textbook results quoted, not proved here (needs verification). Textbook chapter references are from memory. SECOND PASS (2026-11-02, done by the assistant, not a human check): every Self-check question was solved before the printed answer was read and all agreed; the definitions, worked examples, cheat box and traps were read claim by claim and the numbers re-derived by hand or by a small script (state counts, derivations, parse-tree and move counts, decomposition counts); tables and animations are machine output and were read, not re-run; No other defect found. Status raised to self-checked; verified needs a textbook or human check.

last verified: never