dfa minimization 1 2 equivalent states consider the accept states c and g. they are both sinks...
TRANSCRIPT
DFA Minimize
DFA Minimization12Equivalent StatesConsider the accept states c and g. They are both sinks meaning that any string which ever reaches them is guaranteed to be accepted later.Q: Do we need both states?ab1d0,1e0,11c0,1gf0000113Equivalent StatesA: No, they can be unified as illustrated below.Q: Can any other states be unified because any subsequent string suffixes produce identical results?ab1d0,1e10,1cgf0000114Equivalent StatesA: Yes, b and f. Notice that if youre in b or f then:if string ends, reject in both casesif next character is 0, forever accept in both casesif next character is 1, forever reject in both casesSo unify b with f.ab1d0,1e10,1cgf0000115Equivalent StatesIntuitively two states are equivalent if all subsequent behavior from those states is the same.Q: Come up with a formal characterization of state equivalence.a0,1d0,1e10,1cgbf0017DFA Minimization: AlgorithmBuild table to compare each unordered pair of distinct states p,q.
Each table entry hasa mark as to whether p & q are known to be not equivalent, anda list of entries, recording dependences: If this entry is later marked, also mark these.
8DFA Minimization: AlgorithmInitialize all entries as unmarked & with no dependences.
Mark all pairs of a final & nonfinal state.
For each unmarked pair p,q & input symbol a:Let r=d(p,a), s=d(q,a).If (r,s) unmarked, add (p,q) to (r,s)s dependences,Otherwise mark (p,q), and recursively mark all dependences of newly-marked entries.
Coalesce unmarked pairs of states.Delete inaccessible states.9DFA Minimization: Examplefbcdeaghgfedcbaebfcgdh0000000011111111Initialize table entries: Unmarked, empty list10DFA Minimization: ExamplefbcdeaghgfedcbMark pairs of final & nonfinal statesaebfcgdh000000001111111111DFA Minimization: Exampleaebfcgdh0000000011111111For each unmarked pair & symbol, d(b,0) ? d(a,0)d(b,1) ? d(a,1)fbcdeaghgfedcb12DFA Minimization: Exampleg ? bc ? ffbcdeaghgfedcbMaybe.No!aebfcgdh0000000011111111For each unmarked pair & symbol, 13fbcdeaghgfedcbDFA Minimization: Exampleaebfcgdh0000000011111111For each unmarked pair & symbol, 14fbcdeaghgfedcbDFA Minimization: Exampleaebfcgdh0000000011111111d(e,0) ? d(a,0)d(e,1) ? d(a,1)For each unmarked pair & symbol, 15fbcdeaghgfedcbDFA Minimization: Exampleaebfcgdh0000000011111111h ? bf ? fMaybe.Yes.(a,e)For each unmarked pair & symbol, 16DFA Minimization: Examplefbcdeaghgfedcbaebfcgdh0000000011111111(a,e)(g,a)(g,a)For each unmarked pair & symbol, 17DFA Minimization: Examplefbcdeaghgfedcbaebfcgdh0000000011111111(a,e)(g,a)(g,a)Need to mark.So, mark (g,a) also.For each unmarked pair & symbol, 18DFA Minimization: Examplefbcdeaghgfedcbaebfcgdh0000000011111111(g,a)(a,e)For each unmarked pair & symbol, 19DFA Minimization: Examplefbcdeaghgfedcbaebfcgdh0000000011111111Coalesce unmarked pairs of states.(a,e)a eb hd faebhdfcg000001111120DFA Minimization: Examplefbcdeaghgfedcbaebfcgdh0000000011111111Delete unreachable states.(a,e)aebhdfcg0000011111None.21DFA Minimization: NotesOrder of selecting state pairs was arbitrary.All orders give same ultimate result.But, may record more or fewer dependences.Choosing states by working backwards from known non-equivalent states produces fewest dependences.Can delete unreachable states initially, instead.This algorithm: O(n2) time; Huffman (1954), Moore (1956).Constant work per entry: initial mark test & possibly later chasing of its dependences.More efficient algorithms exist, e.g., Hopcroft (1971).22What About NFA Minimization?This algorithm doesnt find a unique minimal NFA.
Is there a (not necessarily unique) minimal NFA???Of course.23NFA MinimizationIn general, minimal NFA not unique!
Example NFAs for 0+:
Both minimal, but not isomorphic.000024Minimizing DFAsBy Partitioning25Minimizing DFAsLots of methodsAll involve finding equivalent states:States that go to equivalent states under all inputs (sounds recursive)We will learn the Partitioning Method
26Minimizing DFAs by PartitioningConsider the following dfa
Accepting states are yellow Non-accepting states are blue Are any states really the same?
27
S2 and S7 are really the same: Both Final states Both go to S6 under input b Both go to S3 under an a S0 and S5 really the same. Why? We say each pair is equivalent
Are there any other equivalent states?We can merge equivalent states into 1 state
28Partitioning AlgorithmFirst Divide the set of states into
Final and Non-final states
Partition I
Partition II a bS0S1S4S1S5S2S3S3S3S4S1S4S5S1S4S6S3S7*S2S3S6*S7S3S629Partitioning AlgorithmNow See if states in each partition each go to the same partition
S1 & S6 are different from the rest of the states in Partition I (but like each other)
We will move them to their own partition
a bS0S1 IS4 IS1S5 IS2 IIS3S3 IS3 IS4S1 IS4 IS5S1 IS4 IS6S3 IS7 II*S2S3 I
S6 I*S7S3 IS6 I30Partitioning Algorithm a bS0S1S4S5S1S4S3S3S3S4S1S4S1S5S2S6S3S7*S2S3S6*S7S3S631Partitioning AlgorithmNow againSee if states in each partition each go to the same partition
In Partition I, S3 goes to a different partition from S0, S5 and S4
Well move S3 to its own partition a bS0S1 IIIS4 IS5S1 IIIS4 IS3S3 IS3 IS4S1 IIIS4 IS1S5 IS2 IIS6S3 IS7 II*S2S3 IS6 III*S7S3 IS6 III
32Partitioning Algorithm Note changes in S6, S2 and S7
a bS0S1 IIIS4 IS5S1 IIIS4 IS4S1 IIIS4 IS3S3 IVS3 IVS1S5 IS2 IIS6S3 IVS7 II*S2S3 IVS6 III*S7S3 IVS6 III
33Partitioning AlgorithmNow S6 goes to a different partition on an a from S1S6 gets its own partition.We now have 5 partitionsNote changes in S2 and S7 a bS0S1 IIIS4 IS5S1 IIIS4 IS4S1 IIIS4 IS3S3 IVS3 IVS1S5 IS2 IIS6S3 IVS7 II*S2S3 IVS6 V*S7S3 IVS6 V
34Partitioning AlgorithmAll states within each of the 5 partitions are identical. We might as well call the states I, II III, IV and V. a bS0S1 IIIS4 IS5S1 IIIS4 IS4S1 IIIS4 IS3S3 IVS3 IVS1S5 IS2 IIS6S3 IVS7 II*S2S3 IVS6 V*S7S3 IVS6 V
35Partitioning Algorithm a bIIII I*II IVVIII I IIIV IV IVV IVII
Here they are:
36
Vaaaaabbbbbb