Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 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.

Similar presentations


Presentation on theme: "1 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."— Presentation transcript:

1 1 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. Example. Given the following NFA as a graph and as a transition table. S 0 2 1 b b  a  a 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}.

2 2 Algorithm: Transform an NFA into a DFA Construct a DFA table T D from an NFA table T N 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. Example. Given the following NFA. The algorithm constructs the following DFA transition table T D, where it is also written in simplified form after a renumbering of the states. S 0 3 1 b b a  a 2 b

3 3 Quiz. Use the algorithm to transform the following NFA into a DFA. S 0 1 a a  b 2 3 a 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.

4 4 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. 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.

5 5 Example. Use the algorithm to transform the following DFA into a minimum-state DFA. S 0 a b a 2 a, b 4 1 3 b 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. Min-state TableRenamed Table S 0 a b a, b 2 1 Min-state DFA graph Quiz: What regular expression equality arises from the two DFAs? Answer: a + aa + (aaa + aab + ab)(a + b)* = a(a + b)*.

6 6 Quiz. Is the following DFA a minimum-state DFA? S b 0 1 a a b S a, b 0 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. 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. E 0 = {{0, 1}} E 1 = {{0, 1}} = E 0. 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. Answer. No. Use the minimum-state algorithm. Quiz. Is the following DFA a minimum-state DFA?


Download ppt "1 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."

Similar presentations


Ads by Google