The.Algorithm.Design.Manual.Springer-Verlag.1998

The.Algorithm.Design.Manual.Springer-Verlag.1998 The.Algorithm.Design.Manual.Springer-Verlag.1998

18.04.2013 Views

Finite State Machine Minimization Next: Longest Common Substring Up: Set and String Problems Previous: Cryptography Finite State Machine Minimization Input description: A deterministic finite automaton M. Problem description: The smallest deterministic finite automaton M' such that M' behaves identically to M. Discussion: Problems associated with constructing and minimizing finite state machines arise repeatedly in software and hardware design applications. Finite state machines are best thought of as pattern recognizers, and minimum-size machines correspond to recognizers that require less time and space. Complicated control systems and compilers are often built using finite state machines to encode the current state and associated actions, as well as the set of possible transitions to other states. Minimizing the size of this machine minimizes its cost. Finite state machines are best thought of as edge-labeled directed graphs, where each vertex represents one of n states and each edge a transition from one state to the other on receipt of the alphabet symbol that labels the edge. The automaton above analyzes a given sequence of coin tosses, with the dark states signifying that an even number of heads have been observed. Automata can be represented using any graph data structure (see Section ), or by using an transition matrix, where is the size of the alphabet. file:///E|/BOOK/BOOK5/NODE207.HTM (1 of 4) [19/1/2003 1:32:15]

Finite State Machine Minimization Finite state machines are often used to specify search patterns in the guise of regular expressions, which are patterns formed by and-ing, or-ing, and looping over smaller regular expressions. For example, the regular expression matches any string on (a,b,c) that begins and ends with an a (including a itself). The best way to test whether a string is described by a given regular expression (especially if many strings will be tested) is to construct the equivalent finite automaton and then simulate the machine on the string. See Section for alternative approaches to string matching. We consider three different problems on finite automata: ● Minimizing deterministic finite state machines - Transition matrices for finite automata quickly become prohibitively large for sophisticated machines, thus fueling the need for tighter encodings. The most direct approach is to eliminate redundant states in the automaton. As the example above illustrates, automata of widely varying sizes can compute the same function. Algorithms for minimizing the number of states in a deterministic finite automaton (DFA) appear in any book on automata theory. The basic approach works by partitioning the states into gross equivalence classes and then refining the partition. Initially, the states are partitioned into accepting, rejecting, and other classes. The transitions from each node branch to a given class on a given symbol. Whenever two states , t in the same class C branch to elements of different classes, the class C must be partitioned into two subclasses, one containing , the other containing t. This algorithm makes a sweep though all the classes looking for a new partition, and repeating the process from scratch if it finds one. This yields an algorithm, since at most n-1 sweeps need ever be performed. The final equivalence classes correspond to the states in the minimum automaton. In fact, a more efficient, algorithm is known with available implementations discussed below. ● Constructing deterministic machines from nondeterministic machines - DFAs are simple to understand and work with, because the machine is always in exactly one state at any given time. Nondeterministic automata (NFAs) can be in more than one state at a time, so its current ``state'' represents a subset of all possible machine states. In fact, any NFA can be mechanically converted to an equivalent DFA, which can then be minimized as above. However, converting an NFA to a DFA can cause an exponential blowup in the number of states, which perversely might later be eliminated in the minimization. This exponential blowup makes automaton minimization problems NP-hard whenever you do not start with a DFA. The proofs of equivalence between NFAs, DFAs, and regular expressions are elementary enough to be covered in undergraduate automata theory classes. However, they are surprisingly nasty to implement, for reasons including but not limited to the exponential blowup of states. Implementations are discussed below. file:///E|/BOOK/BOOK5/NODE207.HTM (2 of 4) [19/1/2003 1:32:15]

Finite State Machine Minimization<br />

Finite state machines are often used to specify search patterns in the guise of regular expressions, which<br />

are patterns formed by and-ing, or-ing, and looping over smaller regular expressions. For example, the<br />

regular expression matches any string on (a,b,c) that begins and ends with an a<br />

(including a itself). <strong>The</strong> best way to test whether a string is described by a given regular expression<br />

(especially if many strings will be tested) is to construct the equivalent finite automaton and then<br />

simulate the machine on the string. See Section for alternative approaches to string matching.<br />

We consider three different problems on finite automata:<br />

● Minimizing deterministic finite state machines - Transition matrices for finite automata quickly<br />

become prohibitively large for sophisticated machines, thus fueling the need for tighter encodings.<br />

<strong>The</strong> most direct approach is to eliminate redundant states in the automaton. As the example above<br />

illustrates, automata of widely varying sizes can compute the same function.<br />

<strong>Algorithm</strong>s for minimizing the number of states in a deterministic finite automaton (DFA) appear<br />

in any book on automata theory. <strong>The</strong> basic approach works by partitioning the states into gross<br />

equivalence classes and then refining the partition. Initially, the states are partitioned into<br />

accepting, rejecting, and other classes. <strong>The</strong> transitions from each node branch to a given class on a<br />

given symbol. Whenever two states , t in the same class C branch to elements of different classes,<br />

the class C must be partitioned into two subclasses, one containing , the other containing t.<br />

This algorithm makes a sweep though all the classes looking for a new partition, and repeating the<br />

process from scratch if it finds one. This yields an algorithm, since at most n-1 sweeps need<br />

ever be performed. <strong>The</strong> final equivalence classes correspond to the states in the minimum<br />

automaton. In fact, a more efficient, algorithm is known with available implementations<br />

discussed below.<br />

● Constructing deterministic machines from nondeterministic machines - DFAs are simple to<br />

understand and work with, because the machine is always in exactly one state at any given time.<br />

Nondeterministic automata (NFAs) can be in more than one state at a time, so its current ``state''<br />

represents a subset of all possible machine states.<br />

In fact, any NFA can be mechanically converted to an equivalent DFA, which can then be<br />

minimized as above. However, converting an NFA to a DFA can cause an exponential blowup in<br />

the number of states, which perversely might later be eliminated in the minimization. This<br />

exponential blowup makes automaton minimization problems NP-hard whenever you do not start<br />

with a DFA.<br />

<strong>The</strong> proofs of equivalence between NFAs, DFAs, and regular expressions are elementary enough<br />

to be covered in undergraduate automata theory classes. However, they are surprisingly nasty to<br />

implement, for reasons including but not limited to the exponential blowup of states.<br />

Implementations are discussed below.<br />

file:///E|/BOOK/BOOK5/NODE207.HTM (2 of 4) [19/1/2003 1:32:15]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!