Download presentation
Presentation is loading. Please wait.
Published byJeffrey Wilson Modified over 8 years ago
1
Jianguo Lu 1 03-60-214: Lab 3 Jan 30, Winter 2004
2
Jianguo Lu 2 Exercises Draw the diagrams of an FA (DFA or NFA) for the following languages, the alphabet is {a, b,..., z}. Write the regular expression after you have the diagram. –A string containing an 'a'; –A string containing two consecutive 'a's. Write regular expressions for each of the following languages over the alphabet {a,b, c}: the strings that the first a precede the first b. The string with no ‘a’ or no ‘b’ is legal. Convert the following NFA to DFA, and minimize it.
3
Jianguo Lu 3 solutions Draw the diagrams of an FA (DFA or NFA) for the following languages, the alphabet is {a, b,..., z}. Write the regular expression after you have the diagram. –A string containing an 'a'; –A string containing two consecutive 'a's. Solutions a-z q1q1 q2q2 a q1q1 q3q3 q2q2 a a
4
Jianguo Lu 4 Problem 2 Write regular expressions for each of the following languages over the alphabet {a,b, c}: the strings that the first a precede the first b. The string with no ‘a’ or no ‘b’ is legal. Solution: –put the problem in another way: before ‘a’ there should not be any ‘b’; –It can be anything after ‘a’; –If both ‘a’ and ‘b’ appears in the string, ‘a’ must precedes ‘b’, otherwise it is a legal string. c*a[abc]*|[bc]*
5
Jianguo Lu 5 Problem 3 NFA to DFA –First compute the epsilon closure of the start state. Let the closure as the new start state. E(0)={0}; Let {0} equals to A, the new start state; –Next compute all the states that can be reached on all input symbols from A: Move(A, $)={1}; E(move(A,$)=e({1}) = {1,2,3,5,7}, let it be a new state B. E(move(A,L)=e({}) ={} Since we generated a new state B, we need to try all the input on B E(move(B,$))=e({4,8})={4, 7,2,3 5,8}, let it be a new state C. E(move(B,L))=e({6})={6,7,2,3,5}, let it be a new state D. Now compute the states can be reached from C and D, on all input symbols. E(move(C,$))=e({4,8})=C E(move(C,L))=e({6})=D E(move(D,$))=e({4,8})=C E(move(D,L))=e({6})=D C is going to be the final state because it contains final states 4 and 8.
6
Jianguo Lu 6 The corresponding DFA L A C B $ $ $ D L $ L
7
Jianguo Lu 7 Minimization of the DFA –The initial partition is (ABD) (C), because C is the final state, while others are not. –Lets try to split group (ABD) Move(A, $)=B Move(B,$)=C, Since B and C are distinguishable state, so are A and B. –So (ABD) is split into (A)(BD) –Let’s try to see whether (BD) can be further split Try B and D on all input symbols, first on $ –Move(B,$)=C –Move(D,$)=C –Can’t tell the difference, so try the next symbol Try B and D on symbol L: –Move(B,L)=D –Move(D,L)=D –Still can’t tell the difference; All the possible symbols are tried, B and D are equivalent.
8
Jianguo Lu 8 The minimized DFA A C BD $ $ $ L L
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.