80 likes | 169 Views
03-60-214: Lab 3. Jan 30, Winter 2004. 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.
E N D
03-60-214: Lab 3 Jan 30, Winter 2004 Jianguo Lu
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. Jianguo Lu
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 a-z a q2 q1 a-z a-z a a q3 q1 q2 Jianguo Lu
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]* Jianguo Lu
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. Jianguo Lu
The corresponding DFA $ $ $ C A B L L $ D L Jianguo Lu
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. Jianguo Lu
The minimized DFA $ $ $ C A BD L L Jianguo Lu