# 1 Chapter 11 - 3 Constructing Efficient Finite Automata

date post

19-Jan-2018Category

## Documents

view

217download

0

Embed Size (px)

description

### Transcript of 1 Chapter 11 - 3 Constructing Efficient Finite Automata

1 Chapter Constructing Efficient Finite Automata 2 Section 11.3 Constructing Efficient Finite Automata First well see how to transform an NFA into a DFA. Then well see how to transform a DFA into a minimum-state DFA. Transforming an NFA into a DFA The -closure of a state s, denoted (s), is the set consisting of s together with all states that can be reached from s by traversing -edges. The -closure of a set S of states, denoted (S), is the union of the -closures of the states in S. 3 Example Given the following NFA as a graph and as a transition table. Some sample -closures for the NFA are as follows: (0) = {0, 1, 2} (1) = {1, 2} (2) = {2} ( ) = ({1, 2}) = {1, 2} ({0, 1, 2}) = {0, 1, 2}. 4 Algorithm: Transform an NFA into a DFA Construct a DFA table TD from an NFA table TN as follows: 1. The start state of the DFA is (s), where s is the start state of the NFA. 2. If {s 1, , s n } is a DFA state and a A, then T D ({s 1, , s n }, a) = (T N (s 1, a) T N (s n, a)). 3. A DFA state is final if one of its elements is an NFA final state. 5 Example Given the following NFA 6 Solution The algorithm constructs the following DFA transition table T D, where it is also written in simplified form after a renumbering of the states 7 Quiz Use the algorithm to transform the following NFA into a DFA 8 Solution The algorithm constructs the following DFA transition table T D, where it is also written in simplified form after a renumbering of the states. 9 Transforming an DFA into a minimum-state DFA Let S be the set of states that can be reached from the start state of a DFA over A. For states s, t S let s ~ t mean that for all strings w A* either T(s, w) and T(t, w) are both final or both nonfinal. Observe that ~ is an equivalence relation on S. So it partitions S into equivalence classes. Observe also that the number of equivalence classes is the minimum number of states needed by a DFA to recognize the language of the given DFA. 10 Algorithm Transform a DFA to a minimum-state DFA 1. Construct the following sequence of sets of possible equivalent pairs of distinct states: E 0 E 1 E k = E k+1, where E 0 = {{s, t} | s and t are either both final or both nonfinal} and E i+1 = {{s, t} E i | {T(s, a), T(t, a)} E i or T(s, a) = T(t, a)} for every a A}. E k represents the distinct pairs of equivalent states from which ~ can be generated. 2. The equivalence classes form the states of the minimum state DFA with transition table T min defined by T min ([s], a) = [T(s, a)]. 3. The start state is the class containing the start state of the given DFA. 4. A final state is any class containing a final state of the given DFA. 11 Example Use the algorithm to transform the following DFA into a minimum-state DFA. 12 Solution The set of states is S = {0, 1, 2, 3, 4}. To find the equivalent states calculate: E 0 = {{0, 4}, {1, 2}, {1, 3}, {2, 3}} E 1 = {{1, 2}, {1, 3}, {2, 3}} E 2 = {{1, 2}, {1, 3}, {2, 3}} = E 1. So 1 ~ 2, 1 ~ 3, 2 ~ 3. This tells us that S is partitioned by {0}, {1, 2, 3}, {4}, which we name [0], [1], [4], respectively. So the minimum-state DFA has three states. 13 Quiz What regular expression equality arises from the two DFAs? Answer: a + aa + (aaa + aab + ab)(a + b)* = a(a + b)* 14 Quiz Is the following DFA a minimum-state DFA? Answer. No. Use the minimum-state algorithm 15 The partition So 0 ~ 1, which tells us that the partition is the whole set of states {0, 1} = [0]. Therefore, we obtain the following minimum-state DFA 16 Quiz Is the following DFA a minimum-state DFA? Answer: No. E 0 = {{0, 1}, {0, 5}, {1, 5}, {2, 3}, {2, 4}, {3, 4}} E 1 = {{1, 5}, {2, 4}} E 2 = {{1, 5}, {2, 4}} = E 1. 17 The DFA So 1 ~ 5 and 2 ~ 4. This gives us {0}, {1, 5}, {2, 4}, {3}, with names [0], [1], [2], [3], respectively with the following minimum- state DFA. 18 The End of Chapter

*View more*