Upload
jocelyn-sims
View
225
Download
0
Embed Size (px)
DESCRIPTION
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}.
Citation preview
1
Chapter 11 - 3
Constructing Efficient Finite Automata
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 DFAThe λ-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 {s1, …, sn} is a DFA state and a ∈ A, then
TD({s1, …, sn}, a) = λ(TN(s1, a) ⋃ … ⋃ TN(sn, 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 TD, 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 TD, 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
AlgorithmTransform a DFA to a minimum-state DFA1. Construct the following sequence of sets of possible equivalent pairs
of distinct states: E0 ⊃ E1 ⊃ … ⊃ Ek = Ek+1, where E0 = {{s, t} | s and t are either both final or both nonfinal} and Ei+1 = {{s, t} ∈ Ei | {T(s, a), T(t, a)} ∈ Ei or T(s, a) = T(t, a)} for every a
∈ A}. Ek 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 Tmin defined by Tmin([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: E0 = {{0, 4}, {1, 2}, {1, 3}, {2, 3}} E1 = {{1, 2}, {1, 3}, {2, 3}} E2 = {{1, 2}, {1, 3}, {2, 3}} = E1.
• 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.E0 = {{0, 1}, {0, 5}, {1, 5},
{2, 3}, {2, 4}, {3, 4}} E1 = {{1, 5}, {2, 4}}
E2 = {{1, 5}, {2, 4}} = E1.
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 11 - 3