Tlen en Automten Test 1, Mon 7 th Dec, 2015 15h45 17h30 This test consists of four exercises over 5 pges. Explin your pproch, nd write your nswer to ech exercise on seprte pge. You cn score mximum of 100 points, nd ech question indictes how mny points it is worth. The test is closed ook. You re NOT llowed to use clcultor, computer or moile phone. You my nswer in Dutch or in English. Plese write clerly, nd do not forget to put on ech pge: your nme nd your student numer. Nottion Throughout the test, we denote for ny lphet A, w A nd A y w the numer of s in w, s it ws introduced in the lecture. Moreover, recll tht v is suword of w if w = xvy for some words x, y. 1 Induction Let A nd B e finite lphets nd f : A B mp from A to words over B. ) Define y induction mp f : A B tht replces in word w A ll letters y f(). (5pt) We define the required mp y f(λ) = λ f(w) = f()f(w) ) Let A = {, } nd f : A A e given y f() = nd f() =. i) Give word w A such tht f(w) =. (5pt) w = does the jo. ii) Show y induction tht f(w) = w + 2 w. We show y induction in w tht f(w) = w + 2 w. IB: w = λ. Here, we get tht f(λ) = λ = 0 = λ + 2 λ IH: For w A, f(w) = w + 2 w. IS: Let x A. We need to distinguish two cses. 1. If x =, then we hve s required. f(w) = f()f(w) = f(w) = f(w) + 1 IH = w + 2 w + 1 = w + 2 w
2. If, on the other hnd, x =, then f(w) = f()f(w) = f(w) = f(w) + 2 IH = w + 2 w + 2 = w + 2 w. So in oth cses f(xw) = xw + 2 xw. This induction proves the desired eqution. 2 Regulr Lnguges [Write your nswers on seprte pge] ) Let A = {, } nd L 1 = {w A w is even} L 2 = L ( ( + ) ( + ) ) L 3 = {w A w does not contin the suword }. Explin for ech i = 1, 2, 3 whether nd why L i = L i. L 1 = L 1, since 1. λ is even nd for ll w, v L 1 we hve wv = w + v is even; thus L 1 L 1, see 5) on exercise sheet 1. 2. L 1 L 1 holds trivilly. L 2 L 2, since λ L 2 ut not in L 2. L 3 L 3, since L 3 nd L 3, hence L 3. ) Let A = {, } nd L = {w A occurs twice s suword in w}. Give regulr expression e, such tht L (e) = L. Explin your nswer. We put e = ( + ) (( + ) +)( + ). Tht L (e) = L cn e seen s follows. To show the inclusion L L (e), let w L so tht there re x 1, y 1, x 2, y 2 A with w = x i y i nd x 1 x 2 nd y 1 y 2. WLOG, we ssume tht x 1 = x 2 z for some non-empty word z. Then either 1. z = u, u A. Then w = x 2 u y 1, hence w L (e). 2. z =. Then w = x 2 y 1, hence w L (e). The other direction cn e seen s follows. Let w L (e), then either w = xyz or w = xy. Thus we cn split in oth cses w twice into uv with u = x, v = yz nd u = xy, v = z in the first cse, nd u = x, v = y nd u = x, v = y in the second cse. In other words, w L. This shows tht L = L (e).
3 Deterministic Finite Automt [Write your nswers on seprte pge] ) Let A = {,, c} nd let L = {w A occurs n odd numer of times s suword in w}. i) Give DFA M with L(M) = L. Explin your nswer. Define M to e, c, c q 0 q 1 q 2 c c q 3 Explntion: We hve the following invrints for the sttes. In q 0 we hve red n even numer of. In q 1 we re witing fter n, which would give us n odd numer of red. In q 2 we hve red n odd numer of In q 3 we re witing fter n, which would give us n even numer of red. The trnsitions then clerly preserve these invrints, nd since only q 2 nd q 3 re ccepting, the utomton ccepts exctly L. ii) Show tht c is ccepted, nd tht is not ccepted. (5pt) We hve q 0, c q 0, q 1, q 2, q 3, λ, thus c L(M). We hve q 0, q 1, q 2, q 2, q 3, q 0, λ, thus is not ccepted. ) Let A = {, } nd the DFA M over A e given y q 0 q 1 q 2
Use the procedure from the lecture to construct regulr expression e with L (e) = L(M). First, we need to trnsform M to only hve one finl stte: q 0 q 1 q 2 1 1 f Then we eliminte q 1 : + q 0 q 2 1 1 f Next, we eliminte q 2 : + + q 0 1 + f Thus e is given y ( + + ) (1 + ). 4 Non-Deterministic Finite Automt [Write your nswers on seprte pge] ) Let A = {0, 1, 2} nd let L e the lnguge of words in which the digits occur only in incresing order, i.e., L = {x 1 x n n N, i. x i A nd i j. x i x j }. i) Show tht L is regulr y constructing n NFA-λ tht ccepts L.
0 1 2 q λ 0 q λ 1 q 2 ii) Show tht your utomton ccepts 002 nd rejects 21. (5pt) We hve hence 002 is ccepted. We hve hence 21 is not ccepted. q 0, 002 q 0, 02 q 0, 2 q 1, 2 q 2, 2 q 2, λ, δ (q 0, 21) = q λ closure(q 0) p δ(q,2) = δ (q 2, 1) =, ) Let A = {,, c} nd the NFA-λ M over A e given y, c δ (p, 1) q 0 q 1 q 2 q 3 λ Use the procedure from the lecture to construct DFA D with L(D) = L(M). Indicte clerly from which suset of sttes of M stte in D origintes. λ {q 0, q 3 } {q 1 }, c, c {q 1, q 2 } {q 1, q 2, q 3 }, c, c c) Let e e the regulr expression + ( + 1). Use the procedure from the lecture to construct n NFA-λ M with L(M) = L (e).
Tlen en Automten Test 2, Thu 21 st Jn, 2016 This test consists of four exercises over 4 pges. Explin your pproch. You cn score mximum of 100 points, nd ech question indictes how mny points it is worth. The test is closed ook. You re NOT llowed to use clcultor, computer or moile phone. You my nswer in Dutch or in English. Plese write clerly, nd do not forget to put on ech pge: your nme nd your student numer. Nottion Throughout the test, we denote for ny lphet A nd A y w the numer of s in the word w A, s it ws introduced in the lecture. Write the nswer to ech exercise on seprte sheet! 1 Non-Regulr Lnguges Write your nswers on seprte sheet Let A = {, }. ) We define the lnguge L to e L = {w n w A, w = n}. Show tht L is not regulr. (5pt) Assume tht L is regulr nd let p > 0 e the pumping length which we get from the pumping lemm (PL). Tke w = p p L, which cn e divided y the PL into w = xyz with y 1, xy p such tht xy i z L for ll i N. By the ove constrints we immeditely get tht y = k with k > 0. Tke i = 0. So xy 0 z = p k p L. But p k p, so xy 0 z L. Contrdiction, hence L is not regulr. Students my use the following rgument L L ( ) = { n n n N}, which is not regulr. Thus L cnnot e regulr. However: L L ( ) = { m n m n}, so this rgument is incorrect. ) Show tht the lnguge L = {w A w = w } is not regulr, using the Pumping Lemm. Assume tht L is regulr nd let p > 0 e the pumping length which we get from the pumping lemm (PL). Tke w = p p L, which cn e divided y the PL into w = xyz with y 1, xy p such tht xy i z L for ll i N. By the ove constrints we immeditely get tht y = k with k > 0. Tke i = 0 (or i = 2 lso works). So xy 0 z = p k p L. But p k p, so xy 0 z L. Contrdiction, hence L is not regulr.
2 Context Free Grmmrs Write your nswers on seprte sheet Fix A = {, } for this exercise. ) Let L e the lnguge over A given y L = { n k m k = n + m}. i) Construct CFG G such tht L(G) = L. G is given y the productions S LR L L λ R R λ hving non-terminls {S, L, R} nd strt symol S. ii) Give derivtion for the word L. (5pt) S LR LR LR R R iii) Show tht the word is not generted. (5pt) The only possile wy to get the first is y S LR LR R ut then from R we cn only get to λ or to..., so we cnnot generte. Alterntive: Full Cse Explortion Strting from S, we hve the following possile derivtions. S LR {LR, LR, R, L} For these, in turn, we hve LR {R, LR, L, LR} Thus in ech cse either too little s or to mny s re produced. LR {R, LR, L, LR} Similr R cnnot produce in front of L cnnot produce in front of Thus in neither of these cses we cn derive, so it is note in the lnguge generted y the grmr.
) Let G e the following CFG over A. S US λ U i) Give precise description of L(G) using set nottion. (5pt) L(G) = {w A w even} = {w 1 w n n N, w i {,,, }} = L ( ( + + + ) ) ii) Is L(G) regulr lnguge? Explin your nswer y either giving reson why it is not or y giving regulr grmmr for L(G). L(G) is regulr. We cn sustitute U in the first production of S to otin S S S S S λ. This cn e refined into the following regulr grmmr. S A B B A λ A S B S More compct solution S T T λ T S S 3 Push Down Automt I Write your nswers on seprte sheet Let M e the PDA with Q = {q 0, q 1, q 2 } Σ = {,, c} Γ = {B, C} F = {q 0 } δ(q 0,, λ) = { q 1, B } δ(q 0,, C) = { q 1, λ } δ(q 0, c, λ) = { q 2, C } δ(q 0, c, B) = { q 2, λ } δ(q 1,, λ) = { q 0, λ } δ(q 2,, λ) = { q 0, λ } ) Drw stte digrm for M. (5pt)
M cn e drwn s, λ/b, C/λ strt q 0 q 1, λ/λ, λ/λ c, λ/c c, B/λ q 2 ) Check which of the following words is in L(M) nd explin your nswer: c nd c. (5pt) There is no trnsition from q 0 tht reds n, so c / L(M). q 0, c, λ q 1, c, B q 0, c, λ q 2,, C q 0, λ, λ. We end in n ccepting stte with n empty stck, so c L(M). c) Is L ( (c) () ) L(M)? Explin your nswer. (5pt) No, c L((c) () ), ut c L(M). To see the ltter, note tht when reding c, either B must e popped of the stck, or C is pushed on the stck. The first is not possile with n empty stck, nd fter the second the stck is not empty. Alterntively: if w L(M) then the numer of s nd s in w is equl, following the sme rgument s ove. This does not hve to e the cse for every w L((c) () ). d) Give precise description of L(M) using set nottion. (5pt) L(M) = {w L((c + c) ) w = w }. Tht is, the words with n equl numer of s nd s, where every nd every is followed y c, nd every c is preceded y n or. 4 Push Down Automt II Write your nswers on seprte sheet
) i) Let A = {, } nd let L e the lnguge L = {w A w = 2 w + 1}. Show tht L is context free y giving PDA tht ccepts it., A/λ, B/λ, λ/aa, λ/λ λ, λ/ q 0 q 1 q 2, λ/b, λ/a ii) Show tht nd re ccepted, y giving the ccepting computtions. (5pt) q 0,, λ q 1,, λ q 2,, λ q 1,, A q 1, λ, λ q 0,, λ q 0,, AA q 1,, AA q 1,, A q 1, λ, λ iii) Show tht is not ccepted y your PDA. (5pt) We hve the following possile computtions (q 0,, λ) (q 1,, ) {(q 1,, λ), (q 2,, )} {(q 2,, λ), (q 1,, )} {(q 1, λ, ), (q 1, λ, )}, neither of which ends with n empty stck. Thus is not ccepted. ) Let G e the grmmr on the lphet {, } given s follows. S λ X Y X Y Y X Construct PDA tht ccepts L(G), using the procedure given in the lecture.
First we trnsform the grmmr into the form necessry construct PDA. The resulting PDA is then. S λ X Y X Y B B Y XA A A B, λ/x, λ/y λ, λ/λ, X/Y B, X/B, A/λ, B/λ, Y/XA, Y/A