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 nd sign their desk crd ut must NOT write nything else until the strt of the exmintion period is nnounced. nswer LL THREE questions No clcultors re permitted in this exmintion. Dictionries re not llowed with one exception. Those whose first lnguge is not English my use stndrd trnsltion dictionry to trnslte etween tht lnguge nd English provided tht neither lnguge is the suject of this exmintion. Suject-specific trnsltion directories re not permitted. No electronic devices cple of storing nd retrieving text, including electronic dictionries, my e used. Note: NSWERS Turn Over
2 Question 1 The following questions re multiple choice. There is t lest one correct nswer, ut there my e severl. To get ll the mrks you hve to list ll correct nswers nd none of the incorrect ones. 1 mistke results in 3 mrks, 2 mistkes result in 1 mrk, 3 or more mistkes result in zero mrks. nswer: Note tht the nswer tht should e provided is just list of the correct lterntive(s). ny further explntions elow re just for clrifiction. () Consider the following finite utomton over Σ = {,}: 0 1 2 3 4 Which of the following sttements out re correct?, (i) The utomton is Deterministic Finite utomton (DF). (ii) ǫ L() (iii) L() (iv) ll words ccepted y contin one more thn or one more thn. (v) The utomton ccepts ll words over Σ tht contin one more thn or one more thn. (5) nswer: Correct: i, iii, iv Incorrect: ii The initil stte is not ccepting. v E.g. / L().
3 () Consider the following set W of words: W = {ǫ,, c, } Which of the following regulr expressions denote lnguge tht contins ll words in W? (ut not necessrily only the words in W: the lnguge denoted y the regulr expression is llowed to contin more words.) (i) (ǫ++c)(ǫ+) (ii) (ǫ++c)( +) (iii) (ǫ++c) (iv) (+c) (v) () +c nswer: Correct: i, iii, iv Incorrect: (5) ii ǫ / L( +) nd therefore ǫ / L((ǫ++c)( +)). v c / L(() ) nd c / L(c ), nd therefore c / L(() +c ). (c) Consider the following Context-Free Grmmr (CFG) G: S XY X X ǫ Y Yc ǫ where S, X, Y re nonterminl symols, S is the strt symol, nd,, c re terminl symols. Which of the following sttements out the lnguge L(G) generted y G re correct? (i) ǫ L(G) (ii) c L(G) (iii) c L(G) (iv) ccc L(G) (v) L(G) = { n 2n c n n N} (where N = {0,1,2,...}) nswer: Correct: i, ii, iv; Incorrect: iii, v ({ n 2n c n n N} L(G)) (5) Turn Over
4 (d) Which of the following properties of prolem P imply tht P is undecidle? (i) P is reducile to the Hlting Prolem. (ii) The Hlting Prolem is reducile to P. (iii) P is recursively enumerle ut not recursive. (iv) The complement of P is recursively enumerle. (v) There is no Turing Mchine tht solves P. nswer: Correct: ii, iii, v Incorrect: i, iv When prolem Q is reducile to nother prolem P, this mens tht ny instnce of Q cn e trnsformed into n instnce of P with the sme solution. If we hd n lgorithm to solve P, we could then lso solve Q. Therefore, if we lredy know tht P is undecidle, this reduction shows tht there cnnot e n lgorithm to solve P. We cn conclude tht P is lso undecidle. This is why (iii) is correct. However if we know tht P is undecidle, the fct tht instnces of Q re reducile to instnces of P is not informtive: there my still e n lgorithm to solve Q, independently of the fct tht we don t hve one for P. Tht s why (ii) does not imply tht P is undecidle. nswer (iv) is incorrect ecuse it merely sys tht there is n lgorithm tht enumertes the instnces of P tht hve negtive solution. This still leves open the possiility tht there is nother lgorithm tht enumertes the instnces of P with positive solution. In tht cse, y comining the two lgorithms, we could decide P. (e) Which of the following sttements out the λ-clculus re true? (i) Every λ-term hs norml form. (ii) Every λ-term hs fixed point. (iii) Every computle function cn e represented y λ-term. (iv) The normliztion property of λ-terms is decidle prolem. (v) The set of functions representle y λ-terms is the sme s those computle y Turing Mchines. (5) nswer: Correct: ii,iii,v Incorrect: i,iv (5)
5 nswer (i) is incorrect ecuse there re λ-terms whose reduction sequences go on forever (independently of wht reduction strtegy we use). One exmple is (λx.xx)(λx.xx). nswer (iv) is incorrect ecuse normliztion of λ-terms is equivlent to the Hlting Prolem (it is in fct the formultion of the Hlting Prolem in the λ-clculous). Therefore it is undecidle. Turn Over
6 Question 2 () Given the following Nondeterministic Finite utomton (NF) N over the lphet Σ = {,, c}, construct Deterministic Finite utomton (DF) D(N) equivlent to N y pplying the suset construction:,,c,,c,,c 0 1 2 3 Show your clcultions in stte-trnsition tle. Consider only the rechle prt of D(N). Then drw the trnsition digrm for the resulting DF D(N). Indicte the initil stte nd the finl sttes oth in the trnsition tle nd the finl trnsition digrm. (12) nswer: δ D() c {0} = {0,1} = {0} = {0} = {0,1} = {0,1} = {0,1,2} = C {0,1} = {0,1,2} = C {0,1,3} = D {0,1,2,3} = E {0,1,3} = D {0,1,3} = D {0,1} = {0,1,2} = C {0,1} = {0,1,2,3} = E {0,1,3} = D {0,1,2,3} = E {0,1,3} = D The sttes hve een nmed (,,..., E) to fcilitte drwing the trnsition digrm. We cn now drw the trnsition digrm for D(N):,c,c,c,c C D E,c
7 () Consider the following Context-Free Grmmr (CFG): S Sp m c lsr S,, nd re nonterminls,,, c, l, m, p, nd r re terminls, nd S is the strt symol. Drw the derivtion tree ccording to this grmmr for the word mlppcrm. (5) nswer: Derivtion tree for mlppcrm: S m m l S r S p S p c Turn Over
8 (c) Construct n unmiguous Context-Free Grmmr (CFG) for regulr expressions over the lphet Σ = {,,c} (with the syntx defined in the lecture notes). To ensure your grmmr is unmiguous, it should reflect the precedence nd ssocitivity for the regulr expression constructs s specified y the following tle: Opertors Precedence ssocitivity highest n/ conctention medium left + lowest left For exmple, ((ǫ+)) + is vlid regulr expression, wheres oth (ecuse the prentheses re not lnced) nd ( + (ecuse + is inry opertor) re not. (8) nswer: The following is one possile grmmr. It hs een strtified to cpture the desired precedence levels, nd left recursion is used to imprt left ssocitivity on the relevnt constructs ccording to the specifiction: E E + E 1 E 1 E 1 E 1 E 2 E 2 E 2 E 2 E 3 E 3 (E) E P E P c ǫ Here, E, E 1, E 2, nd E P re nonterminls with E eing the strt symol, nd +,, (, ),,, c, ǫ, re terminls. (Note in prticulr tht E P ǫ is not n epsilon production in this cse!)
9 Question 3 () Write the λ-terms tht represent the following vlues: The oolen vlues true nd flse; The exclusive or function xor, such tht xortruetrue flse, xortrueflse true, xorflsetrue true, xorflseflse flse; For every couple of terms nd, term, representing the pir, such tht The Church Numerl 3., true,, flse ; nswer: true = λx.λy.x flse = λx.λy.y xor = λu.λv.u(vflsetrue)v where (vflsetrue) is the encoding of (notv), = λx.x 3 = λf.λx.f (f (f x)) (8) () Consider the following λ-terms: xor-pir is function on pirs of oolens, xor-fun function from Church Numerls to pirs of oolens: xor-pir = λp. pflse,xor(ptrue)(pflse) xor-fun = λn.n xor-pir true, true Wht vlues do the following terms reduce to? xor-pir true,true? xor-pir true,flse? xor-pir flse,true? xor-pir flse,flse? Show the steps of reduction in the computtion of (xor-fun3). [You cn use the previous reductions nd those from prt () s single steps.] Give n informl definition of wht xor-fun does: for which numers n does (xor-funn) true,true? (10) nswer: xor-pir true,true true,flse xor-pir true,flse flse,true xor-pir flse,true true,true xor-pir flse,flse flse,flse Turn Over
10 xor-fun3 3xor-pir true,true xor-pir(xor-pir(xor-pir true,true )) xor-pir(xor-pir true,flse ) xor-pir flse,true true,true (xor-funn) reduces to true,true if n is divisile y 3, to true,flse if the reminder of division of n y 3 is 1, nd to flse,true if the reminder is 2. (c) In the context of complexity theory, explin wht it mens for decision prolem to elong to the clsses: P, NP, NP-complete. (7) nswer: prolem elongs to the clss P if there is Turing Mchine tht lwys termintes in polynomil time nd decides ech instnce of the prolem. It elongs to NP if either of the following equivlent conditions hold: (i) There is non-deterministic Turing Mchine tht runs in polynomil time nd decides every instnce of the prolem. (ii) There is deterministic Turing Mchine tht runs in polynomil time nd checks solutions to instnces of the prolem: when we give it s input n instnce of the prolem nd cndidte solution, it termintes in n ccepting sttes if nd only if the solution is correct. prolem is NP-complete if it elongs to NP nd every NP prolem cn e reduced in polynomil time to it. End