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 be a DFA and extend to strings as .
- Two states are equivalent, written , if for every string : .
- They are distinguishable if some string (a distinguishing string) is accepted from exactly one of them. is an equivalence relation.
- A state is reachable if some string leads to it from .
- The minimal DFA of is a complete DFA for with the fewest states. Its states are the equivalence classes of the reachable states of any complete DFA for :
- Theorem. The minimal DFA is unique up to renaming of states, and no DFA for 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
- Remove unreachable states (search from ). They never matter.
- Make the DFA complete (add a dead state if some transition is missing).
- 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.
- 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 , two states are in the same group exactly when no string of length at most distinguishes them. Round uses the empty string; round prepends one symbol. At most rounds split anything, because every round that splits increases the number of groups, which cannot exceed .
Example 1: a DFA with a useless parity bit
The first DFA below recognises "ends with " but also remembers whether the number of symbols read is even or odd (states and ), and has a state that nothing leads to. It has states, reachable.
A DFA for 'ends with 01' with a useless parity bit (7 states, one unreachable): start
Simulated, not typedDouble circle = accepting state. Arrow from nowhere = start state.
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.
Run the rounds. After the unreachable state is dropped, round separates the accepting states from the rest. Round looks at where the states of the big group go on and on and splits it into and . Round changes nothing, so we stop with three groups.
Minimisation by partition refinement: start
Computed by a script, not typed| round | groups 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.
Merging the groups gives the minimal DFA: three states, the usual DFA for "ends with ".
The minimal DFA of the same language (3 states): start
Simulated, not typedDouble circle = accepting state. Arrow from nowhere = start state.
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.
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.
- Mark a pair when exactly one of the two states is accepting (the empty string distinguishes them). These are the level- pairs.
- Mark a pair at level if for some symbol the pair was marked at level (so followed by that pair's distinguishing string distinguishes and ).
- 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| q0e | q0o | q1e | q1o | q2e | |
|---|---|---|---|---|---|
| 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.
In this table the pairs , and stay empty: the parity bit never changes the future of a string, because "ends with " 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 rounds of work: . Hopcroft's algorithm needs . (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 " machine on three states is minimal because its three states have different futures.
Worked examples
EX 1Which states can be merged
EasyA complete DFA has states , start , accepting . Round gives and . If , , , , then on both stay in and on both go to : no split, so and the minimal DFA has states. Check with a distinguishing-string test: no string separates and since swaps them and sends both to .
EX 2Counting minimal states of common languages
EasyOver the minimal DFAs (complete, dead state counted) have: "length divisible by ": states; "ends with ": ; "contains no ": (the third state is the dead state reached after ); "at least two or at least one ": ; "the second symbol is ": (start, after the first symbol, accepting, dead); "the number of is divisible by and the number of is odd": . These numbers were recomputed from the definition of the futures.
EX 3Eight states to five
MediumDFA over , start , accepting :
| state | on | on |
|---|---|---|
Step 1: is unreachable (no transition enters ), remove it: seven states. Step 2: round : and . Round (look at the group of the targets): = (rest, rest); = (rest, ); = (rest, rest); = (, rest); = (rest, rest); = (rest, ). So the rest splits into , and . Round (groups now , , , ): lands in (, ), lands in the same pair of groups, but lands in (, ). So leaves the group, giving , , , , . Round changes nothing. The minimal DFA has states. A distinguishing string for and is : from it goes (accepted), from it goes (rejected); this is why the pair is marked at level in table filling, while and stay unmarked.
EX 4Minimise after the subset construction
MediumFor the NFA of "contains or " the subset construction gave states; two of them, and , have the same future (both are accepting-trap states), so minimisation gives (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 states; after minimisation how many can remain?" Any number from to . (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 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 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: ; Hopcroft: . NFAs have no unique minimal form.
Traps and GATE patterns
Connections
Builds on
Unlocks
Across subjects
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
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)
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)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).
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 COMPUTATIONConsider 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 _______.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 COMPUTATIONThe 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
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 _________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_________.
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
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
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
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).
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 reachable states and its round- partition is against . Can the minimal DFA have more than states?
Show answerHide
No. The minimal DFA has at most as many states as the reachable part of the DFA, so at most .
Question 2
Why must unreachable states be removed before the partition is refined?
Show answerHide
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 answerHide
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 has states. How many states does the minimal DFA for the complement of have?
Show answerHide
: swap accepting and non-accepting states; the pairs remain distinguishable (the same strings distinguish them).
Question 5
The minimal DFA for "the number of is divisible by and the number of is odd" has how many states?
Show answerHide
: the 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
My notes (saved in this browser)