Theory of Computation & Computer Graphics β Introduction to Finite Automata, NEC licence examination syllabus (Nepal Engineering Council).
Minimization of Finite State Machines
Every regular language has exactly one smallest DFA β and there is an algorithm that finds it.
π Where this lives: Minimization matters wherever a state machine is burned into hardware. A finite state machine implemented in a digital circuit needs βlogβ nβ flip-flops for n states, so cutting 5 states to 3 can mean 3 flip-flops instead of 2 β and in a controller replicated a million times on a chip, or in a lookup table that must fit in cache, those savings compound. The same algorithm compresses the DFA tables inside regular expression engines and protocol validators. Search "state minimization sequential circuit design flip-flop count".
Equivalence and the algorithm
TWO STATES ARE EQUIVALENT IF NO INPUT STRING CAN TELL THEM
APART.
FORMALLY: states p and q are EQUIVALENT (written p β‘ q) if for
EVERY string w β Ξ£*,
Ξ΄Μ(p, w) β F βΊ Ξ΄Μ(q, w) β F
β starting from p and from q, the same strings are accepted.
If some string w leads one to an accepting state and the other
to a non-accepting state, that w DISTINGUISHES them.
THE k-EQUIVALENCE HIERARCHY, which is what the algorithm
actually computes:
p β‘β q if p and q are both accepting or both non-accepting
p β‘β q if no string of length β€ k distinguishes them
THE SEQUENCE STABILISES: once β‘β = β‘βββ, no further refinement
can occur, and that relation is β‘. With n states this happens
within nβ1 rounds, so the algorithm always terminates.
ββ WHY MINIMIZATION IS WELL DEFINED ββββββββββββββββββββββββ
THE MYHILL-NERODE THEOREM underwrites the whole topic:
A language L is regular if and only if the relation
x β‘_L y βΊ βz: (xz β L βΊ yz β L)
has FINITELY MANY equivalence classes; and the number of
classes is EXACTLY the number of states in the minimal DFA.
TWO CONSEQUENCES WORTH STATING:
1. THE MINIMAL DFA IS UNIQUE UP TO RENAMING OF STATES. This
is unusual and powerful β most computational models have
no canonical smallest form, but DFAs do.
2. IT GIVES A METHOD FOR PROVING NON-REGULARITY: exhibit
infinitely many pairwise distinguishable strings, and the
language cannot be regular. For {aβΏbβΏ}, the strings
a, aa, aaa, β¦ are pairwise distinguishable (aβ± and aΚ² are
separated by bβ±), so infinitely many classes exist and
no DFA can have them all.
ββ THE TABLE-FILLING ALGORITHM (MOORE'S ALGORITHM) βββββββββ
THE STANDARD EXAM METHOD.
STEP 1 β REMOVE UNREACHABLE STATES. Any state not reachable
from the start state contributes nothing and is deleted
first. THIS STEP IS ROUTINELY FORGOTTEN AND COSTS MARKS.
STEP 2 β Draw a table with one cell for each unordered pair
of states.
STEP 3 β MARK every pair (p,q) where exactly one of p, q is
accepting. These are distinguished by Ξ΅, the empty string.
STEP 4 β REPEAT until no change: for each unmarked pair
(p,q) and each symbol a, if the pair (Ξ΄(p,a), Ξ΄(q,a)) is
MARKED, then mark (p,q).
STEP 5 β Every pair still UNMARKED is a pair of EQUIVALENT
states. Merge each equivalence class into one state.
THE LOGIC OF STEP 4: if some string w distinguishes the
successors, then the string aw distinguishes p and q β because
reading a takes them to the successors, after which w
separates them.
ββ A FULLY WORKED MINIMIZATION βββββββββββββββββββββββββββββ
DFA with states A, B, C, D, E; alphabet {0,1}; start A;
accepting {D}:
STATE 0 1
βββββββββββββββββ
βA B C
B B D
C B C
D B E
E B C
βββββββββββββββββ
ROUND 0 β mark pairs differing in acceptance. Only D accepts:
MARKED: (A,D), (B,D), (C,D), (D,E)
ROUND 1 β examine each unmarked pair:
(A,B): on 1 β (C,D), which is MARKED β MARK (A,B)
(A,C): on 0 β (B,B) same; on 1 β (C,C) same β leave
(A,E): on 0 β (B,B); on 1 β (C,C) β leave
(B,C): on 1 β (D,C), MARKED β MARK (B,C)
(B,E): on 1 β (D,C), MARKED β MARK (B,E)
(C,E): on 0 β (B,B); on 1 β (C,C) β leave
ROUND 2 β no further changes. STOP.
UNMARKED PAIRS: (A,C), (A,E), (C,E)
These form ONE equivalence class {A, C, E}.
THE PARTITION IS: { A, C, E }, { B }, { D }
VERIFY BY INSPECTION β A, C and E behave identically:
A: on 0 β B, on 1 β C
C: on 0 β B, on 1 β C
E: on 0 β B, on 1 β C
Identical successors, so no string can separate them.
THE MINIMAL DFA, writing the merged class as P:
STATE 0 1
βββββββββββββββββ
βP B P
B B D
D B P
βββββββββββββββββ
accepting: D
FIVE STATES REDUCED TO THREE. The language, incidentally, is
"binary strings ending in 01", and three states is exactly
what that needs β one for each amount of progress toward the
pattern:
P no 0 pending at the end (nothing useful seen yet)
B the last symbol was a 0, so a 1 now completes "01"
D "01" has just been completed β ACCEPT
THIS IS THE MINIMIZATION RESULT MADE CONCRETE: the original
five states carried the same three pieces of information
between them, with A, C and E all meaning "no 0 pending".
Partition refinement, and what minimization is good for
ββ THE PARTITION REFINEMENT VIEW βββββββββββββββββββββββββββ
The same computation seen top-down rather than pair-by-pair,
and it is faster to execute by hand on larger machines:
START with the partition { non-accepting states },
{ accepting states }.
REPEAT: split any block whose members send different symbols
into different blocks.
STOP when no block splits.
ON THE SAME EXAMPLE:
Pβ = { A, B, C, E } , { D }
Refine: on 1, B goes to D (block 2) while A, C, E go to C
(block 1). So B separates.
Pβ = { A, C, E } , { B } , { D }
Refine again: A, C, E all go to B on 0 and to block {A,C,E}
on 1 β no split.
Pβ = Pβ, so STOP.
THREE BLOCKS = THREE STATES, agreeing with the table method.
HOPCROFT'S ALGORITHM is the refined version, running in
O(n log n) rather than the O(nΒ²) of naive table filling β
the asymptotically best known, and what production tools use.
ββ WHY MINIMIZE ββββββββββββββββββββββββββββββββββββββββββββ
1. HARDWARE COST. n states need βlogβ nβ flip-flops.
5 states β βlogβ 5β = 3 flip-flops
3 states β βlogβ 3β = 2 flip-flops
A saving of one flip-flop per instance, plus the
combinational logic driving it.
2. MEMORY AND SPEED. A smaller transition table fits in cache;
for a lexer run over megabytes of source, that is a
measurable difference.
3. EQUIVALENCE TESTING β the most theoretically important use.
TO DECIDE WHETHER TWO DFAs ACCEPT THE SAME LANGUAGE,
MINIMIZE BOTH AND CHECK WHETHER THE RESULTS ARE ISOMORPHIC.
Because the minimal DFA is UNIQUE, this is a complete
decision procedure β and it is the reason the uniqueness
result matters rather than being a curiosity.
4. VERIFICATION. Protocol and circuit equivalence checking
reduces to exactly this.
5. UNDERSTANDING. The minimal machine reveals what the
language actually requires the machine to remember, with
all redundancy stripped away.
ββ THE COMMON MISTAKES βββββββββββββββββββββββββββββββββββββ
Β· FORGETTING TO REMOVE UNREACHABLE STATES FIRST. The
algorithm will happily merge unreachable states with
others and give a machine that is correct but not minimal
β or leave them in place entirely.
Β· Assuming that states with the same OUTGOING SYMBOLS are
equivalent. Equivalence is about WHERE the transitions
lead, over all future strings, not about which symbols are
accepted.
Β· Forgetting that a DFA must be COMPLETE. If the given
machine has missing transitions, add a DEAD (trap) state
with all transitions to itself before minimizing β
otherwise Ξ΄ is not a total function and the algorithm's
assumptions fail.
Β· Merging an accepting with a non-accepting state. They are
distinguished by Ξ΅ and are marked in round 0; if this
happens, the marking was done wrongly.
ββ THE PLACE OF THIS RESULT ββββββββββββββββββββββββββββββββ
Combining this topic with the previous one gives a complete
computational picture of regular languages:
REGULAR EXPRESSION
β (Thompson's construction)
Ξ΅-NFA
β (subset construction)
DFA
β (minimization)
MINIMAL DFA β UNIQUE, and a CANONICAL FORM for the
language
EVERY REGULAR LANGUAGE HAS A UNIQUE CANONICAL REPRESENTATIVE
THAT CAN BE COMPUTED MECHANICALLY. That is why questions about
regular languages β equivalence, emptiness, finiteness β are
all DECIDABLE, in sharp contrast to the same questions for
context-free languages and Turing machines later in this
section.
The minimal DFA is unique up to renaming β an unusual property that most computational models lack β and it is what makes DFA equivalence decidable: minimize both machines and check whether the results are isomorphic. That is a complete decision procedure, and it is why the uniqueness result is more than a curiosity.
π Go further: The uniqueness of the minimal DFA is the foundation of automata learning β algorithms that infer a machine purely from observing its behaviour. Dana Angluin's L* algorithm asks two kinds of question ("is this string accepted?" and "is this hypothesis machine correct?") and provably converges on the minimal DFA, because there is exactly one to converge on. This is used today to reverse-engineer undocumented network protocol implementations and to check that a bank card or TLS library actually implements the state machine its specification describes β several real security flaws have been found by learning the machine a device implements and comparing it with the one it should. Search "Angluin L-star automata learning protocol state machine inference".
π‘ Exam angle: define equivalent states formally and state the MyhillβNerode theorem with its consequence that the minimal DFA is unique. The guaranteed question is to minimize a given DFA: remove unreachable states, draw the pair table, mark by acceptance in round 0, then propagate marks through successors until stable, and merge the unmarked pairs. Show the resulting transition table and state the reduction (e.g. 5 β 3). Know the partition refinement alternative and that Hopcroft's algorithm runs in O(n log n). List the uses β hardware cost via βlogβ nβ flip-flops, and especially equivalence testing.
Syllabus points
Equivalent & distinguishable states
Minimization by partitioning (numerical)
Create a free account to tick topics off, take notes as you read, watch the video lessons and get a day-by-day study plan built around your exam date.