Compiler Design. Spring Lexical Analysis. Sample Exercises and Solutions. Prof. Pedro C. Diniz

Size: px
Start display at page:

Download "Compiler Design. Spring Lexical Analysis. Sample Exercises and Solutions. Prof. Pedro C. Diniz"

Transcription

1 University of Southern Cliforni Computer Siene Deprtment Compiler Design Spring 7 Lexil Anlysis Smple Exerises nd Solutions Prof. Pedro C. Diniz USC / Informtion Sienes Institute 47 Admirlty Wy, Suite Mrin del Rey, Cliforni 99 pedro@isi.edu Lexil Anlysis Smple Exerises Spring 7

2 University of Southern Cliforni Computer Siene Deprtment Prolem : Considering the lphet Σ = {, derive Non-Deterministi-Finite Automton (NFA) using the Thompson onstrution tht is le to reognize the sentenes generted y the regulr expression *( )*. Does the sentene w = elong to the lnguge generted y this regulr expression? Justify. Solution: Considering simplifition of the omintion of the NFA during the Thompson onstrution (e.g., sequene of two e-trnsitions n e onsidered s single e-trnsition) possile NFA is s shown elow nd where the strt stte is the stte leled The word w = elongs to the lnguge generted y this RE euse there is pth from the strt stte to the epting stte tht spells out the word, respetively the pth,,4,,8,,,,,,. Prolem : Strting from the NFA you derived in prolem, onvert it to DFA using the su-set onstrution desried in lss. Verify tht the DFA yields the sme output s the originl NFA for the sme input string w. Solution: Using the e-losure nd DFAedge omputtion s desried in lss, we hve the following mpping of set of sttes of the NFA to sets of sttes of the DFA: I = e-losure () = {,,, 4, I = DFAedge(I,) = e-losure ({,,, 4,, ) = { I = DFAedge(I,) = e-losure ({,,, 4,, ) = {,,, 4,, 7 I = DFAedge(I,) = e-losure ({, ) = Ierr I4 = DFAedge(I,) = e-losure ({, ) = {8,,, I = DFAedge(I,) = e-losure ({,,, 4,, 7, ) = {, 9,,, I = DFAedge(I,) = e-losure ({,,, 4,, 7, ) = {,,, 4,, 7 = I I7 = DFAedge(I4,) = e-losure ({8,,,, ) = Ierr I8 = DFAedge(I4,) = e-losure ({8,,,, ) = {,, I9 = DFAedge(I,) = e-losure ({, 9,,,, ) = Ierr I = DFAedge(I,) = e-losure ({, 9,,,, ) = {8,,,, I = DFAedge(I8,) = e-losure ({,,, ) = Ierr I = DFAedge(I8,) = e-losure ({,,, ) = {,, = I8 I = DFAedge(I,) = e-losure ({8,,,,, ) = Ierr I4 = DFAedge(I,) = e-losure ({8,,,,, ) = I8 Effetively there re only 8 sttes s shown in the DFA elow nd this is lerly not the miniml DFA tht n reognize this regulr expression. Lexil Anlysis Smple Exerises Spring 7

3 University of Southern Cliforni Computer Siene Deprtment, Ierr I I I4 I8 I I I For the input sentene w = in his DFA we would reh the stte I8, through sttes I, I4 nd I8 nd thus epting this string. Prolem : Strting from the DFA you onstruted in the previous prolem, onvert it to miniml DFA using the minimiztion lgorithm desried in lss. Verify tht the DFA yields the sme output s the originl NFA for the sme input string w. Solution: The first prtition would hve the two sets of sttes P = {I, I, I, Ierr nd = {I4, I, I8, I. A seond prtition would mintin nd prtition P into {I, I, Ierr nd generte P = {I sine I goes to itself on nd to on. Next the lgorithm would generte P4 = {I) nd next generte P = {Ierr leving P = {I. The finl DFA would hve therefore sttes hs shown elow., P P4 P P Agin, on the input string w = the DFA would trverse P, P4, nd loop in therefore epting the string. Importnt Note: If you try to pply the sme onstrution, i.e. prtitioning the set of sttes strting with n inomplete DFA where the trp stte is missing you might e surprised to find tht you reh t n inorret miniml DFA. Lexil Anlysis Smple Exerises Spring 7

4 University of Southern Cliforni Computer Siene Deprtment Prolem 4: Considering the lphet Σ = {, onstrut Non-Deterministi-Finite Automton (NFA) using the Thompson onstrution tht is le to reognize the sentenes generted y the regulr expression (**)**. Does the sentene w = elong to the lnguge generted y this regulr expression? Justify. Solution: The NFA is s shown elow nd where the strt stte is stte leled S = e-losure () = {,,, 4,,, this is finl stte euse of S = DFAedge(S,) = e-losure (S, ) = {,, 8 S = DFAedge(S,) = e-losure (S, ) = {,, 4,,, finl stte DFAedge(S,) = e-losure (S, ) = {,, 8 = S DFAedge(S,) = e-losure (S, ) = {,, 4,,, = S S = DFAedge(S,) = e-losure (S, ) = {,, 4, 9,,, finl stte S4 = DFAedge(S,) = e-losure (S, ) = {, 7, 8 DFAedge(S4,) = e-losure (S4, ) = {,, 4, 9,,, = S DFAedge(S4,) = e-losure (S4, ) = {, 7, 8 = S4 DFAedge(S,) = e-losure (S, ) = {,, 8 = S DFAedge(S,) = e-losure (S, ) = {,, 4,,, = S This results in the DFA shown elow with strting stte S. S S S S S S4 S4 This DFA n e further minimize y reognizing tht S, S nd S form self-ontined prtition nd S nd S4 nother prtition resulting in the DFA on the right-hnd-side. Lexil Anlysis Smple Exerises 4 Spring 7

5 University of Southern Cliforni Computer Siene Deprtment Prolem : Consider the lphet Σ = {,.. Construt Non-Deterministi-Finite Automton (NFA) using the Thompson onstrution tht is le to reognize the sentenes generted y the regulr expression RE = ()*.()*.. Do the sentenes w = nd w = elong to the lnguge generted y this regulr expression? Justify.. Convert the NFA in prt ) to DFA using the suset onstrution. Show the mpping etween the sttes in the NFA nd the resulting DFA. d. Minimize the DFA using the itertive refinement lgorithm disussed in lss. Show your intermedite prtition results nd doule hek the DFA using the sentenes w nd w. Solution: ) A possile onstrution (lredy simplified to hve only single e-trnsition etween sttes) would result in the NFA shown elow nd where the strt stte is leled. 4 ) Both words re reognized y this NFA. Regrding the word there is pth from stte to the epting stte, nmely:,,,,4,,4,,. Regrding the word the utomton my reh stte following the pth,,,4,,4,,4,,. ) Using the suset onstrution we rrive t the following susets nd trnsitions. S = e-losure () = {,,, 4,, this is finl stte euse of stte S = DFAedge(S,) = e-losure (goto(s, )) = {, 4,, finl stte SE = DFAedge(S,) = e-losure (goto(s, )) = { S = DFAedge(S,) = e-losure (goto(s, )) = {4,, finl stte S = DFAedge(S,) = e-losure (goto(s, )) = {, 4,, finl stte DFAedge(S,) = e-losure (goto(s, )) = {4,, = S DFAedge(S,) = e-losure (goto(s, )) = { = SE DFAedge(S,) = e-losure (goto(s, )) = {, 4,, = S DFAedge(S,) = e-losure (goto(s, )) = { = SE This results in the DFA shown elow with strting stte S. S SE S S S, d) This DFA n e further minimize y using the itertive refinement prtitioning yielding the sequene of prtitions indited elow. Lexil Anlysis Smple Exerises Spring 7

6 University of Southern Cliforni Computer Siene Deprtment S SE S S S S P SE S S S P, P, Initil prtitioning on finl sttes Prtitioning on S P SE S S S P4 S SE S S P,, Prtitioning on finl miniml DFA Lexil Anlysis Smple Exerises Spring 7

7 University of Southern Cliforni Computer Siene Deprtment Prolem : Minimize the FA shown elow over the lphet {,. Mke sure to onvert it first into DFA nd them pply the itertive refinement lgorithm disussed in lss. strt 4 Solution: The first oservtion is tht there re some sttes for whih one of the trnsitions on the lphet symols is missing. This is the se with sttes "" nd "". As suh s need to ugment this FA with "trp-stte" tht is non-epting s shown elow in ). The reminder DFA result from the pplition of the itertive prtitioning lgorithm desried in lss. strt strt P 4, 4 P, ) Augmented DFA strt ) Prtion sed on epting nd non-epting sttes strt P P 4 P, 4 P, P ) Prtion sed on '' trnsistions d) Prtion sed on '' trnsistions strt strt P P4 4 P e) Prtion sed on '' trnsistions P, f) Minimized DFA, Lexil Anlysis Smple Exerises 7 Spring 7

8 University of Southern Cliforni Computer Siene Deprtment Prolem 7: Consider the DFA elow with strting stte nd epting stte :, 4, ) Using the Kleene onstrution lgorithm derive regulr expression. ) Simplify the expression found in ) ove. Solution: Before engging in very long sequene of ontention nd symoli opertions we mke the oservtion tht stte 4 is trp-stte. As suh we n sfely ignore it sine it is not n epting stte. Wht this mens is tht we n use the lgorithm simply with k = nd need to use it to ompute R s there re pths from the strt stte to the finl stte vi stte. Expressions for k = R = (e) R = ( ) R = () R = () R = (e ) Expressions for k = R = R (R )*R R = (e) R = R (R )*R R = ( ) R = R (R )*R R = () R = R (R )*R R = () R = R (R )*R R = (e ) Expressions for k = R = R (R )*R R = R = (e) R = R (R )*R R = ( ) (e )* (e ) ( ) = ( ) * R = R (R )*R R = (e ) (e )* () () = *() R = R (R )*R R = () (e )* (e ) () = () * R = R (R )*R R = (e ) (e )* (e ) (e ) = * R = R (R )*R R = ( ) (e )* () = ( ) * () R = R (R )*R R = () (e )* () = () *() Expressions for k = R = R (R )*R R = R = (e) R = R (R )*R R = ( ) * () (() *())* () * ( )* R = R (R )*R R = *() (() *())* () *() * () R = R (R )*R R = () *() (() *())* () * () * R = R (R )*R R = *() (() *())* () * * R = R (R )*R R = ( ) * () (() *())* () *() ( ) * () R = R (R )*R R = () *() (() *())* () *() () *() Lexil Anlysis Smple Exerises 8 Spring 7

9 University of Southern Cliforni Computer Siene Deprtment Clerly these expressions hve lot of redundnt terms. In ft we re only interested in R = ( ) * () (() *())* () * ( )* sine the strting stte is stte nd the only epting stte is stte. ) To simplify the expression found ove is very hrd, s there re lot of prtil terms in this expression. Insted you follow the edges in the DFA nd try to ompose the regulr expressions (in some sense ignoring wht you hve done in the previous step). The simplest wy to look t this prolem is to see tht there is prefix ( ) nd then you return to stte either y (*) or (), so ompt regulr expression would e R = ( )(() ())* muh more ompt regulr expressions tht R ove. Prolem 8: Consider the lphet Σ = {;. Define short, possily the shortest, regulr expression tht genertes strings over Σ tht ontin extly one nd t lest one. Solution: The string must either strt with one or n, so we n use * prefix to ount for ny possile numer of leding s efore the first. The single must hve t lest one either preeding it or just efore it. After this single there n e ny numer of triling s. As possile (lthough not neessrily unique) regulr expression denoting the sought lnguge is R = *( )*. Prolem 9: Given n NFA with e-trnsitions how do you derive n equivlent NFA without those e- trnsitions? Justify. Solution: For those sttes with e-trnsitions merge the edges of the sttes t the end of those e trnsitions into the urrent stte. Iterte until there re no e-trnsitions left. You still hve NFA ut there will e t more multiple edges with the lel out of given stte. Prolem : Given n NFA with severl ept sttes, show how to onvert it onto NFA with extly one strt stte nd one epting stte. Solution: The initil stte is the sme s in the originl NFA. As to the epting sttes just dd e- trnsitions from the originl epting sttes to new epting stte nd lel tht epting stte s the only epting stte of the new NFA. Lexil Anlysis Smple Exerises 9 Spring 7

10 University of Southern Cliforni Computer Siene Deprtment Prolem : Given the Finite Automton elow with initil stte nd lphet {, nswer the following questions: 4, () Why is this FA Non-Deterministi Finite Automton (NFA)? () Convert this NFA to DFA using the losure omputtion. () Minimize the resulting DFA. (d) Wht is the Regulr Expression mthed y this NFA? You re dvised not to use the utomti Kleene onstrution or try to look t the input NFA ut rther the orretly minimized DFA. Solution: () This FA is lredy DFA, s the only trnsitions tht re missing ll go to the trp stte. () The suset onstrution, whih in this se yields the sme originl DFA on the left where we hve noted the suset eh stte stnds for. { { { {4 {,, () Using the itertive prtition refinement we hve the following prtitions (elow left) nd the resulting minimized DFA on the right gin with the sttes relelled. Notie tht this is speil se where the refinement lgorithm nnot refine ny su-sets of sttes given tht the originl DFA ws lredy miniml. P4 { P { { P {4 { P,, (d) Bsed on the lst DFA the regulr expression identified y this FA must hve extly two onseutive symol possily preeded y single symol. For instne, the string is in the lnguge ut the string or re not. The regulr expression n e denoted y *. Lexil Anlysis Smple Exerises Spring 7

11 University of Southern Cliforni Computer Siene Deprtment Prolem : Drw the smllest DFA tht epts the lnguge derived y the regulr expression (** **). Solution: A possile trnsltion guided y the ide of the Thompson onstrution is shown elow., 4 Using the itertive refinements lgorithm for DFA minimiztion indeed onfirms tht this is the smllest possile DFA. The sequene of refinements is shown elow., 4, 4 4,, 4 4, 4, Prolem : Given the regulr expression RE = ( *)*(*) over the lphet Σ = {, do the following trnsformtions:. Derive NFA using the Thompson onstrution ple of identifying the strings generted y this regulr expression.. Convert the NFA otined in ) to DFA.. Minimize the resulting DFA using the itertive refinement lgorithm disussed in lss. d. Determine in how mny steps is the sequene proessed. Justify. Solution: Regrding ) the NFA is given elow. Here we mde some very simple simplifition tht two or more sequenes of e-trnsitions n e onverted to single e-trnsitions. This sustntilly redues the numer of sttes in the NFA nd this filittes the onstrution of the equivlent DFA. Lexil Anlysis Smple Exerises Spring 7

12 University of Southern Cliforni Computer Siene Deprtment Applying the suset onstrution, we hve the following sttes S = e-losure () = {,, 4, 7, 8,,,,, 4, this is finl stte euse of S = DFAedge(S,) = e-losure (goto(s, )) = { S = DFAedge(S,) = e-losure (goto(s, )) = {,,, 4, 7, 8, 9,,, 4, finl S = DFAedge(S,) = e-losure (goto(s, )) = { S4 = DFAedge(S,) = e-losure (goto(s, )) = {,,, 4,, 7, 8,,, 4, finl S = DFAedge(S,) = e-losure (goto(s, )) = { = S S = DFAedge(S,) = e-losure (goto(s, )) = {,,, 4, 7, 8, 9,,,, 4, finl S7 = DFAedge(S,) = e-losure (goto(s, )) = { = S S8 = DFAedge(S,) = e-losure (goto(s, )) = { = S S9 = DFAedge(S4,) = e-losure (goto(s4, )) = { = S S = DFAedge(S4,) = e-losure (goto(s4, )) = {,,, 4,, 7, 8, 8,,,, 4, = S S = DFAedge(S,) = e-losure (goto(s, )) = {,,, 4, finl S = DFAedge(S,) = e-losure (goto(s, )) = {,,, 4, 7, 8, 9,,, 4, = S S = DFAedge(S,) = e-losure (goto(s, )) = { = S S4 = DFAedge(S,) = e-losure (goto(s, )) = {,,, 4,, 7, 8,,, 4, = S4 So there re totl of 7 sttes, S, S, S, S, S4, S, S nd the orresponding DFA is s shown y the tle elow (old sttes re finl sttes) nd then in the figure elow the tle. Next Stte Current Stte S S S S S S4 S S S S S S S4 S S S S S S S S4, 4 Lexil Anlysis Smple Exerises Spring 7

13 University of Southern Cliforni Computer Siene Deprtment, P 4 initil refinement on eptne riteri P4, 4 refinement of on P P, 4 P refinement of on P, P 4 P4 refinement of P on P P P P P, 4 P4 refinement of on P P P P P4, 4 finl refinement with sttes P Prolem 4: Given the DFA elow desrie in English the set of strings epted y it., Solution: Any string over the lphet tht ontins ny numer of onseutive s, inluding none with prefix of zero or more onseutive s. Lexil Anlysis Smple Exerises Spring 7

14 University of Southern Cliforni Computer Siene Deprtment Prolem : Given regulr lnguge L. i.e., lnguge desried y regulr expression, prove tht the reverse of L is lso regulr lnguge (Note: the reverse of lnguge L is L R where for eh word w in L, w R is in L R. Given word w over the given lphet, w R is onstruted y spelling w kwrds). Solution: If L is regulr lnguge then there exists DFA M tht reognizes it. Now given M we n onstrut M tht reognizes the reverse of L with respet to the input lphet. We now desrie how to onstrut M. M is repli of M ut reversing ll the edges. The finl stte of M is the stte tht used to e the strt stte of M. The strt stte of M is new stte with e-trnsitions to the sttes in M tht used to e the finl sttes of M. Now euse M might hve multiple finl sttes M is y onstrution NFA. Given the equivlene of NFA nd regulr expressions we hve shown tht if L is regulr so is L R. Prolem : Drw the DFA ple of reognizing the set of ll strings eginning with whih interpreted s the inry representtion of n integer (ssuming the lst to e proessed is the lest signifint) is ongruent to zero modulo i.e., the numeri vlue of this inry representtion is multiple of. Solution: The hrd prt out this prolem is tht you need to keep trk with the lredy oserved its wht the reminder of the division y is. Given tht you hve reminder you would need no more tht sttes, one for eh of the reminder vlues through eing the stte tht represents reminder of zero the epting stte, in this se stte S. The DFA elow omplishes this. You n verify this DFA y trying the numer in inry or in inry. Notie tht in the lst stte S ny dditionl mens you re shifting the its y one it, i.e., multiplying y, hene stying in the sme stte. S S S S Prolem 7: Consider the lphet Σ = {,.. Consider the Non-Deterministi Finite Automton (NFA) depited elow. Why is this utomton non-deterministi? Explin the vrious soure on indeterminy.. Do the sentenes w = nd w = elong to the lnguge reognized y this FA? Justify.. Convert the NFA in prt ) to DFA using the suset onstrution. Show the mpping etween the sttes in the NFA nd the resulting DFA. d. Minimize the DFA using the itertive refinement lgorithm desried in lss. Show your intermedite prtition results nd doule hek the DFA using the sentenes w nd w. Lexil Anlysis Smple Exerises 4 Spring 7

15 University of Southern Cliforni Computer Siene Deprtment 4 strt Solution: ) This is indeed NFA for two resons. First, it inludes e-trnsitions. Seond, in stte there re two trnsitions on the sme terminl or lphet symol, "". ) Regrding the word there is pth from stte to the epting stte, nmely:,,,,. Regrding the word the utomton will never e le to reh the stte s in order to spell out the hrter will neessrily e in stte nd to reh tht stte we nnot hve two onseutive "" hrters we would e either in stte or stte 4. ) Using the suset onstrution we rrive t the following susets nd trnsitions. S = e-losure ({) = {,, 4 this is not finl stte. S = DFAedge(S,) = e-losure (goto(s, )) = {,,, finl stte S = DFAedge(S,) = e-losure (goto(s, )) = { S9 = DFAedge(S,) = e-losure (goto(s, )) = {,, finl stte S4 = DFAedge(S,) = e-losure (goto(s, )) = {,, finl stte. S = DFAedge(S,) = e-losure (goto(s, )) = {,, finl stte. DFAedge(S,) = e-losure (goto(s, )) = { = S DFAedge(S4,) = e-losure (goto(s4, )) = {,, = S finl stte. DFAedge(S4,) = e-losure (goto(s4, )) = {,, = S4 finl stte. S = DFAedge(S,) = e-losure (goto(s, )) = {, finl stte. S7 = DFAedge(S,) = e-losure (goto(s, )) = {, finl stte. DFAedge(S,) = e-losure (goto(s, )) = {, = S finl stte. S8 = DFAedge(S,) = e-losure (goto(s, )) = { DFAedge(S7,) = e-losure (goto(s7, )) = { = S8 DFAedge(S7,) = e-losure (goto(s7, )) = {, = S7 finl stte. DFAedge(S8,) = e-losure (goto(s8, )) = { = S8 DFAedge(S8,) = e-losure (goto(s8, )) = { = S8 DFAedge(S9,) = e-losure (goto(s9, )) = {,, = S9 DFAedge(S9,) = e-losure (goto(s9, )) = { = S This results in the DFA shown elow with strting stte S. strt S S S9 S S4 S S7 S S8, Lexil Anlysis Smple Exerises Spring 7

16 University of Southern Cliforni Computer Siene Deprtment d) We n try to minimize this DFA using the itertive refinement lgorithm desried in lss. The figure elow depits possile sequene of refinements. For eh step, we indite the riteri used to disriminte etween sttes in the previous prtition. As n e seen, the lgorithm leds to no refinement, so this is prtiulr se where the su-set lgorithm tht help us derive the DFA from its originl NFA does yield miniml DFA. P P P P strt S S S S9 S4 S S7 S S8, strt S S S9 S S4 S S7 S, S8 strt S S S S4 S9 S S7 S, S8 P P P () Prtition etween epting nd non-epting sttes () Disrimintion sed on "" trnsitions () Disrimintion sed on "" trnsitions strt P S P S S P9 S9 S4 S P4 S7 S P P S8, strt P S P S S P4 P S S4 P9 S9 S7 S P P S8, strt P S P7 P S S P4 P S S4 P9 S9 S7 S P P S8, (d) Disrimintion sed on "" trnsitions (e) Disrimintion sed on "" trnsitions (f) Disriminion sed on "" trnsitions Lexil Anlysis Smple Exerises Spring 7

17 University of Southern Cliforni Computer Siene Deprtment Prolem 8: Consider the DFA elow with strting stte nd epting stte : strt ) Desrie in English the set of strings epted y this DFA. ) Using the Kleene onstrution lgorithm derive the regulr expression reognized y this utomton simplifying it s muh s possile. Solution: ) This utomton reognizes ll non-null strings over the {, lphet tht end with "". ) The derivtions re shown elow with the ovious simplifition. Expressions for k = R = ( e) R = () R = () R = ( e) Expressions for k = R = R (R )*R R = ( e). ( e)*. ( e) ( e) = * R = R (R )*R R = ( e). ( e)*. () () = * * R = R (R )*R R = (). ( e)*. ( e) () = + + R = R (R )*R R = (). ( e)*. ( e) ( e) = (* ) Expressions for k = R = R (R )*R R = ( * * ). (* )*. ( + + ) ( * ) R = R (R )*R R = ( * * ). (* )*. ( + + ) ( * * ) R = R (R )*R R = ( * * ). (* )*. ( + + ) ( + + ) R = R (R )*R R = ( * * ). (* )*. ( + + ) (* ) L = R = ( * * ). (* )*. ( + + ) ( * * ) As n e seen the simplifition of ny of these regulr expressions eyond the expressions for k= is firly omplited. This method, lthough orret y design leds to regulr expressions tht re fr from eing miniml or even the most ompt representtion of the regulr lnguge the DFA reognizes. Lexil Anlysis Smple Exerises 7 Spring 7

18 University of Southern Cliforni Computer Siene Deprtment Prolem 9: For the regulr expression depited elow nswer the following questions: RE = (e - +)?. (e E). (-9)+ ) Using the Thompson onstrution (or simplifition thereof) derive NFA tht reognizes the strings speified y this RE. ) Convert the NFA in ) to n equivlent DFA using the suset onstrution. ) Mke sure the DFA M found in ) ove is miniml (you do not need to show tht it is in ft miniml) nd onstrut the DFA M tht epts the omplement of the regulr lnguge the first DFA epts. Show tht M does ept the word w = "e" whih is not epted y the originl DFA. Solution: ) The figure elow depits the NFA with e-trnsitions nd where we hve simplified the trnsition on numeri s. 'e' '' strt '-' 4 'E' 7... '9' 8 9 '+' ) We use the suset onstrution y tring for every set of sttes the other possile sttes the NFA ould e in if it were to trverse e-edges only. The list elow depits the results of this onstrution where we lso desrie the omputtion of edge DFA edge using the funtion DFAedge nd then omputing the e-losure of the resulting intermedite set of sttes. e-losure({) DFAedge(S,'-') DFAedge(S,'+') DFAedge(S,'e') DFAedge(S,'E') DFAedge(S,'<>') DFAedge(S,'-') DFAedge(S,'+') DFAedge(S,'e') DFAedge(S,'E') DFAedge(S,'<>') = {,,,, 4 = S = e-losure({) = {,, 4 = S = e-losure({) = {,, 4 = S = e-losure({) = {,, 7 = S = e-losure({) = {,, 7 = S = e-losure( { ) = SE; error stte = e-losure( { ) = SE; error stte = e-losure( { ) = SE; error stte = e-losure({) = {,, 7 = S = e-losure({) = {,,7 = S = e-losure( { ) = SE; error stte DFAedge(S,'-') = e-losure( { ) = SE; error stte DFAedge(S,'+') = e-losure( { ) = SE; error stte DFAedge(S,'e') = e-losure( { ) = SE; error stte DFAedge(S,'E') = e-losure( { ) = SE; error stte DFAedge(S,'<>') = e-losure( {8 ) = {, 7, 8, 9, = S; DFAedge(S,'-') = e-losure( { ) = SE; error stte DFAedge(S,'+') = e-losure( { ) = SE; error stte DFAedge(S,'e') = e-losure( { ) = SE; error stte DFAedge(S,'E') = e-losure( { ) = SE; error stte DFAedge(S,'<>') = e-losure( {8 ) = {, 7, 8, 9, = S; Lexil Anlysis Smple Exerises 8 Spring 7

19 University of Southern Cliforni Computer Siene Deprtment The figure elow depits the DFA resulting from the pplition of the suset onstrution. Notie tht this is fully speified DFA where eh stte inludes trnsition for ll the hrters in the onsidered lphet. strt '-' '+' S 'e' 'E' '' '9'... S... '' '9' '' '9' 'e' 'E' '-' '+'... 'e' 'E' '' S S 'e' 'E' '-' '+' SE... '9' 'e' 'E' '-' '+' ''... '9' ) Let M e the DFA found in ). This DFA is in ft miniml. Informl proof: All sttes re required. S is the strt stte. S ptures the ft tht we hve oserved sign. Stte S ptures to ft we need to oserve t lest one. All the s re then ptured y stte S. Stte SE is the trp error stte. Let M e this first DFA. We onstrut M y mking ll epting sttes of M non-epting sttes nd ll non-epting sttes of M s epting sttes of M. The stte strt is unhnged. This is DFA s we only hnge the stte of non-epting sttes. The strt stte is still singleton nd ll trnsitions re lerly identified in the newly reted DFA s shown elow. '-' '+' S S 'e' 'E' 'e' 'E' ''... S ''... '9' strt '' '9'... '' '9' S... '' '9' 'e' 'E' '-' '+'... 'e' 'E' '-' '+' SE '9' 'e' 'E' '-' '+' In this newly reted DFA the input string w = "e" tkes the DFA to stte SE whih is n epting stte n this "omplement" mhine. Lexil Anlysis Smple Exerises 9 Spring 7

20 University of Southern Cliforni Computer Siene Deprtment Prolem : Consider the lphet Σ = {,,.. Consider the Non-Deterministi Finite Automton (NFA) depited elow. Why is this utomton non-deterministi? Explin the vrious soure on indeterminy.. Do the sentenes w = nd w = elong to the lnguge generted y this FA? Justify.. Convert the NFA in prt ) to DFA using the suset onstrution. Show the mpping etween the sttes in the NFA nd the resulting DFA. d. By inspetion n you derive regulr expression (RE) this NFA detets?,, 4,, strt, Solution: ) This FA is non-deterministi s for t lest one of its sttes there re two trnsitions on the sme lel to two distint sttes. This is the se with stte where on '' the FA goes to stte nd. Similrly, sttes nd exhiit the sme ehviour. ) The sentene w = elongs to the lnguge epted y this FA s there is pth through sttes, nd tht spells out this word nd stte is n epting stte. As to the word w = ny word tht egins with '' leds to stte 4 whih is trp nd non-epting stte. As suh w does not elong to the lnguge reognized y this FA. ) A simplified su-set onstrution is s shown elow: S = e-losure ({) = { this is not finl stte. DFAedge(S, ) = e-losure (goto(s, )) = {, = S DFAedge(S, ) = e-losure (goto(s, )) = {4 DFAedge(S, ) = e-losure (goto(s, )) = {4 DFAedge(S, ) = e-losure (goto(s, )) = {4 = S = S = S DFAedge(S, ) = e-losure (goto(s, )) = {,4 = S4 DFAedge(S, ) = e-losure (goto(s, )) = {4, = S DFAedge(S, ) = e-losure (goto(s, )) = {4 DFAedge(S, ) = e-losure (goto(s, )) = {4 DFAedge(S, ) = e-losure (goto(s, )) = {4 = S = S = S DFAedge(S4, ) = e-losure (goto(s4, )) = {4 = S DFAedge(S4, ) = e-losure (goto(s4, )) = {4 = S DFAedge(S4, ) = e-losure (goto(s4, )) = {,4 = S4 DFAedge(S, ) = e-losure (goto(s, )) = {4 = S DFAedge(S, ) = e-losure (goto(s, )) = {4, = S DFAedge(S, ) = e-losure (goto(s, )) = {4 = S Lexil Anlysis Smple Exerises Spring 7

21 University of Southern Cliforni Computer Siene Deprtment In this onstrution, we hve simplified the resulting DFA y mking the trnsition etween stte {, on '' diretly move to stte 4 whih is trp or error stte. A more mehnil proedure would hve seen the retion of n dditionl trp stte tht is equivlent to stte 4.,4,,, 4,, strt 4,, d) By inspetion of the two pths from stte to either stte or stte we n immeditely see tht the lnguge epted y this FA n e desried y the regulr expressions RE = * *. Prolem : Consider the lphet Σ = {,,. Construt DFAs tht ept the following lnguges. Argue tht your DFA is miniml (with respet to the numer of sttes) or use the DFA minimiztion lgorithm to show tht tht is the se.. {w {, w = n, w = m,m,n N. {w {, w = n, n N nd w doesn t ontin the sustring Solution:. strt., 7,, strt 4 Lexil Anlysis Smple Exerises Spring 7

22 University of Southern Cliforni Computer Siene Deprtment Prolem : Develop regulr expression (RE) tht detets the longest string over the lphet {-z with the following properties:. The string egins with n hrter nd ends with z hrter;. After the first, the string n inlude n lterntion of two susequenes, nmely sequene tht egins with hrter followed y zero or more s hrters ending with n e hrter nd susequene tht egins with hrter ut does not hve ny s hrter until terminting t hrter.. If t ny point in the susequene there is x hrter, tht speifi sequene is onsidered terminted, i.e., the x ts s the e hrter in the first type of sequene nd s the t hrter in the seond type of sequene. 4. The two susequenes nnot e nested ut n e repeted in ny lternting order. As n exmple, the string sssefghtsez is to e epted s well s the string ssxfftz Questions: e. Develop regulr expression tht ptures the struture of the eptle strings desried ove. Use short-hnds to pture susets of hrters in the lphet so tht your desription nd the orresponding FA re kept short. f. Using the regulr expression define in setion ) devise the orresponding Non-Deterministi Finite Automton (NFA) using the Thompson onstrution desried in lss. g. Convert the NFA in setion ) to DFA using the suset onstrution. Show the mpping etween the sttes in the NFA nd the resulting DFA. h. Minimize the DFA derived in setion ) (or show it is lredy miniml) using the itertive refinement lgorithm desried in lss. Solution: ) Among the mny possile solutions for regulr expression the one elow seems to e the most intuitive. Here we use the short-hnd notstx for ll hrters in the lphet exept s nd t i.e., notstx = {-r, u, v, y, z. RE =. [ (. (s * ). (x e) ) (. ( notstx * ). (x t) ) ] *. z ) The NFA elow reflets the struture of the RE presented ove where we hve lso ompressed some e-trnsitions for revity, in prtiulr the ones tht reflet Kleene losure nd lterntion. ℇ ℇ ℇ ℇ s x,e ℇ 7 9 ℇ ℇ ℇ ℇ z 7 strt ℇ ℇ ℇ 4 ℇ /{stx x,t ℇ 8 4 ℇ ) The suset onstrution of this NFA is s shown elow where gin we hve merged trnsitions on hrter with nlogous ehvior. Lexil Anlysis Smple Exerises Spring 7

23 University of Southern Cliforni Computer Siene Deprtment s s 7,9 x,e x,e strt,,,4,7,9,8, x,t,,,4,,,,,,,4,,4,, z z 7 /stx 8, x,t /stx d) The minimiztion of this DFA using the itertive refinement lgorithm is summrized elow. We egin y simple prtitionetween the epting sttes nd the non-epting sttes. This immeditely lows us to isolte the epting stte 7. The seond prtition used the hrter z s the disrimintig token showing tht sttes,,,4,,,, nd,,,4,,4,, my e equivlent. The lst prtition digrms reflet the ft tht ll sttes re disjoint. P P P s s s 7,9 x,e x,e s 7,9 x,e x,e strt,,,4,7,9,8, x,t,,,4,,,,,,,4,,4,, z z 7 strt,,,4,7,9,8, x,t,,,4,,,,,,,4,,4,, z z 7 /stx 8, x,t /stx 8, x,t /stx /stx P4 P P P P s s 7,9 7,9 s x,e s x,e x,e P4 x,e strt,,,4,7,9,8, x,t,,,4,,,,,,,4,,4,, z z 7 P7 strt P,,,4,7,9 P,8, x,t,,,4,,,,,,,4,,4,, z z 7 /stx x,t /stx x,t 8, 8, /stx /stx P P s s P4 s 7,9 x,e x,e 4 s x,e x,e P7 strt P,,,4,7,9 P,8, x,t,,,4,,,,,,,4,,4,, z z 7 strt x,t x,t z /stx x,t /stx 8 8, /stx P8 /stx Lexil Anlysis Smple Exerises Spring 7

24 University of Southern Cliforni Computer Siene Deprtment Prolem : Given the DFA elow over the lphet {, determine the following:. Use the dynmi-progrmming Kleene lgorithm to derive the regulr expression tht denotes the lnguge epted y it. Mke sure your lelling of the DFA sttes is orret nd tht the DFA is ompletely speified, i.e., eh stte hs trnsitions on ll the lphet hrters.. Desrie suintely wht re the words epted y this DFA?, strt Solution:. Use the dynmi-progrmming Kleene lgorithm to derive the regulr expression tht denotes the lnguge epted y it. Mke sure your lelling of the DFA sttes is orret nd tht the DFA is ompletely speified, i.e., eh stte hs trnsitions on ll the lphet hrters. Expressions for k = R = (e) R = () R = () R = Ø R = ( e) R = Ø R = Ø R = () R = ( e) Expressions for k = R = R (R )*R R = (e)(e) * (e) (e) = (e) R = R (R )*R R = (e)(e) * () () = () R = R (R )*R R = (e)(e) * () () = () R = R (R )*R R = R = Ø R = R (R )*R R = R = ( e) R = R (R )*R R = R = Ø R = R (R )*R R = R = Ø R = R (R )*R R = R = () R = R (R )*R R = R = ( e) Expressions for k = R = R (R )*R R = (). ( e) *. Ø (e) = (e) Lexil Anlysis Smple Exerises 4 Spring 7

25 University of Southern Cliforni Computer Siene Deprtment R = R (R )*R R = (). ( e) *. ( e) () = ( + ) R = R (R )*R R = (). ( e) *. Ø () = () R = R (R )*R R = ( e) ( e)* Ø Ø = Ø R = R (R )*R R = ( e) ( e)* ( e) ( e) = ( * ) R = R (R )*R R = ( e) ( e)* Ø Ø = Ø R = R (R )*R R = (). ( e)*. Ø Ø = Ø R = R (R )*R R = (). ( e)*. ( e) () = (). ()* R = R (R )*R R = (). ( e)*. Ø ( e) = ( e) Expressions for k = R = R (R )*R R = (). ()*. Ø (e) = Ø R = R (R )*R R = (). ()*. (). ()* ( + ) R = R (R )*R R = (). ()*. ( e) () = (). ()* R = R (R )*R R = Ø. ()*. Ø Ø = Ø R = R (R )*R R = Ø. ()*. (). ()* ( * ) = ( * ) R = R (R )*R R = Ø. ()*. ( e) Ø = Ø R = R (R )*R R = ( e). ()*. Ø Ø = Ø R = R (R )*R R = ( e). ()*. (). ()* (). ()* = ()*. (). ()* R = R (R )*R R = ( e). ()*. ( e) ( e) = ()* The lnguge reognized y this DFA n e expressed y the regulr expression R. L = R = (). ( e)*. ( e) = (). ( e)* =.*. Desrie suintely wht re the words epted y this DFA? This utomton reognizes ll inries strings tht denote integers tht re non-negtive powers of two nd s suh n e desried y the ompt regulr expression: *. Prolem 4: Consider the finite utomton elow over the lphet å = {, nd with strting stte. strt,!! 4 For this utomton, nswer the following questions:. Why is this Non-Deterministi Finite Automton (NFA)?. Convert the NFA in setion ) to DFA using the suset onstrution. Show the mpping etween the sttes in the NFA nd the resulting DFA.. Minimize the DFA derived in setion ) (or show it is lredy miniml) using the itertive refinement lgorithm desried in lss. Lexil Anlysis Smple Exerises Spring 7

26 University of Southern Cliforni Computer Siene Deprtment d. Desrie in your own words the lnguge reognized y this utomton nd present possile regulr expression tht represents this lnguge. Solution: ) Why is this Non-Deterministi Finite Automton (NFA)? This FA is NFA s there is t lest one stte out of whih there re two trnsitions lelled with the sme lphet symol (in this se stte ). Also, for sttes nd 4 we hve e-trnsitions. ) Convert the NFA in setion ) to DFA using the suset onstrution. Show the mpping etween the sttes in the NFA nd the resulting DFA. The resulting DFA is s shown elow.,,4, strt,,4,,,4,4, ) Minimize the DFA derived in setion ) (or show it is lredy miniml) using the itertive refinement lgorithm desried in lss. The figure elow depits the vrious refinement steps, resulting in miniml DFA with 4 sttes. Lexil Anlysis Smple Exerises Spring 7

27 University of Southern Cliforni Computer Siene Deprtment,,4 P,,4 P, P, strt P,,4, strt,,4,,,,4,4,,4,4, () Prtition on Aepting vs. Non-Aepting Sttes () Prtition of P on / trnsitions. P,,4 P strt P,,,4, strt,,,4,4, () Prtition of P on / trnsitions. (d) Finl prtition. d) Desrie in your own words the lnguge reognized y this utomton. This DFA reognizes ll strings over the lphet å = {, tht hve t lest one symol nd re proeeded y t most one symol. A possile regulr expression for this lnguge is RE =?. + or lterntively, RE = ( e). +. Prolem : In this prolem, we onsider the trnsltion of strings with integer vlues into omm-seprted-vlue (sv) formt. The input string onsists of sequene of one or more letters or numeril s (forming n identifier) followed y one or more lnk spe hrters to whih we hve set of three integers seprted y the - hrter nd terminted y newline ( \n ) hrter. The diffiulty rises from the ft tht the first integer n e negtive integer nd thus egins with the - hrter ut the two susequent integers re ssumed to e positive. The output string hs ll - hrter, exept the first, repled y n opening (, : nd ) hrter respetively. Below you n find ouple of exmples of the intended trnsltion sheme where the \n stnds for the new-line hrter: Input F --- \n DX -- \n Output F, (-:), \n DX, (:), \n Lexil Anlysis Smple Exerises 7 Spring 7

28 University of Southern Cliforni Computer Siene Deprtment String tht do not omply with the strutured desried re not to e trnslted nd the resulting trnsltion genertes n error ondition. We n model this ondition y hving the trnsltion progrm emit n error messge s desried in more detil in setion d). For this trnsltion sheme, nswer the following questions:. Derive regulr expression RE over the ASCII hrter lphet tht ptures vlid strings nd thus invlid strings.. Convert the RE developed in ) into n NFA using the Thompson onstrution.. Convert the NFA derived in setion ) to DFA using the suset onstrution. Show the mpping etween the sttes in the NFA nd the resulting DFA. d. Minimize the DFA derived in setion ) (or show it is lredy miniml) using the itertive refinement lgorithm desried in lss. e. Using the C ode skeleton desried in lss for the implementtion of DFA with tle, implement C ode funtion tht n reognize vlid strings mthing the RE derived in ). Whenever n error ondition is deteted, your implementtion should print the error string. Solution: ) Derive regulr expression RE over the ASCII hrter lphet tht ptures vlid strings nd thus invlid strings. A regulr expression (not neessrily unique) ould e desried s shown elow where letter denotes n lpheti hrter nd numeril etween nd 9. Also, lnk denotes spe hrter, int denotes string representing n integer (oth positive or negtive) nd posint denotes string exlusively representing positive integer. Lstly,. denotes regulr expression ontention nd lterntion. RE = {letter.({letter {)*.{lnk+.{int - {posint - {posint.{lnk*. \n letter = (,,, z ) = (,,, 9 ) posint = {+ int = ( - e).{+ ) Convert the RE developed in ) into n NFA using the Thompson onstrution. A simplified version of the NFA resulting from the use of the Thompson onstrution for the RE desried in ) ove is shown elow. For omptness, we summrized multiple identil stte trnsitions on vrious hrters, suh s trnsitions on ll lpheti hrters s single stte trnsition. The strt stte is the stte leled. All omitted trnsitions impliitly denote trnsition to n error trp stte, sy S error. strt letter, lnk '-' letter lnk! 4 '-' '-' 7 8 lnk lnk! 9! ) Convert the NFA derived in setion ) to DFA using the suset onstrution. Show the mpping etween the sttes in the NFA nd the resulting DFA. The figure elow depits the DFA resulting from the use of the suset onstrution. Eh DFA stte is lelled y the orresponding suset of sttes of the originl NFA. Lexil Anlysis Smple Exerises 8 Spring 7

29 University of Southern Cliforni Computer Siene Deprtment letter, lnk lnk strt letter lnk { { '-' {, { {4 '-' { { '-' {7 lnk {8, {9, d) Minimize the DFA derived in setion ) (or show it is lredy miniml) using the itertive refinement lgorithm desried in lss. letter, lnk P P lnk strt letter lnk { { '-' {, { {4 '-' { { '-' {7 lnk {8, {9, () Prtition on Aepting vs. Non-Aepting Sttes letter, lnk P P8 P9 lnk strt letter lnk { { '-' {, { {4 '-' { { '-' {7 lnk {8, {9, () Refinement of P on (note tht error stte trnsitions mke the differene etween sttes {8, nd {9,) P P P P4 P P P7 lnk letter, P8 P9 lnk strt letter lnk { { '-' {, { {4 '-' { { '-' {7 lnk {8, {9, () Finl refinement. letter, lnk lnk strt letter lnk s s '-' s s s4 '-' s s '-' s7 lnk s8 s9 (d) DFA with relelled sttes (trp error stte omitted for omptness) e) Using the C ode skeleton desried in lss for the implementtion of DFA with tle, implement C ode funtion tht n reognize vlid strings mthing the RE derived in ). Whenever n error ondition is deteted, your implementtion should print the error string. Lexil Anlysis Smple Exerises 9 Spring 7

30 University of Southern Cliforni Computer Siene Deprtment #inlude <stdio.h> #inlude <stdli.h> #inlude <strings.h> #inlude <type.h> #define error_stte - int urrent_stte; int delt(hr ){ swith(urrent_stte){ se : if(islph()!= ){ printf("%",); return ; return error_stte; rek; se : if((islph()!= ) (is()!= )){ printf("%",); return ; if( == ' '){ printf("%, ",); return ; return error_stte; rek; se : if( == ' '){ return ; if( == '-'){ printf("(-"); return ; if(is()!= ){ printf("(%",); return 4; return error_stte; rek; se : if(is()!= ){ printf("%",); return 4; return error_stte; rek; se 4: if(is()!= ){ printf("%",); return 4; if( == '-'){ printf(":"); return ; return error_stte; rek; se : if(is()!= ){ printf("%",); return ; return error_stte; rek; se : if(is()!= ){ printf("%",); return ; if( == '-'){ printf("), "); return 7; return error_stte; rek; se 7: if(is()!= ){ printf("%",); return 8; return error_stte; rek; se 8: if(is()!= ){ printf("%",); return 8; if( == ' '){ printf(" "); return 9; return error_stte; rek; se 9: if( == ' '){ return 9; return error_stte; rek; se : rek; defult: return error_stte; return error_stte; int min (int rg, hr ** rgv){ hr ; urrent_stte = ; while(){ = gethr(); if( == '\n') rek; urrent_stte = delt(); if(urrent_stte == error_stte){ rek; if((urrent_stte == 8) (urrent_stte == 9)){ printf(" Vlid string\n"); else { printf(" error \n"); return ; Lexil Anlysis Smple Exerises Spring 7

Compiler Design. Fall Lexical Analysis. Sample Exercises and Solutions. Prof. Pedro C. Diniz

Compiler Design. Fall Lexical Analysis. Sample Exercises and Solutions. Prof. Pedro C. Diniz University of Southern Cliforni Computer Science Deprtment Compiler Design Fll Lexicl Anlysis Smple Exercises nd Solutions Prof. Pedro C. Diniz USC / Informtion Sciences Institute 4676 Admirlty Wy, Suite

More information

Compiler Design. Fall Lexical Analysis. Sample Exercises and Solutions. Prof. Pedro C. Diniz

Compiler Design. Fall Lexical Analysis. Sample Exercises and Solutions. Prof. Pedro C. Diniz Univerity of Southern Cliforni Computer Siene Deprtment Compiler Deign Fll 6 Lexil Anlyi Smple Exerie nd Solution Prof. Pedro C. Dini USC / Informtion Siene Intitute 4676 Admirlty Wy, Suite Mrin del Rey,

More information

CS 573 Automata Theory and Formal Languages

CS 573 Automata Theory and Formal Languages Non-determinism Automt Theory nd Forml Lnguges Professor Leslie Lnder Leture # 3 Septemer 6, 2 To hieve our gol, we need the onept of Non-deterministi Finite Automton with -moves (NFA) An NFA is tuple

More information

The University of Nottingham SCHOOL OF COMPUTER SCIENCE A LEVEL 2 MODULE, SPRING SEMESTER MACHINES AND THEIR LANGUAGES ANSWERS

The University of Nottingham SCHOOL OF COMPUTER SCIENCE A LEVEL 2 MODULE, SPRING SEMESTER MACHINES AND THEIR LANGUAGES ANSWERS The University of ottinghm SCHOOL OF COMPUTR SCIC A LVL 2 MODUL, SPRIG SMSTR 2015 2016 MACHIS AD THIR LAGUAGS ASWRS Time llowed TWO hours Cndidtes my omplete the front over of their nswer ook nd sign their

More information

NON-DETERMINISTIC FSA

NON-DETERMINISTIC FSA Tw o types of non-determinism: NON-DETERMINISTIC FS () Multiple strt-sttes; strt-sttes S Q. The lnguge L(M) ={x:x tkes M from some strt-stte to some finl-stte nd ll of x is proessed}. The string x = is

More information

CSCI565 - Compiler Design

CSCI565 - Compiler Design CSCI565 - Compiler Deign Spring 6 Due Dte: Fe. 5, 6 t : PM in Cl Prolem [ point]: Regulr Expreion nd Finite Automt Develop regulr expreion (RE) tht detet the longet tring over the lphet {-} with the following

More information

CS311 Computational Structures Regular Languages and Regular Grammars. Lecture 6

CS311 Computational Structures Regular Languages and Regular Grammars. Lecture 6 CS311 Computtionl Strutures Regulr Lnguges nd Regulr Grmmrs Leture 6 1 Wht we know so fr: RLs re losed under produt, union nd * Every RL n e written s RE, nd every RE represents RL Every RL n e reognized

More information

= state, a = reading and q j

= state, a = reading and q j 4 Finite Automt CHAPTER 2 Finite Automt (FA) (i) Derterministi Finite Automt (DFA) A DFA, M Q, q,, F, Where, Q = set of sttes (finite) q Q = the strt/initil stte = input lphet (finite) (use only those

More information

Nondeterministic Automata vs Deterministic Automata

Nondeterministic Automata vs Deterministic Automata Nondeterministi Automt vs Deterministi Automt We lerned tht NFA is onvenient model for showing the reltionships mong regulr grmmrs, FA, nd regulr expressions, nd designing them. However, we know tht n

More information

Regular languages refresher

Regular languages refresher Regulr lnguges refresher 1 Regulr lnguges refresher Forml lnguges Alphet = finite set of letters Word = sequene of letter Lnguge = set of words Regulr lnguges defined equivlently y Regulr expressions Finite-stte

More information

Nondeterministic Finite Automata

Nondeterministic Finite Automata Nondeterministi Finite utomt The Power of Guessing Tuesdy, Otoer 4, 2 Reding: Sipser.2 (first prt); Stoughton 3.3 3.5 S235 Lnguges nd utomt eprtment of omputer Siene Wellesley ollege Finite utomton (F)

More information

Finite State Automata and Determinisation

Finite State Automata and Determinisation Finite Stte Automt nd Deterministion Tim Dworn Jnury, 2016 Lnguges fs nf re df Deterministion 2 Outline 1 Lnguges 2 Finite Stte Automt (fs) 3 Non-deterministi Finite Stte Automt (nf) 4 Regulr Expressions

More information

Technische Universität München Winter term 2009/10 I7 Prof. J. Esparza / J. Křetínský / M. Luttenberger 11. Februar Solution

Technische Universität München Winter term 2009/10 I7 Prof. J. Esparza / J. Křetínský / M. Luttenberger 11. Februar Solution Tehnishe Universität Münhen Winter term 29/ I7 Prof. J. Esprz / J. Křetínský / M. Luttenerger. Ferur 2 Solution Automt nd Forml Lnguges Homework 2 Due 5..29. Exerise 2. Let A e the following finite utomton:

More information

Project 6: Minigoals Towards Simplifying and Rewriting Expressions

Project 6: Minigoals Towards Simplifying and Rewriting Expressions MAT 51 Wldis Projet 6: Minigols Towrds Simplifying nd Rewriting Expressions The distriutive property nd like terms You hve proly lerned in previous lsses out dding like terms ut one prolem with the wy

More information

Prefix-Free Regular-Expression Matching

Prefix-Free Regular-Expression Matching Prefix-Free Regulr-Expression Mthing Yo-Su Hn, Yjun Wng nd Derik Wood Deprtment of Computer Siene HKUST Prefix-Free Regulr-Expression Mthing p.1/15 Pttern Mthing Given pttern P nd text T, find ll sustrings

More information

Minimal DFA. minimal DFA for L starting from any other

Minimal DFA. minimal DFA for L starting from any other Miniml DFA Among the mny DFAs ccepting the sme regulr lnguge L, there is exctly one (up to renming of sttes) which hs the smllest possile numer of sttes. Moreover, it is possile to otin tht miniml DFA

More information

CS103B Handout 18 Winter 2007 February 28, 2007 Finite Automata

CS103B Handout 18 Winter 2007 February 28, 2007 Finite Automata CS103B ndout 18 Winter 2007 Ferury 28, 2007 Finite Automt Initil text y Mggie Johnson. Introduction Severl childrens gmes fit the following description: Pieces re set up on plying ord; dice re thrown or

More information

Worked out examples Finite Automata

Worked out examples Finite Automata Worked out exmples Finite Automt Exmple Design Finite Stte Automton which reds inry string nd ccepts only those tht end with. Since we re in the topic of Non Deterministic Finite Automt (NFA), we will

More information

Computational Biology Lecture 18: Genome rearrangements, finding maximal matches Saad Mneimneh

Computational Biology Lecture 18: Genome rearrangements, finding maximal matches Saad Mneimneh Computtionl Biology Leture 8: Genome rerrngements, finding miml mthes Sd Mneimneh We hve seen how to rerrnge genome to otin nother one sed on reversls nd the knowledge of the preserved loks or genes. Now

More information

Assignment 1 Automata, Languages, and Computability. 1 Finite State Automata and Regular Languages

Assignment 1 Automata, Languages, and Computability. 1 Finite State Automata and Regular Languages Deprtment of Computer Science, Austrlin Ntionl University COMP2600 Forml Methods for Softwre Engineering Semester 2, 206 Assignment Automt, Lnguges, nd Computility Smple Solutions Finite Stte Automt nd

More information

1 PYTHAGORAS THEOREM 1. Given a right angled triangle, the square of the hypotenuse is equal to the sum of the squares of the other two sides.

1 PYTHAGORAS THEOREM 1. Given a right angled triangle, the square of the hypotenuse is equal to the sum of the squares of the other two sides. 1 PYTHAGORAS THEOREM 1 1 Pythgors Theorem In this setion we will present geometri proof of the fmous theorem of Pythgors. Given right ngled tringle, the squre of the hypotenuse is equl to the sum of the

More information

Homework 3 Solutions

Homework 3 Solutions CS 341: Foundtions of Computer Science II Prof. Mrvin Nkym Homework 3 Solutions 1. Give NFAs with the specified numer of sttes recognizing ech of the following lnguges. In ll cses, the lphet is Σ = {,1}.

More information

1 Nondeterministic Finite Automata

1 Nondeterministic Finite Automata 1 Nondeterministic Finite Automt Suppose in life, whenever you hd choice, you could try oth possiilities nd live your life. At the end, you would go ck nd choose the one tht worked out the est. Then you

More information

Convert the NFA into DFA

Convert the NFA into DFA Convert the NF into F For ech NF we cn find F ccepting the sme lnguge. The numer of sttes of the F could e exponentil in the numer of sttes of the NF, ut in prctice this worst cse occurs rrely. lgorithm:

More information

Let's start with an example:

Let's start with an example: Finite Automt Let's strt with n exmple: Here you see leled circles tht re sttes, nd leled rrows tht re trnsitions. One of the sttes is mrked "strt". One of the sttes hs doule circle; this is terminl stte

More information

NFA DFA Example 3 CMSC 330: Organization of Programming Languages. Equivalence of DFAs and NFAs. Equivalence of DFAs and NFAs (cont.

NFA DFA Example 3 CMSC 330: Organization of Programming Languages. Equivalence of DFAs and NFAs. Equivalence of DFAs and NFAs (cont. NFA DFA Exmple 3 CMSC 330: Orgniztion of Progrmming Lnguges NFA {B,D,E {A,E {C,D {E Finite Automt, con't. R = { {A,E, {B,D,E, {C,D, {E 2 Equivlence of DFAs nd NFAs Any string from {A to either {D or {CD

More information

2.4 Theoretical Foundations

2.4 Theoretical Foundations 2 Progrmming Lnguge Syntx 2.4 Theoretil Fountions As note in the min text, snners n prsers re se on the finite utomt n pushown utomt tht form the ottom two levels of the Chomsky lnguge hierrhy. At eh level

More information

Regular expressions, Finite Automata, transition graphs are all the same!!

Regular expressions, Finite Automata, transition graphs are all the same!! CSI 3104 /Winter 2011: Introduction to Forml Lnguges Chpter 7: Kleene s Theorem Chpter 7: Kleene s Theorem Regulr expressions, Finite Automt, trnsition grphs re ll the sme!! Dr. Neji Zgui CSI3104-W11 1

More information

Discrete Structures, Test 2 Monday, March 28, 2016 SOLUTIONS, VERSION α

Discrete Structures, Test 2 Monday, March 28, 2016 SOLUTIONS, VERSION α Disrete Strutures, Test 2 Mondy, Mrh 28, 2016 SOLUTIONS, VERSION α α 1. (18 pts) Short nswer. Put your nswer in the ox. No prtil redit. () Consider the reltion R on {,,, d with mtrix digrph of R.. Drw

More information

CS 373, Spring Solutions to Mock midterm 1 (Based on first midterm in CS 273, Fall 2008.)

CS 373, Spring Solutions to Mock midterm 1 (Based on first midterm in CS 273, Fall 2008.) CS 373, Spring 29. Solutions to Mock midterm (sed on first midterm in CS 273, Fll 28.) Prolem : Short nswer (8 points) The nswers to these prolems should e short nd not complicted. () If n NF M ccepts

More information

CMPSCI 250: Introduction to Computation. Lecture #31: What DFA s Can and Can t Do David Mix Barrington 9 April 2014

CMPSCI 250: Introduction to Computation. Lecture #31: What DFA s Can and Can t Do David Mix Barrington 9 April 2014 CMPSCI 250: Introduction to Computtion Lecture #31: Wht DFA s Cn nd Cn t Do Dvid Mix Brrington 9 April 2014 Wht DFA s Cn nd Cn t Do Deterministic Finite Automt Forml Definition of DFA s Exmples of DFA

More information

1 From NFA to regular expression

1 From NFA to regular expression Note 1: How to convert DFA/NFA to regulr expression Version: 1.0 S/EE 374, Fll 2017 Septemer 11, 2017 In this note, we show tht ny DFA cn e converted into regulr expression. Our construction would work

More information

Running an NFA & the subset algorithm (NFA->DFA) CS 350 Fall 2018 gilray.org/classes/fall2018/cs350/

Running an NFA & the subset algorithm (NFA->DFA) CS 350 Fall 2018 gilray.org/classes/fall2018/cs350/ Running n NFA & the suset lgorithm (NFA->DFA) CS 350 Fll 2018 gilry.org/lsses/fll2018/s350/ 1 NFAs operte y simultneously exploring ll pths nd epting if ny pth termintes t n ept stte.!2 Try n exmple: L

More information

CMSC 330: Organization of Programming Languages

CMSC 330: Organization of Programming Languages CMSC 330: Orgniztion of Progrmming Lnguges Finite Automt 2 CMSC 330 1 Types of Finite Automt Deterministic Finite Automt (DFA) Exctly one sequence of steps for ech string All exmples so fr Nondeterministic

More information

Chapter 4 State-Space Planning

Chapter 4 State-Space Planning Leture slides for Automted Plnning: Theory nd Prtie Chpter 4 Stte-Spe Plnning Dn S. Nu CMSC 722, AI Plnning University of Mrylnd, Spring 2008 1 Motivtion Nerly ll plnning proedures re serh proedures Different

More information

Alpha Algorithm: Limitations

Alpha Algorithm: Limitations Proess Mining: Dt Siene in Ation Alph Algorithm: Limittions prof.dr.ir. Wil vn der Alst www.proessmining.org Let L e n event log over T. α(l) is defined s follows. 1. T L = { t T σ L t σ}, 2. T I = { t

More information

First Midterm Examination

First Midterm Examination Çnky University Deprtment of Computer Engineering 203-204 Fll Semester First Midterm Exmintion ) Design DFA for ll strings over the lphet Σ = {,, c} in which there is no, no nd no cc. 2) Wht lnguge does

More information

Section 1.3 Triangles

Section 1.3 Triangles Se 1.3 Tringles 21 Setion 1.3 Tringles LELING TRINGLE The line segments tht form tringle re lled the sides of the tringle. Eh pir of sides forms n ngle, lled n interior ngle, nd eh tringle hs three interior

More information

@#? Text Search ] { "!" Nondeterministic Finite Automata. Transformation NFA to DFA and Simulation of NFA. Text Search Using Automata

@#? Text Search ] { ! Nondeterministic Finite Automata. Transformation NFA to DFA and Simulation of NFA. Text Search Using Automata g Text Serh @#? ~ Mrko Berezovský Rdek Mřík PAL 0 Nondeterministi Finite Automt n Trnsformtion NFA to DFA nd Simultion of NFA f Text Serh Using Automt A B R Power of Nondeterministi Approh u j Regulr Expression

More information

Algorithms & Data Structures Homework 8 HS 18 Exercise Class (Room & TA): Submitted by: Peer Feedback by: Points:

Algorithms & Data Structures Homework 8 HS 18 Exercise Class (Room & TA): Submitted by: Peer Feedback by: Points: Eidgenössishe Tehnishe Hohshule Zürih Eole polytehnique fédérle de Zurih Politenio federle di Zurigo Federl Institute of Tehnology t Zurih Deprtement of Computer Siene. Novemer 0 Mrkus Püshel, Dvid Steurer

More information

CSE 401 Compilers. Today s Agenda

CSE 401 Compilers. Today s Agenda CSE 401 Compilers Leture 3: Regulr Expressions & Snning, on?nued Mihel Ringenurg Tody s Agend Lst?me we reviewed lnguges nd grmmrs, nd riefly strted disussing regulr expressions. Tody I ll restrt the regulr

More information

Test Generation from Timed Input Output Automata

Test Generation from Timed Input Output Automata Chpter 8 Test Genertion from Timed Input Output Automt The purpose of this hpter is to introdue tehniques for the genertion of test dt from models of softwre sed on vrints of timed utomt. The tests generted

More information

Designing finite automata II

Designing finite automata II Designing finite utomt II Prolem: Design DFA A such tht L(A) consists of ll strings of nd which re of length 3n, for n = 0, 1, 2, (1) Determine wht to rememer out the input string Assign stte to ech of

More information

CS241 Week 6 Tutorial Solutions

CS241 Week 6 Tutorial Solutions 241 Week 6 Tutoril olutions Lnguges: nning & ontext-free Grmmrs Winter 2018 1 nning Exerises 1. 0x0x0xd HEXINT 0x0 I x0xd 2. 0xend--- HEXINT 0xe I nd ER -- MINU - 3. 1234-120x INT 1234 INT -120 I x 4.

More information

Thoery of Automata CS402

Thoery of Automata CS402 Thoery of Automt C402 Theory of Automt Tle of contents: Lecture N0. 1... 4 ummry... 4 Wht does utomt men?... 4 Introduction to lnguges... 4 Alphets... 4 trings... 4 Defining Lnguges... 5 Lecture N0. 2...

More information

Formal Languages and Automata

Formal Languages and Automata Moile Computing nd Softwre Engineering p. 1/5 Forml Lnguges nd Automt Chpter 2 Finite Automt Chun-Ming Liu cmliu@csie.ntut.edu.tw Deprtment of Computer Science nd Informtion Engineering Ntionl Tipei University

More information

AUTOMATA AND LANGUAGES. Definition 1.5: Finite Automaton

AUTOMATA AND LANGUAGES. Definition 1.5: Finite Automaton 25. Finite Automt AUTOMATA AND LANGUAGES A system of computtion tht only hs finite numer of possile sttes cn e modeled using finite utomton A finite utomton is often illustrted s stte digrm d d d. d q

More information

Types of Finite Automata. CMSC 330: Organization of Programming Languages. Comparing DFAs and NFAs. NFA for (a b)*abb.

Types of Finite Automata. CMSC 330: Organization of Programming Languages. Comparing DFAs and NFAs. NFA for (a b)*abb. CMSC 330: Orgniztion of Progrmming Lnguges Finite Automt 2 Types of Finite Automt Deterministic Finite Automt () Exctly one sequence of steps for ech string All exmples so fr Nondeterministic Finite Automt

More information

Types of Finite Automata. CMSC 330: Organization of Programming Languages. Comparing DFAs and NFAs. Comparing DFAs and NFAs (cont.) Finite Automata 2

Types of Finite Automata. CMSC 330: Organization of Programming Languages. Comparing DFAs and NFAs. Comparing DFAs and NFAs (cont.) Finite Automata 2 CMSC 330: Orgniztion of Progrmming Lnguges Finite Automt 2 Types of Finite Automt Deterministic Finite Automt () Exctly one sequence of steps for ech string All exmples so fr Nondeterministic Finite Automt

More information

CS415 Compilers. Lexical Analysis and. These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University

CS415 Compilers. Lexical Analysis and. These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University CS415 Compilers Lexicl Anlysis nd These slides re sed on slides copyrighted y Keith Cooper, Ken Kennedy & Lind Torczon t Rice University First Progrmming Project Instruction Scheduling Project hs een posted

More information

Table of contents: Lecture N Summary... 3 What does automata mean?... 3 Introduction to languages... 3 Alphabets... 3 Strings...

Table of contents: Lecture N Summary... 3 What does automata mean?... 3 Introduction to languages... 3 Alphabets... 3 Strings... Tle of contents: Lecture N0.... 3 ummry... 3 Wht does utomt men?... 3 Introduction to lnguges... 3 Alphets... 3 trings... 3 Defining Lnguges... 4 Lecture N0. 2... 7 ummry... 7 Kleene tr Closure... 7 Recursive

More information

CSCI 340: Computational Models. Kleene s Theorem. Department of Computer Science

CSCI 340: Computational Models. Kleene s Theorem. Department of Computer Science CSCI 340: Computtionl Models Kleene s Theorem Chpter 7 Deprtment of Computer Science Unifiction In 1954, Kleene presented (nd proved) theorem which (in our version) sttes tht if lnguge cn e defined y ny

More information

Descriptional Complexity of Non-Unary Self-Verifying Symmetric Difference Automata

Descriptional Complexity of Non-Unary Self-Verifying Symmetric Difference Automata Desriptionl Complexity of Non-Unry Self-Verifying Symmetri Differene Automt Lurette Mris 1,2 nd Lynette vn Zijl 1 1 Deprtment of Computer Siene, Stellenosh University, South Afri 2 Merk Institute, CSIR,

More information

TOPIC: LINEAR ALGEBRA MATRICES

TOPIC: LINEAR ALGEBRA MATRICES Interntionl Blurete LECTUE NOTES for FUTHE MATHEMATICS Dr TOPIC: LINEA ALGEBA MATICES. DEFINITION OF A MATIX MATIX OPEATIONS.. THE DETEMINANT deta THE INVESE A -... SYSTEMS OF LINEA EQUATIONS. 8. THE AUGMENTED

More information

1. For each of the following theorems, give a two or three sentence sketch of how the proof goes or why it is not true.

1. For each of the following theorems, give a two or three sentence sketch of how the proof goes or why it is not true. York University CSE 2 Unit 3. DFA Clsses Converting etween DFA, NFA, Regulr Expressions, nd Extended Regulr Expressions Instructor: Jeff Edmonds Don t chet y looking t these nswers premturely.. For ech

More information

Lecture 08: Feb. 08, 2019

Lecture 08: Feb. 08, 2019 4CS4-6:Theory of Computtion(Closure on Reg. Lngs., regex to NDFA, DFA to regex) Prof. K.R. Chowdhry Lecture 08: Fe. 08, 2019 : Professor of CS Disclimer: These notes hve not een sujected to the usul scrutiny

More information

Formal languages, automata, and theory of computation

Formal languages, automata, and theory of computation Mälrdlen University TEN1 DVA337 2015 School of Innovtion, Design nd Engineering Forml lnguges, utomt, nd theory of computtion Thursdy, Novemer 5, 14:10-18:30 Techer: Dniel Hedin, phone 021-107052 The exm

More information

First Midterm Examination

First Midterm Examination 24-25 Fll Semester First Midterm Exmintion ) Give the stte digrm of DFA tht recognizes the lnguge A over lphet Σ = {, } where A = {w w contins or } 2) The following DFA recognizes the lnguge B over lphet

More information

CS 301. Lecture 04 Regular Expressions. Stephen Checkoway. January 29, 2018

CS 301. Lecture 04 Regular Expressions. Stephen Checkoway. January 29, 2018 CS 301 Lecture 04 Regulr Expressions Stephen Checkowy Jnury 29, 2018 1 / 35 Review from lst time NFA N = (Q, Σ, δ, q 0, F ) where δ Q Σ P (Q) mps stte nd n lphet symol (or ) to set of sttes We run n NFA

More information

CS 311 Homework 3 due 16:30, Thursday, 14 th October 2010

CS 311 Homework 3 due 16:30, Thursday, 14 th October 2010 CS 311 Homework 3 due 16:30, Thursdy, 14 th Octoer 2010 Homework must e sumitted on pper, in clss. Question 1. [15 pts.; 5 pts. ech] Drw stte digrms for NFAs recognizing the following lnguges:. L = {w

More information

Grammar. Languages. Content 5/10/16. Automata and Languages. Regular Languages. Regular Languages

Grammar. Languages. Content 5/10/16. Automata and Languages. Regular Languages. Regular Languages 5//6 Grmmr Automt nd Lnguges Regulr Grmmr Context-free Grmmr Context-sensitive Grmmr Prof. Mohmed Hmd Softwre Engineering L. The University of Aizu Jpn Regulr Lnguges Context Free Lnguges Context Sensitive

More information

6.5 Improper integrals

6.5 Improper integrals Eerpt from "Clulus" 3 AoPS In. www.rtofprolemsolving.om 6.5. IMPROPER INTEGRALS 6.5 Improper integrls As we ve seen, we use the definite integrl R f to ompute the re of the region under the grph of y =

More information

System Validation (IN4387) November 2, 2012, 14:00-17:00

System Validation (IN4387) November 2, 2012, 14:00-17:00 System Vlidtion (IN4387) Novemer 2, 2012, 14:00-17:00 Importnt Notes. The exmintion omprises 5 question in 4 pges. Give omplete explntion nd do not onfine yourself to giving the finl nswer. Good luk! Exerise

More information

THEORY OF FORMAL LANGUAGES EXERCISE BOOK. A Suite of Exercises with Solutions DRAFT COPY

THEORY OF FORMAL LANGUAGES EXERCISE BOOK. A Suite of Exercises with Solutions DRAFT COPY THEORY OF FORMAL LANGUAGES EXERCISE BOOK A Suite of Exerises with Solutions DRAFT COPY Lu Breveglieri ollortors Gimpolo Agost Alessndro Brenghi Ann Beletsk Stefno Crespi Reghizzi Bernrdo Dl Seno Vinenzo

More information

The University of Nottingham SCHOOL OF COMPUTER SCIENCE A LEVEL 2 MODULE, SPRING SEMESTER LANGUAGES AND COMPUTATION ANSWERS

The University of Nottingham SCHOOL OF COMPUTER SCIENCE A LEVEL 2 MODULE, SPRING SEMESTER LANGUAGES AND COMPUTATION ANSWERS The University of Nottinghm SCHOOL OF COMPUTER SCIENCE LEVEL 2 MODULE, SPRING SEMESTER 2016 2017 LNGUGES ND COMPUTTION NSWERS Time llowed TWO hours Cndidtes my complete the front cover of their nswer ook

More information

Global alignment. Genome Rearrangements Finding preserved genes. Lecture 18

Global alignment. Genome Rearrangements Finding preserved genes. Lecture 18 Computt onl Biology Leture 18 Genome Rerrngements Finding preserved genes We hve seen before how to rerrnge genome to obtin nother one bsed on: Reversls Knowledge of preserved bloks (or genes) Now we re

More information

Bottom-Up Parsing. Canonical Collection of LR(0) items. Part II

Bottom-Up Parsing. Canonical Collection of LR(0) items. Part II 2 ottom-up Prsing Prt II 1 Cnonil Colletion of LR(0) items CC_LR(0)_I items(g :ugmented_grmmr){ C = {CLOURE({ })} ; repet{ foreh(i C) foreh(grmmr symol X) if(goto(i,x) && GOTO(I,X) C) C = C {GOTO(I,X)};

More information

FABER Formal Languages, Automata and Models of Computation

FABER Formal Languages, Automata and Models of Computation DVA337 FABER Forml Lnguges, Automt nd Models of Computtion Lecture 5 chool of Innovtion, Design nd Engineering Mälrdlen University 2015 1 Recp of lecture 4 y definition suset construction DFA NFA stte

More information

Instructions. An 8.5 x 11 Cheat Sheet may also be used as an aid for this test. MUST be original handwriting.

Instructions. An 8.5 x 11 Cheat Sheet may also be used as an aid for this test. MUST be original handwriting. ID: B CSE 2021 Computer Orgniztion Midterm Test (Fll 2009) Instrutions This is losed ook, 80 minutes exm. The MIPS referene sheet my e used s n id for this test. An 8.5 x 11 Chet Sheet my lso e used s

More information

Java II Finite Automata I

Java II Finite Automata I Jv II Finite Automt I Bernd Kiefer Bernd.Kiefer@dfki.de Deutsches Forschungszentrum für künstliche Intelligenz Finite Automt I p.1/13 Processing Regulr Expressions We lredy lerned out Jv s regulr expression

More information

3 Regular expressions

3 Regular expressions 3 Regulr expressions Given n lphet Σ lnguge is set of words L Σ. So fr we were le to descrie lnguges either y using set theory (i.e. enumertion or comprehension) or y n utomton. In this section we shll

More information

Chapter 3. Vector Spaces. 3.1 Images and Image Arithmetic

Chapter 3. Vector Spaces. 3.1 Images and Image Arithmetic Chpter 3 Vetor Spes In Chpter 2, we sw tht the set of imges possessed numer of onvenient properties. It turns out tht ny set tht possesses similr onvenient properties n e nlyzed in similr wy. In liner

More information

Discrete Structures Lecture 11

Discrete Structures Lecture 11 Introdution Good morning. In this setion we study funtions. A funtion is mpping from one set to nother set or, perhps, from one set to itself. We study the properties of funtions. A mpping my not e funtion.

More information

I1 = I2 I1 = I2 + I3 I1 + I2 = I3 + I4 I 3

I1 = I2 I1 = I2 + I3 I1 + I2 = I3 + I4 I 3 2 The Prllel Circuit Electric Circuits: Figure 2- elow show ttery nd multiple resistors rrnged in prllel. Ech resistor receives portion of the current from the ttery sed on its resistnce. The split is

More information

Lesson 2: The Pythagorean Theorem and Similar Triangles. A Brief Review of the Pythagorean Theorem.

Lesson 2: The Pythagorean Theorem and Similar Triangles. A Brief Review of the Pythagorean Theorem. 27 Lesson 2: The Pythgoren Theorem nd Similr Tringles A Brief Review of the Pythgoren Theorem. Rell tht n ngle whih mesures 90º is lled right ngle. If one of the ngles of tringle is right ngle, then we

More information

12.4 Similarity in Right Triangles

12.4 Similarity in Right Triangles Nme lss Dte 12.4 Similrit in Right Tringles Essentil Question: How does the ltitude to the hpotenuse of right tringle help ou use similr right tringles to solve prolems? Eplore Identifing Similrit in Right

More information

THE PYTHAGOREAN THEOREM

THE PYTHAGOREAN THEOREM THE PYTHAGOREAN THEOREM The Pythgoren Theorem is one of the most well-known nd widely used theorems in mthemtis. We will first look t n informl investigtion of the Pythgoren Theorem, nd then pply this

More information

22: Union Find. CS 473u - Algorithms - Spring April 14, We want to maintain a collection of sets, under the operations of:

22: Union Find. CS 473u - Algorithms - Spring April 14, We want to maintain a collection of sets, under the operations of: 22: Union Fin CS 473u - Algorithms - Spring 2005 April 14, 2005 1 Union-Fin We wnt to mintin olletion of sets, uner the opertions of: 1. MkeSet(x) - rete set tht ontins the single element x. 2. Fin(x)

More information

Lecture Notes No. 10

Lecture Notes No. 10 2.6 System Identifition, Estimtion, nd Lerning Leture otes o. Mrh 3, 26 6 Model Struture of Liner ime Invrint Systems 6. Model Struture In representing dynmil system, the first step is to find n pproprite

More information

Harvard University Computer Science 121 Midterm October 23, 2012

Harvard University Computer Science 121 Midterm October 23, 2012 Hrvrd University Computer Science 121 Midterm Octoer 23, 2012 This is closed-ook exmintion. You my use ny result from lecture, Sipser, prolem sets, or section, s long s you quote it clerly. The lphet is

More information

Scanner. Specifying patterns. Specifying patterns. Operations on languages. A scanner must recognize the units of syntax Some parts are easy:

Scanner. Specifying patterns. Specifying patterns. Operations on languages. A scanner must recognize the units of syntax Some parts are easy: Scnner Specifying ptterns source code tokens scnner prser IR A scnner must recognize the units of syntx Some prts re esy: errors mps chrcters into tokens the sic unit of syntx x = x + y; ecomes

More information

Finite Automata-cont d

Finite Automata-cont d Automt Theory nd Forml Lnguges Professor Leslie Lnder Lecture # 6 Finite Automt-cont d The Pumping Lemm WEB SITE: http://ingwe.inghmton.edu/ ~lnder/cs573.html Septemer 18, 2000 Exmple 1 Consider L = {ww

More information

The Word Problem in Quandles

The Word Problem in Quandles The Word Prolem in Qundles Benjmin Fish Advisor: Ren Levitt April 5, 2013 1 1 Introdution A word over n lger A is finite sequene of elements of A, prentheses, nd opertions of A defined reursively: Given

More information

Solutions for HW9. Bipartite: put the red vertices in V 1 and the black in V 2. Not bipartite!

Solutions for HW9. Bipartite: put the red vertices in V 1 and the black in V 2. Not bipartite! Solutions for HW9 Exerise 28. () Drw C 6, W 6 K 6, n K 5,3. C 6 : W 6 : K 6 : K 5,3 : () Whih of the following re iprtite? Justify your nswer. Biprtite: put the re verties in V 1 n the lk in V 2. Biprtite:

More information

Lecture 6: Coding theory

Lecture 6: Coding theory Leture 6: Coing theory Biology 429 Crl Bergstrom Ferury 4, 2008 Soures: This leture loosely follows Cover n Thoms Chpter 5 n Yeung Chpter 3. As usul, some of the text n equtions re tken iretly from those

More information

CSE 332. Sorting. Data Abstractions. CSE 332: Data Abstractions. QuickSort Cutoff 1. Where We Are 2. Bounding The MAXIMUM Problem 4

CSE 332. Sorting. Data Abstractions. CSE 332: Data Abstractions. QuickSort Cutoff 1. Where We Are 2. Bounding The MAXIMUM Problem 4 Am Blnk Leture 13 Winter 2016 CSE 332 CSE 332: Dt Astrtions Sorting Dt Astrtions QuikSort Cutoff 1 Where We Are 2 For smll n, the reursion is wste. The onstnts on quik/merge sort re higher thn the ones

More information

Intermediate Math Circles Wednesday, November 14, 2018 Finite Automata II. Nickolas Rollick a b b. a b 4

Intermediate Math Circles Wednesday, November 14, 2018 Finite Automata II. Nickolas Rollick a b b. a b 4 Intermedite Mth Circles Wednesdy, Novemer 14, 2018 Finite Automt II Nickols Rollick nrollick@uwterloo.c Regulr Lnguges Lst time, we were introduced to the ide of DFA (deterministic finite utomton), one

More information

p-adic Egyptian Fractions

p-adic Egyptian Fractions p-adic Egyptin Frctions Contents 1 Introduction 1 2 Trditionl Egyptin Frctions nd Greedy Algorithm 2 3 Set-up 3 4 p-greedy Algorithm 5 5 p-egyptin Trditionl 10 6 Conclusion 1 Introduction An Egyptin frction

More information

Lecture 09: Myhill-Nerode Theorem

Lecture 09: Myhill-Nerode Theorem CS 373: Theory of Computtion Mdhusudn Prthsrthy Lecture 09: Myhill-Nerode Theorem 16 Ferury 2010 In this lecture, we will see tht every lnguge hs unique miniml DFA We will see this fct from two perspectives

More information

Coalgebra, Lecture 15: Equations for Deterministic Automata

Coalgebra, Lecture 15: Equations for Deterministic Automata Colger, Lecture 15: Equtions for Deterministic Automt Julin Slmnc (nd Jurrin Rot) Decemer 19, 2016 In this lecture, we will study the concept of equtions for deterministic utomt. The notes re self contined

More information

CSCI 340: Computational Models. Transition Graphs. Department of Computer Science

CSCI 340: Computational Models. Transition Graphs. Department of Computer Science CSCI 340: Computtionl Models Trnsition Grphs Chpter 6 Deprtment of Computer Science Relxing Restrints on Inputs We cn uild n FA tht ccepts only the word! 5 sttes ecuse n FA cn only process one letter t

More information

Introduction to Olympiad Inequalities

Introduction to Olympiad Inequalities Introdution to Olympid Inequlities Edutionl Studies Progrm HSSP Msshusetts Institute of Tehnology Snj Simonovikj Spring 207 Contents Wrm up nd Am-Gm inequlity 2. Elementry inequlities......................

More information

Nondeterminism and Nodeterministic Automata

Nondeterminism and Nodeterministic Automata Nondeterminism nd Nodeterministic Automt 61 Nondeterminism nd Nondeterministic Automt The computtionl mchine models tht we lerned in the clss re deterministic in the sense tht the next move is uniquely

More information

INTRODUCTION TO AUTOMATA THEORY

INTRODUCTION TO AUTOMATA THEORY Chpter 3 INTRODUCTION TO AUTOMATA THEORY In this hpter we stuy the most si strt moel of omputtion. This moel els with mhines tht hve finite memory pity. Setion 3. els with mhines tht operte eterministilly

More information

CS 491G Combinatorial Optimization Lecture Notes

CS 491G Combinatorial Optimization Lecture Notes CS 491G Comintoril Optimiztion Leture Notes Dvi Owen July 30, August 1 1 Mthings Figure 1: two possile mthings in simple grph. Definition 1 Given grph G = V, E, mthing is olletion of eges M suh tht e i,

More information

Homework Solution - Set 5 Due: Friday 10/03/08

Homework Solution - Set 5 Due: Friday 10/03/08 CE 96 Introduction to the Theory of Computtion ll 2008 Homework olution - et 5 Due: ridy 10/0/08 1. Textook, Pge 86, Exercise 1.21. () 1 2 Add new strt stte nd finl stte. Mke originl finl stte non-finl.

More information

input tape head moves current state

input tape head moves current state CPS 140 - Mthemticl Foundtions of CS Dr. Susn Rodger Section: Finite Automt (Ch. 2) (lecture notes) Things to do in clss tody (Jn. 13, 2004): ffl questions on homework 1 ffl finish chpter 1 ffl Red Chpter

More information

Spacetime and the Quantum World Questions Fall 2010

Spacetime and the Quantum World Questions Fall 2010 Spetime nd the Quntum World Questions Fll 2010 1. Cliker Questions from Clss: (1) In toss of two die, wht is the proility tht the sum of the outomes is 6? () P (x 1 + x 2 = 6) = 1 36 - out 3% () P (x 1

More information

5. (±±) Λ = fw j w is string of even lengthg [ 00 = f11,00g 7. (11 [ 00)± Λ = fw j w egins with either 11 or 00g 8. (0 [ ffl)1 Λ = 01 Λ [ 1 Λ 9.

5. (±±) Λ = fw j w is string of even lengthg [ 00 = f11,00g 7. (11 [ 00)± Λ = fw j w egins with either 11 or 00g 8. (0 [ ffl)1 Λ = 01 Λ [ 1 Λ 9. Regulr Expressions, Pumping Lemm, Right Liner Grmmrs Ling 106 Mrch 25, 2002 1 Regulr Expressions A regulr expression descries or genertes lnguge: it is kind of shorthnd for listing the memers of lnguge.

More information

8 THREE PHASE A.C. CIRCUITS

8 THREE PHASE A.C. CIRCUITS 8 THREE PHSE.. IRUITS The signls in hpter 7 were sinusoidl lternting voltges nd urrents of the so-lled single se type. n emf of suh type n e esily generted y rotting single loop of ondutor (or single winding),

More information