State Minimization
Section 2.5
Fri, Oct 7, 2005
Minimizing a DFA
To minimize a DFA is to find an equivalent DFA that
has the least possible number of states.
If the DFA is going to be used to write a program
(e.g., a compiler) or to design hardware, then there
may be a significant benefit in minimizing it before
implementing it.
Indistinguishable States
Let M be a DFA. Two states p and q are called
indistinguishable if the DFA obtained by making p
the initial state is equivalent to the DFA obtained by
making q the initial state.
Write p ≡ q.
This is an equivalence relation on K.
Why?
Distinguishing States
We say that a string w distinguishes states p and q if
(p, w) M* (f, e), for some final state f, and
(q, w) M* (u, e) for some nonfinal state u,
or vice versa.
Therefore, two states are indistinguishable if there is
no string that distinguishes them.
Minimizing a DFA
The problem is to determine which states are
distinguishable and which are indistinguishable.
To minimize a DFA, we want to identify its
equivalence classes of indistinguishable states and
replace them with single states.
The Relation ≡n
Let p and q be states. Define the relation
p ≡n q
to mean that p and q are not distinguishable by any
string w with |w| n.
That is, no sequence of up to n moves will distinguish
p and q.
This, too, is an equivalence relation.
Clearly, p ≡ 0 q if and only if p, q F or p, q F.
Properties of ≡n
The following are obvious:
For all n 0, if p ≡ q, then p ≡n q.
For all n 0, if p ≡n q then p ≡ q.
For all n 1, if p ≡n q, then p ≡n – 1 q.
But it is not the case that if p ≡n – 1 q, then p ≡n q.
Another Property of ≡n
Theorem: For any two states p and q and any n 1,
p ≡n q if and only if
p ≡n – 1 q, and
for all a Σ, δ(p, a) ≡n – 1 δ(q, a).
This theorem characterizes the relation ≡n entirely in
terms of the relation ≡n – 1 and the function .
It leads to an algorithm to determine which states are
indistinguishable.
The Minimization Algorithm
Initialize the equivalence classes for ≡0 as F and K –
F.
For n = 0, 1, 2, …, compute the equivalence classes
of ≡n from ≡n – 1 and , as described in the previous
theorem.
Repeat this until, for some n, the classes of ≡n are the
same as the classes of ≡n – 1.
This must eventually happen.
Why?
The Minimization Algorithm
At that point, the equivalence classes of ≡n are the
equivalence classes of ≡.
Why?
Replace each equivalence class of states under ≡ by a
single state.
Example of Minimization
Minimize the following DFA.
a
b b a b
2 3 4 5 6
a a b a a
b
1
a
a a
b
b b
7 8 9 10
b
a, b
Example: The ≡0 Partition
The relation ≡0 partitions K into two classes.
{1, 2, 3, 4, 5, 6, 7, 8, 9}, {10}
Example: The ≡1 Partition
1 2 3 4 5 6 7 8 9 10
a 2 6 8 5 10 10 2 5 4 10
b 7 3 9 3 7 3 9 7 10 10
Apply the “a-transitions” to each class:
{2, 6, 8, 5, 10, 10, 2, 5, 4}, {10}
Apply the “b-transitions” to each class:
{7, 3, 9, 3, 7, 3, 9, 7, 10}, {10}
Example: The ≡1 Partition
The a-transitions indicate that 5 and 6 are in a
different class than 1, 2, 3, 4, 7, 8, and 9.
The b-transitions indicate that 9 is in a different class
than 1, 2, 3, 4, 5, 6, 7, and 8.
The partition of ≡1 is
{1, 2, 3, 4, 7, 8}, {5, 6}, {9}, {10}
Example: The ≡2 Partition
Apply the a-transitions to these classes:
{2, 6, 8, 5, 2, 5}, {10, 10}, {4}, {10}
Apply the b-transitions to these classes:
{7, 3, 9, 3, 9, 7}, {7, 3}, {10}, {10}
The a-transitions split {1, 2, 3, 4, 7, 8} into {1, 3, 7}
and {2, 4, 8}.
The b-transitions split {1, 2, 3, 4, 7, 8} into {1, 2, 4,
8} and {3, 7}.
Example: The ≡2 Partition
Combining these, we get the ≡2 partition
{1}, {3, 7}, {2, 4, 8}, {5, 6}, {9}, {10}.
Apply the a-transitions to these classes:
{2}, {8, 2}, {6, 5, 5}, {10, 10}, {4}, {10}.
Apply the b-transitions to these classes:
{7}, {9, 9}, {3, 3, 7}, {7, 3}, {10}, {10}.
This produces no new classes.
Example: The ≡3 Partition
Therefore, these are the classes of ≡, namely
{1}, {2, 4, 8}, {3, 7}, {5, 6}, {9}, {10}.
Example of Minimization
Combine states 2, 4, and 8 into one state.
a
b b a b
2 3 4 5 6
a a b a a
b
1
a
a a
b
b b
7 8 9 10
b
a, b
Example of Minimization
Combine states 2, 4, and 8 into one state.
a
b b a b
2 3 4 5 6
a a b a a
b
1
a
a a
b
b b
7 8 9 10
b
a, b
Example of Minimization
Combine states 3 and 7 into one state.
a
b b a b
2 3 4 5 6
a a b a a
b
1
a
a a
b
b b
7 8 9 10
b
a, b
Example of Minimization
Combine states 5 and 6 into one state.
a
b b a b
2 3 4 5 6
a a b a a
b
1
a
a a
b
b b
7 8 9 10
b
a, b
Example of Minimization
Replace each of these classes with a single class.
a
248 56 a, b
a
a
b
1 b a 10
a
b
b
37 9
b
Example of Minimization
Now we can see that the language of this DFA is
{w *w contains aaa or bbb}.
Example
Find a minimal DFA that accepts the language
{w * | w contains 010 and 101}.