In automata theory (a branch of theoretical computer science), DFA minimization is the task of transforming a given deterministic finite automaton (DFA) into an equivalent DFA that has a minimum number of states. Here, two DFAs are called equivalent if they recognize the same regular language. Several different algorithms accomplishing this task are known and described in standard textbooks on automata theory.
Minimal DFA For each regular language, there exists a minimal deterministic automaton that accepts it, that is, a DFA with a minimum number of states. By the Myhill-Nerode theorem, this DFA is unique (except that states can be given different names). The minimal DFA ensures minimal computational cost for tasks such as pattern matching. There are three classes of states that can be removed or merged from the original DFA without affecting the language it accepts.
Unreachable states are the states that are not reachable from the initial state of the DFA, for any input string. These states can be removed. Dead states are the states from which no final state is reachable. These states can be removed unless the automaton is required to be complete. Nondistinguishable states are those that cannot be distinguished from one another for any input string. These states can be merged. DFA minimization is usually done in three steps:
remove dead and unreachable states (this will accelerate the following step), merge nondistinguishable states, optionally, re-create a single dead state ("sink" state) if the resulting DFA is required to be complete.
Unreachable states Given a DFA M=(Q,Σ,δ,q0,F), a state q∈Q is reachable if there exists an input string w∈Σ∗ that terminates at state q. That is, δ∗(q0,w)=q. A state q is unreachable if it is not a reachable state. In the definition above:
Q is the set of states, Σ is the set of input symbols, δ:Q×Σ→Q is the transition function, δ∗:Q×Σ∗→Q is the extended transition function, q0 is the initial state, and F is the set of accepting (or final) states. Reachable states can be obtained with the following algorithm:
Assuming an efficient implementation of state sets and operations, this algorithm can be implemented with time complexity O(n+m), where n is the number of states and m is the number of transitions of the input automaton. Let R be the set of reachable states. The set of unreachable states is Q∖R, that is, the states unmarked by the algorithm. Unreachable states can be removed from the DFA without affecting the language that it accepts.
Nondistinguishable states The following algorithms present various approaches to merging nondistinguishable states.
Hopcroft's algorithm One algorithm for merging the nondistinguishable states of a DFA, due to Hopcroft (1971), is based on partition refinement, partitioning the DFA states into groups by their behavior. These groups represent equivalence classes of the Nerode congruence, whereby every two states are equivalent if they have the same behavior for every input sequence. That is, for every two states p1 and p2 that belong to the same block of the partition P, and every input word w, the transitions determined by w should always take states p1 and p2 to either states that both accept or states that both reject. It should not be possible for w to take p1 to an accepting state and p2 to a rejecting state or vice versa. The following pseudocode describes the form of the algorithm as given by Xu. Alternative forms have also been presented.
… excerpt ends here. Continue reading the full article.


