Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Chapter 11 - 3 Constructing Efficient Finite Automata.

Similar presentations


Presentation on theme: "1 Chapter 11 - 3 Constructing Efficient Finite Automata."— Presentation transcript:

1 1 Chapter 11 - 3 Constructing Efficient Finite Automata

2 2 Section 11.3 Constructing Efficient Finite Automata First we’ll see how to transform an NFA into a DFA. Then we’ll 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 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 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 5 Example Given the following NFA

6 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 7 Quiz Use the algorithm to transform the following NFA into a DFA

8 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 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 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 11 Example Use the algorithm to transform the following DFA into a minimum-state DFA.

12 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 13 Quiz What regular expression equality arises from the two DFAs? Answer: a + aa + (aaa + aab + ab)(a + b)* = a(a + b)*

14 14 Quiz Is the following DFA a minimum-state DFA? Answer. No. Use the minimum-state algorithm

15 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 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 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 18 The End of Chapter 11 - 3


Download ppt "1 Chapter 11 - 3 Constructing Efficient Finite Automata."

Similar presentations


Ads by Google