CSE 260-002: Exm 3-ANSWERS, Spring 20 ime: 50 minutes Nme: his exm hs 4 pges nd 0 prolems totling 00 points. his exm is closed ook nd closed notes.. Wrshll s lgorithm for trnsitive closure computtion is sed on dynmic progrmming which uses the following recursive formul: i,j,k n w [k] ij = w [k ] ij (w [k ] ik w [k ] kj ) Bsed on the ove recursive formul, Wrshll s lgorithm is written s follows: W = M R ; M R is the 0- mtrix for the reltion R. or k= to n do the following: or i= to n do the following: or j= to n do the following: w ij = w ij (w ik w kj ) Let W k e the zero-one mtrix produced in the kth. itertion. () (5 points) Wht do the logicl opertions on the right hnd side of the following sttement ccomplish in computing the trnsitive closure? Explin your nswer. w ij = w ij (w ik w kj ) It computes the pth ij y connecting pths ik nd kj going throug k. () (3 points) Give W 0 = M R for the reltion {(, ), (, ), (, c)} W 0 = M R = c 0 0 0 (c) (6 points) Bsed on the ordering of the nodes s,, c give the mtrices W through W 3 s produced y the Wrshll s lgorithm. W = c 0 W 2 = c
W 3 = c (d) (3 points) Give the run time complexity of the Wrshll s lgorithm. O(n 3 ) 2. ollowing reltion is defined on the set A = {5, 20, 29, 27} R = {(, )ɛa A (mod 3)} () (5 points) Give the reltion R s set. {(5, 5), (20, 20), (29, 29), (27, 27), (5, 27), (27, 5), (20, 29), (29, 20)} R: 5 27 20 29 () (3 points) Why R is n equivlence reltion? rom the ove reltion it is seen tht R is reflexive, symmetric nd trnsitive. (c) (5) Give the equivlence clsses for the reltion R. [5] = {5, 27} [20] = {20, 29} 3. ollowing is reltionl tle contining person nmes nd their telephone numers. A person cn hve more thn one telephone numer nd telephone numer my elong to more thn one person. P nme tel ------------------ n t n2 t n2 t2 n3 t3 () (3 points) Write the ove reltionl tle in set nottion. {(n, t), (n2, t), (n2, t2), (n3, t3)} () Provide mening of ech of the following queries in simple English. Give the results of the queries in set nottion. i. (3 points) {x y P (x, y) z (x z P (z, y)} Nmes of those with tel not shred y nyone else. {n3} 2
ii. (3 points) Give set uilder nottion for the following query: Give nmes of those persons whose telephone numer is not t. {x.nme P (x) y ((P (y) y.tel = t ) y.nme x.nme)} Explntion: hose y s who hve tel. ti nd x s nme is not sme s ny one of those y s. iii. (5 points) Give n SQL sttement for the following query using SQL EXISS. Get the nmes of those persons who shres telephone numer with nother person. SELEC X.nme ROM P X WHERE EXISS SELEC * ROM P Y WHERE X.tel=Y.tel nd X.nme!= Y.nme!= represents not equl 4. Let V = {S, A, B,,, c} nd = {,, c}. Determine whether G =< V,, S, P > is type 0 grmmr ut not type grmmr, type grmmr ut not type 2 grmmr, or type 2 grmmr ut not type 3 grmmr, or type 3 grmmr if P, the set of productions, is () (3 points) S S S S ype 2 ut not type 3 () (3 points) S AB B A A A c ype 2 ut not type 3 5. Give the lnguges, using set uilder nottion, for the following two grmmrs. () (3 points) G :< V,, S, P > V = {S, A, B,,, c} = {,, c} P={S AB, A A c, B B c} L(G) = { i c j c i 0 j 0} () (3 points) G :< V,, S, P > V = {S,,, c} = {,, c} P={S SB c, B B λ} L(G) = { i c( j ) i i 0, j 0} OR { i c j i, j 0} 3
6. Consider the following grmmr for rithmetic expressions: G: V = {E,,, +,, (, ),,, c}, = {+,, (, ),,, c}, P = {E E +, E,,, (E),,, c} () (5 points) Give derivtion for the word ((+)*c)+. E E + E + E + + + (E)+ (E )+ (E ) + (E c) + ( c) + ( c) + ((E) c) + ((E + ) c)+ ((E + ) c)+ ((E +) c)+ (( +) c)+ (( + ) c) + ( + ) c) + () (5 points) Construct the prse tree for the word ((+)*c)+. E + ( c E E * ( ) E + ) (c) (3 points) Extend the grmmr G to include the opertors - (minus) nd / (division). G extended : V = {E,,, +,,, /, (, ),,, c}, = {+,,, /, (, ),,, c}, P = {E E +, E E, E,, /,, (E),,, c} 7. (5 points) Construct finite-stte mchine for the lnguge: 0 0 E s 0 0 s 0 0, s 2 Reject NOE: Becuse trnsitions re functionl mpping (trnsition function), trnsitions hve to e defined for ll vlues of the domin (QxI). A must e le to go to the end of the input string for ny given input string to decide whether to ccept or reject the input string. 8. () (4 points) Give n A for the following lnguge: {x x = i i, i 2} 4
s0 s2 s s5, s3, s4, s6 () (6 points) Give two strings (words) for the following lnguge nd indicte why n A cnnot e uilt for the lnguge? {x x = i i, i 0}, 2 2 As cn e seen from the ove construction, to hndle string i i for ritrry vlue of i, one needs to hve n infinite numer of sttes which is not finite stte mchine. his not proof y ny mens ut n intuitive justifiction. his indictes tht context free lnguges (which re not regulr) cnnot e recognized y n A. 9. rnsition function of n A is defined s follows: f : S I S where S is finite set of sttes nd I is finite input lphet. () (2 points) Why for ech stte in n A trnsition hs to e defined for every input chrcter? Becuse it is function. () (2 points) Define the domin nd codomin of n NA where S is finite set of sttes nd I is finite input lphet. Domin is S Codomin is 2 S (c) (2 points) Why in NA trnsition function need not e defined for ech input on stte. In n NA trnsition on n input is to set of sttes which is suset of 2 S. Becuse 2 S includes the null set trnsition does not hve to go to ny stte. 0. Consider the nondeterministic finite stte mchine given elow (Mchine M): 0, 0, s0 s () (5 points) Wht is L(M) {0, } {0, } () (8 points) Convert the ove NA to n A y using n lgorithmic process. Descrie riefly your steps. q ɛq A, ɛi, f A (q, ) = pɛqn A f N A (p, ) 5
0 s0 s0,s 0, 6