Forml Lnguges nd Automt Exm Fculty of Computers & Informtion Deprtment: Computer Science Grde: Third Course code: CSC 34 Totl Mrk: 8 Dte: 23//2 Time: 3 hours Answer the following questions: ) Consider the lnguge S *, where S = { }. Write out ll the words in S * tht hve seven or fewer letters. Cn ny word in this lnguge contin the sustrings or? Why? ) Does the two following two regulr expressions define the sme lnguge: (+) * (+) * (+) * nd * * (+) *? Investigte your nswer. c) Construct regulr expression defining ech of the following lnguges over the lphet = { }: The lnguge of ll strings of 's nd 's in which either the strings re ll 's or else there is n followed y some 's. Lnguge of ll strings of 's nd 's tht t some point contin doule letter. All words tht contin t lest one of the strings s, s 2, s 3 or s 4. 2 ) Let = {,}, drw deterministic finite utomt (DFA) tht recognize, exctly: Lnguge ( (+) * (+)(+) * ) All words with s the third letter nd reject ll other words. All words tht hve different first nd lst letters. ) Drw the corresponding NFA to the following DFA + + (See the next pge)
c) If L is the lnguge recognized y the DFA in the figure, Drw DFA to recognize L', where L' is the complement of L. 3 ) Stte pumping lemm. ) Use pumping lemm to prove tht L = { n n, n } is nonregulr. c) Define the lnguge EQUAL to hve only the words with the sme totl numer of 's nd 's. Does EQUAL nonregulr lnguge? Prove your nswer. 4) ) Define wht we men y decidle prolem. ) Is there n effective procedure to determine the finiteness of lnguge of finite utomte? Stte it, if ny. c) Write the context free grmmr tht genertes L = { n n, n } 5 ) Define PALINDROMEX s the lnguge of ll words of the form sxreverse(s). Construct deterministic pushdown utomt tht ccept this lnguge. ) Define ODDPALINDROME to e the lnguge of ll strings of 's nd 's tht re plindromes nd hve n odd numer of letters. Construct nondeterministic pushdown utomt tht ccept this lnguge.
Model Answer Forml Lnguges nd Automt Exm Fculty of Computers & Informtion Deprtment: Computer Science Course code: CSC 34 Totl Mrk: 8 Dte: 23//2 Time: 3 hours ) Consider the lnguge S *, where S = { }. Write out ll the words in S * tht hve seven or fewer letters. Cn ny word in this lnguge contin the sustrings or? Why? The words of length less thn 7 re: : contins no fctors, : contins one fctor,,, : contins 2 fctors,,,,,,,: contins 3 fctors All words contins 4 or more fctors hve length 8. The lnguge words cn't contin neither nor. The reson is the locks tht uild the words re only 2. These 2 locks strt with nd end with or vice vers. So, the result of comintion yields only,,, or. ) Does the two following two regulr expressions define the sme lnguge: (+) * (+) * (+) * nd * * (+) *? Investigte your nswer. Yes. Both of them denote ll the words with t lest two 's. c) Construct regulr expression defining ech of the following lnguges over the lphet = { }: The lnguge of ll strings of 's nd 's in which either the strings re ll 's or else there is n followed y some 's.
The lnguge of ll strings of 's nd 's tht t some point contin doule letter. All words tht contin t lest one of the strings s, s 2, s 3 or s 4. * + * or equivlently ( +) * (+) * (+)(+) * (+) * (s +s 2 +s 3 +s 4 )(+) *
2 ) Let = {, }, drw deterministic finite utomt tht recognize exctly the following: Lnguge ( (+) * (+)(+) * ) +, All words with s the third letter nd reject ll other words.,,, +, All words tht hve different first nd lst letters. + +
) Drw the corresponding NFA to the following DFA + +, + + OR, + c) If L is the lnguge recognized y the DFA in the figure, Drw DFA to recognize L', where L' is the complement of L. ±
3 ) Stte pumping lemm. Let L e ny regulr lnguge tht hs infinitely mny words. Then there exist some three strings x, y, z (where y is not the null string) such tht ll the strings of the form xy n z L, n =, 2, 3, ) Use pumping lemm to prove tht L = { n n, n } is nonregulr. Assume the contrry, i.e. L is regulr Hence, y pumping lemm, x, y, z such tht xyz, xyyz L We differentite mong 3 cses of y: y constitute of only 's: We hve xyz contins the sme numer of 's nd 's So, xyyz contins numer of 's igger thn numer of 's So, xyyz L But xyyz L, which is contrdiction. y constitute of only 's: Sme rgument s ove. y constitutes of equl numer of 's nd 's: To e xyz L, y must equls to p p, for some p So yy = p p p p Now xyyz = x p p p p z L, which is contrdiction. The contrdictions show tht L is nonregulr.
c) Define the lnguge EQUAL to hve only the words with the sme totl numer of 's nd 's. Does EQUAL nonregulr lnguge? Prove your nswer. EQUAL is nonregulr ecuse { n n } = * * EQUAL We know tht * * is regulr lnguge nd the set of regulr lnguge is closed under intersection. Hence EQUAL cn't e regulr.
4) ) define wht we men y decidle prolem. An effective solution to prolem tht hs yes or no nswer is clled decision procedure. A prolem tht hs decision procedure is clled decidle. ) Is there n effective procedure to determine the finiteness of lnguge of finite utomte? Stte it, if ny. Yes. ssume tht the finite utomton hs N sttes Test ll words of length p on the mchine, where N p < 2 N If t lest one of these words ccepted then the lnguge is infinite Else if ll these words consumed t nonfinl sttes then the lnguge is finite. c) Write the context free grmmr tht genertes L = { n n, n } G = ({S}, {,}, {S S}, S)
5 ) Define PALINDROMEX s the lnguge of ll words of the form sxreverse(s). Construct deterministic pushdown utomt tht ccept this lnguge. Any deterministic pushdown utomt equivlent to the following is sufficient: OR
) Define ODDPALINDROME to e the lnguge of ll strings of 's nd 's tht re plindromes nd hve n odd numer of letters. Construct nondeterministic pushdown utomt tht ccept this lnguge. Any nondeterministic pushdown utomt equivlent to the following is sufficient: