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 desk rd ut must OT write nything else until the strt of the exmintion period is nnouned. Answer ALL THR questions o lultors re permitted in this exmintion. Ditionries re not llowed with one exeption. Those whose first lnguge is not nglish my use stndrd trnsltion ditionry to trnslte etween tht lnguge nd nglish provided tht neither lnguge is the sujet of this exmintion. Sujet-speifi trnsltion diretories re not permitted. o eletroni devies ple of storing nd retrieving text, inluding eletroni ditionries, my e used. ote: ASWRS Turn Over
2 Question 1 The following questions re multiple hoie. There is t lest one orret nswer, ut there my e severl. To get ll the mrks you hve to list ll orret nswers nd none of the inorret ones. 1 mistke results in 3 mrks, 2 mistkes result in 1 mrk, 3 or more mistkes result in zero mrks. Answer: ote tht the nswer tht should e provided is just list of the orret lterntive(s). The dditionl explntions elow re just for your informtion. () Whih of the following sttements re orret? (i) The empty word ǫ is the only word in the empty lnguge. (ii) ǫ Σ, where Σ = {0,1} (iii) ǫ / (iv) The empty word ǫ does not elong to ny non-empty lnguge. (v) ǫ { i j i,j,i+j 42} (where = {0,1,2,...}) Answer: Corret: ii, v Inorret: i The empty lnguge ; i.e., the empty set, does not ontin ny words, not even the empty one. iii By definition, ǫ L for ny lnguge L, inluding the empty lnguge. iv {ǫ} is n exmple of non-empty lnguge tht does ontin the empty word ǫ. (5)
3 () Consider the following finite utomton A over Σ = {,,}:,,,,,,,, 0 1 2 3 4 Whih of the following sttements out A re orret? (i) The utomton A is Deterministi Finite Automton (DFA). (ii) ǫ L(A) (iii) L(A) (iv) L(A) (v) The lnguge epted y the utomton A is ll words over Σ tht ontins the letters,,, in tht order. (5) Answer: Corret: iv, v Inorret: i The utomton is n FA sine more thn one trnsition sometimes re possile for some sttes nd lphet symols. ii ǫ / L(A) sine no strt stte is epting. iii / L(A) sine it is not possile to reh ny epting stte on this word. () Consider the following regulr expression: () () Whih of the following regulr expressions denote the sme lnguge s the ove regulr expression? (i) (++) (ii) (+) (++) (iii) (ǫ+) ( +) (iv) +() +() (v) ( ) ( ) (5) Answer: Corret: iii Inorret: i, ii, iv, v Turn Over
4 (d) Consider the following Context-Free Grmmr (CFG) G: S XX Y X X Y Y Y ǫ where S, X, Y re nonterminl symols, S is the strt symol, nd,, re terminl symols. Whih of the following sttements out the lnguge L(G) generted y G re orret? (i) ǫ L(G) (ii) L(G) (iii) L(G) (iv) L(G) = L 1 L 1 L 2 where L 1 = { i j i i,j, i > 0} nd L 2 = { i i } (where = {0,1,2,...}) (v) The following CFG G is equivlent to G ove; i.e., L(G ) = L(G): S XX X X Y Y Y ǫ Answer: Corret: i, ii, iv Inorret: (5) iii Sine the word ontins s nd s, the derivtion must egin S XX. The only possiility to derive the word from XX is to split it into two prts fter the lst, nd derive the first prt from the first X nd the lst prt from the seond X. But while n e derived from the first X, nnot e derived from the seond. v ot equivlent euse ǫ n now e derived from X, mening tht word like L(G ). However, / L(G).
5 (e) Whih of the following sttements out the Hlting Prolem re orret? (i) The Hlting Prolem is undeidle. (ii) The Hlting Prolem is semi-deidle. (iii) The Hlting Prolem is the prolem tht Turing Mhines n get stuk. (iv) There is no Turing Mhine tht deides the Hlting Prolem. (v) A Turing mhine tht never hlts hs got the Hlting Prolem. Answer: Corret: i, ii, iv (The semi-deidle lnguges re proper suset of the undeidle ones.) Inorret: iii, v (5) Turn Over
6 Question 2 () Given the following ondeterministi Finite Automton (FA) over the lphet Σ = {,, }, onstrut Deterministi Finite Automton (DFA) D() tht epts the sme lnguge s y pplying the suset onstrution:,, 0 1 2 3 4 To sve work, onsider only the rehle prt of D(). Clerly show your lultions in stte-trnsition tle. Then drw the trnsition digrm for the resulting DFA D(). Do not forget to indite the initil stte nd the finl sttes oth in the trnsition tle nd the finl trnsition digrm. (12) Answer: δ D() {0} = A {0,1} = B {0,2} = C {0} = A {0,1} = B {0,1} = B {0,2,3} = D {0} = A {0,2} = C {0,1,3} = {0,2} = C {0} = A {0,2,3} = D {0,1,3} = {0,2} = C {0,4} = F {0,1,3} = {0,1} = B {0,2,3} = D {0,4} = F {0,4} = F {0,1} = B {0,2} = C {0,3} = G {0,3} = G {0,1} = B {0,2} = C {0,4} = F We n now drw the trnsition digrm for D(): A B C D F G
7 () Wht lnguge does the following Turing Mhine (TM) M ept? where M = (Q, Σ, Γ, δ,q 0, B, F) Q = {q 0,q 1,q 2,q 3,q 4 } Σ = {,,} Γ = {,,,x,b} F = {q 4 } δ(q 0,) = {(q 1,x,R)} δ(q 1,) = {(q 1,x,R)} δ(q 1,) = {(q 2,x,R)} δ(q 1,) = {(q 3,x,R)} δ(q 2,) = {(q 2,x,R)} δ(q 2,) = {(q 3,x,R)} δ(q 3,) = {(q 3,x,R)} δ(q 3,B) = {(q 4,B,R)} δ(q, x) = stop elsewhere Give preise, mthemtil hrteristion of the epted lnguge long with rief explntion of why the mhine epts this lnguge. (8) Answer: L(M) = { i j k i,j,k,i 1,k 1}. Alterntively, we n oserve tht the lnguge tully is regulr nd given y e.g. the regulr expression. The mhine only ever move right nd either stys in stte or moves to higher numered stte. The mhine strts in stte q 0, where only is epted, using the mhine to move to stte q 1. In q 1 the mhine n loop on, epting further ritrry numer of s, or it n ept or moving to q 2 or q 3, respetively. Both q 2 nd q 3 re looping sttes, llowing n ritrry numer of s nd s respetively to e epted. A single is required to move form q 2 to q 3, ut note tht q 3 lso n e rehed diretly from q 1 on single, mening tht the numer of s in n epted word n e 0. The words epted re thus those onsisting of 1 or more s, followed y 0 or more s, followed y 1 or more s. Turn Over
8 () In the ontext of Turing Mhines, explin wht it mens for lnguge to e: reursive, reursively-enumerle, deidle, undeidle. (5) Answer: A reursive lnguge is lnguge tht is epted y Turing Mhine tht lwys hlts. This is the sme s sying tht the lnguge is deidle (or tht the prolem represented y the lnguge is deidle). A reursively enumerle lnguge is lnguge tht is epted y Turing Mhine (ut not y ny Turing mhine tht neessrily hlts). A lnguge tht is not reursive is undeidle. The undeidle lnguges thus inludes the reursively enumerle (or semi-deidle) lnguges nd those lnguges whih re not even reursively-enumerle.
9 Question 3 () The following is ontext-free grmmr (CFG) for simple rithmeti expressions. For simpliity, we only onsider the numers 0, 1, nd 2: + () 0 1 2 nd re nonterminls, is the strt symol, +,,, (, ), 0, 1, 2 re terminls. Show tht this grmmr is miguous. (5) Answer: To demonstrte miguity, demonstrte tht there is t lest one derivle word for whih there re two different leftmost or rightmost derivtions, or two different prse tress. For exmple, here re two different leftmost derivtions of the word 0+1+2: + + + + + 0+ + 0+ + 0+1+ 0+1+ 0+1+2 nd + + 0+ 0+ + 0+ + 0+1+ 0+1+ 0+1+2 Alterntively, here re the two prse trees orresponding to the derivtions ove: + + + nd + 2 0 0 1 1 2 Turn Over
10 () Construt n equivlent ut unmiguous version of the ontext-free grmmr for rithmeti expressions given in () ove y mking it reflet the following onventions regrding opertor preedene nd ssoitivity: Opertors Preedene Assoitivity highest right medium left + lowest left It should further e possile to use prentheses for grouping in the usul wy. (8) Answer: Strtify the grmmr so tht produtions for opertors refer to either produtions t the sme level or produtions t the next level up, nd use left-reursive produtions for left-ssoitive opertors nd right-reursive produtions for right-ssoitive opertors. + 1 1 1 1 2 2 2 3 2 3 3 () 0 1 2
11 () The following Context-free grmmr(cfg) is immeditely left-reursive: S S X X XX YXd Y Y Ye Yf g S, X, nd Y re nonterminls,,,, d, e, f, nd g re terminls, nd S is the strt symol. Trnsform this grmmr into n equivlent right-reursive CFG. Stte the generl trnsformtion rule you re using nd show the min trnsformtion steps. (12) Answer: First identify the immeditely left-reursive non-terminls. Then group the produtions for eh suh non-terminl into two groups: one where eh RHS strts with the non-terminl in question, nd one where they don t: A Aα 1... Aα m A β 1... β n Then reple those produtions with new produtions for A nd produtions for A, where A is new nme, s follows: A β 1 A... β n A A α 1 A... α m A ǫ There re two immeditely left-reursive non-terminls in the given grmmr: X nd Y. The grmmr is essentilly lredy grouped s required. Applying the ove trnsformtion rule to oth the X nd Y produtions yields: S S X X YXdX YX X XX ǫ Y gy Y ey fy ǫ nd