Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our User Agreement and Privacy Policy.

Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our Privacy Policy and User Agreement for details.

Like this document? Why not share!

837 views

Published on

archived theory of computation question bank ecil 2000-2005

Published in:
Entertainment & Humor

No Downloads

Total views

837

On SlideShare

0

From Embeds

0

Number of Embeds

61

Shares

0

Downloads

0

Comments

0

Likes

4

No embeds

No notes for slide

- 1. CFLs & PDA –IIGN-PDA2-Q1. A cfg is ambiguous ifa) The grammar contains no useless non terminalsb) It produces more than one parse free for somesentencec) Some productions have two non-terminals side byside on the right hand sided) None of the aboveGN-PDA2-S1. Solution:We will use counter examples & the method ofeliminationa) Consider L = { }b) This is the standard definition of ambiguity incfg’s, that more than one parse free exists for asentence.Ex: S a, S A, A a S S A a or a‘TRUE’c) Consider L= { }The cfg S , S AB
- 2. Is unambiguous and contains two non-terminals onLHS.AlternativesS AB, A a, B b generates L= {a b}unambiguously‘FALSE’GN-PDA2-Q2.FORTRAN is aa) Regular language b) cflc) csl (context sensitive language) d) None of theaboveGN-PDA2-S2.Solution:The context-sensitive language are powerful enoughto describe all programming languages.Regular sets cannot describe parenthesis matching &cfg’s cannot describe semantic features of HLLs liketype checking.
- 3. GN-PDA2-Q3. Context-free languages andregular language are both closed under theoperation(s) ofa) Union b) intersectionc) concatenation d) complementation.GN-PDA2-S3. Union and concatenation preserve boththe classes of languages. So the answer is (a) & (c).GN-PDA2-Q4. For a context free grammar,FOLLOW (A) is the set of terminals that canappear immediately to the right of a non terminal insome “sentential” form. We define two setsLFOLLOW (A) and RFOLLOW(A) by replaces the wordsentential by “left most sentential” and “right mostsentential” respectively in the definition of FOLLOW(A).Which of the following statements is true?
- 4. a) FOLLOW (A) and L FOLLOW (A) may be differentb) FOLLOW (A) and R FOLLOW (A) are always thesamec) All three sets are identicald) All three sets are differentGN-PDA2-Q5. If G is a context-free grammarand W is a string of length l in L(G), how long isa derivation of w in G, if G is in the Chomsknormal form. (GATE-1992)a) 2l b) 2l + 1 c) 2l – 1 d) lGN-PDA2-S5.Solution:ConsiderS AB aB ab is the derivation l=2, and the no. ifsteps is 3.This problem has a monotonic function. Consider itsvalue around the origin.
- 5. GN-PDA2-Q6. Context-free languages are (GATE-1992)a) closed under unionb) closed under complementationc) closed under intersectiond) closed under Kleene closureGN-PDA2-Q7. Which of the followingconversions is not possible (algorithmically)?(GATE 1994)a) Regular grammar to cfgb) Non-deterministic fsa to deterministic fsac) Non-deterministic pda to determinstic pdad) Non-deterministic TM to deterministic TM.
- 6. GN-PDA2-Q8. Which of the following featurescannot be captured by a context-free grammar?(GATE 1994)a) Syntax of if-then-else statementsb) Syntax of recursive proceduresc) Whether a variable has been declared before it isusedd) variable names if even lengthGN-PDA2-Q9. If L1 and L2 are context-freelanguage & R is a regular set, one of thelanguages below is not necessarity a context-free language. Which one?(GATE-1996)
- 7. a) L1L2 b)L1 L2 c) L1 R d)L1 RGN-PDA2-S9.Solution:a) The concatenation of two cfls is a cfl, so L1L2 is acfl.b) L1 R is cfl as cfl regular set is a cfl.c) The union of two cfl is a cfl, so L1 L2.d) The cfls are not closed under intersection as { anbn ci /i, n 1} {ai bn cm /i, m 1} = {an bn cn / n 1}is not a cfl.GN-PDA2-Q10. Define for a cfl L {00,1}*,Imt(L) = { U/UV L for some V in {o, 1}*}. (Inother words Imt(L) is the set of all prefixes ofL).Let L= {w/w is non-empty and has an equalnumber of a’s & b’s}. Then Imt(L) isa) The set of all binary strings with unequal numberof 0’s and 1’s.
- 8. b) The set of all binary strings includers the nullstringc) The set of all binary strings with exactly one more‘0’ than the number of 1’s or one more 1 than thenumber of 0’sd) None of the aboveGN-PDA2-S10.Solution:a) is not conrrect as L is in Imt(L)c) is not correct as 0* and 1* are in Imt(L)b) is correct we can select any number of a’s & b’s inany order in Imt(L).GN-PDA2-Q11. Let Q=({q1, q2}, {a, b}, {a, b,z}, { , q1, z, u} be a PDA accepting, by emptystore the language which is the set of all non-empty even palindromes over the set {a, b}.Below is an incomplete specification of thetransition function . The top of the stack isassumed to be at the right end of the string
- 9. representation of the stack contents. (GATE 1996)1. (q1, a, z) = {q1, za}2. (q1, b, z) = { (q1, zb}3. (q1, a, a) = 1, 2 4. (q1, b, b) = 3 , 4 5. (q2, a, a) = {(q2, )}6. (q2, b, b) = {(q2, )}7. (q1, , z) ={(q2, )}Now boxes 1, 2, 3, 4 area) (q1, bb), (q2, ), (q1, aa), (q2, )b) (q1, aa), (q2, bb), (q1, bb), (q2, aa)c) (q1, aa), (q2, ), (q1, bb), (q2, )d) None of the above.GN-PDA2-S11.Solution:The language of even length palindromes {w (a,b)*} is a cfl that is not a dcfl. Only a non-deterministic pda can recognize this language.The trick is to guess the center.1: (q1, aa) guess if center has not come2: (q2, ) guess is center has come3: (q1, bb) guess center has not come4: (q2, ) guess if center has come
- 10. GN-PDA2-Q12. Which of the following languageover {a, b, c} is accepted by a DPDA? (GATE1997)a) {w wR / w (a b)*}b) {wwR / w (a b c)*}c) {an bn cn / n 0}d) {w/w is a palindrome over {a, b, c}}GN-PDA2-S12.Solution:c) is a standard language where {an bn cn / n 1} is acsl. We will not allow in csls. So it is not a cfl by thepumping lemma for cfls.(b) & (d) both contain {wwR / w (a b c)*} . Cannot guessthe center, for this we need a nondeterministic pda.a) is a standard dcfl where in the left of c we pushonto the stack & right of c we pop the stack.GN-PDA2-Q13. What is the language acceptedby the following PDA?
- 11. (GATE 1998) (q0, 1, z0) = {(q0, Xz0)} (q0, , z0) = {(q0, )} (q0, 1, X) = {(q0, XX)} (q1, 1, X) = {(q1, )} (q0, 0, X) = {(q1, X)} (q1, 0, z0) = {(q0, z0)}a) {0n10n1/ n 1}b) {1n01n / n 1}c) {1n01n0 / n 1}d) {1n01n01n / n 1}GN-PDA2-S13.Solution:a) In state q0, 0+… is not accepted so (a) is ruledout by eliminationb) 1n means n X’s are stacked 0 and is a transitionform q0 to q1. In state q1, 1n in the input is requires.A last 0 allows the m/c to go back to q0 and by an move empty the stack and accept.(A b in the question is that is accepted by the pda)Note that (b) & (d) do not allow the stack to beemptied
- 12. GN-PDA2-Q14.What is the language generated by the CFG? (GATE 1998)S1 aS1bS1 aAbS1 aBbA aA aB Bb bHere V = {S1, A, B} & T = {a, b}a) {a b : n, m 0, n m 2} n mb) {a b : n, m 1, n m 1} n mc) {a b : n, m 0, n m 1} n md) {a b : n, m 0, n m 0} n mGN-PDA2-S14.Solution:S1 aS1b, S1 a S1b R * A aA a, A a * B bB b, B b * S1 a R aAbb R a R aBbb R * a n aa bb R a n ab bb R * a R a b R a R b b R *
- 13. GN-PDA2-Q15.Context free language are closed under (GATE1999)a) Union, intersectionb) Union, Kleene closurec) Intersection, complementd) Complement, Kleene closureGN-PDA2-S15.Solution:Cfls are not closed under . We have {an bn ci/ i,n 1} {ai bm cm/ i, m 1}={an bn ci/ n 1} is not a cfl.The complement operation does not preserve thecfls.By elimination (a), (c) & (d) are ruled out.CFL’s are closed under union and Kleene closure.GN-PDA2-Q16. Let LD be the set of alllanguages accepted by a PDA by find state and
- 14. LE the set of all languages accepted by emptystack. Which of the following is true? (GATE1999)a) LD = LE b) LD LE c) LD LE d) None of the aboveGN-PDA2-S16.Solution:Standard result (a)GN-PDA2-Q17. If L1 is a context-free languageand L2 is a regular language which of thefollowing is/are false?a) L1 - L2 is not context freeb) L1 L2 is context freec) ~L1 is context freed) ~L2 is regularGN-PDA2-S17.Solution:d) is true as regular sets are closed undercomplement
- 15. b) is true as cfl regular set is a cfla) L1-L2 is a cfl. Consider a pda acceptors L1 whichstore the f.a. acceptor L2 on its finite control. If astring is in L2 the pda will not acceptc) The cfls are not closed under complement.GN-PDA2-Q18. Let L denote the languagegenerated by the grammarS 0S0/00. Which of the following is true? (GATE 2000) +a) L= 0 b) L is regular but not 0+c) L is cfl and not regular d) L is not context-free.GN-PDA2-S18.Solution:a) 0 is not generated by the cfg. So (a) is not theanswerd) is false as a cfg generated a cfl.c) cfls over a single alphabet are regular. So (c) isfalse.Note that (00)+ is generated by sBy elimination (b) is answer
- 16. GN-PDA2-Q19. In a programming languagewhose syntax is context-free (GATE2000)a) Multiple variables having the same featuresb) Multiple variables having the same valuesc) Multiple variables having the same memoryidentifiers.d) Multiple uses of the same variableGN-PDA2-S19.Solution:The same goonda may have many names but stay inone house.
- 17. GN-PDA2-Q20. Consider the following decisionproblems.( 1 ) Does a given FSM accept a given string.( 2 ) Does a given CFG generate an infinite numberof stringsa) Both (P1) and (P2) are decidable.b) Neither (P1) nor (P2) is decidable.c) Only (P1) is decidable.d) Only (P2) is decidable.GN-PDA2-S20.Solution:We can construct a dfa and trace it to see if a givenstring is accepted. So P1 is decidable.Take a cfg, throw array useless non-terminals, drawthe graph with non-terminals as nodes. If A --B--?Put an edge between A & B. If the resultant graphhas loops, the cfg generates an infinite set. Thus P2is decidable.So both P1 & P2 are decidable.
- 18. GN-PDA2-Q21. Which of the followingstatements is true? (GATE2001) a) If a language is context-free it can always beaccepted by a determine push down automatab) The union of two cfls is a cflc) The intersection of two cfls is a cfld) The complement of a cfl is a cflGN-PDA2-S21.Solution:Standard results. The cfls are not closed underintersection or complement and require a non-deterministic pda for their recognition. The cfls areclosed under union.GN-PDA2-Q22. The language accepted by apush down automation in which the stack islimited to 10 items is best described as (GATE 2002)a) Context free b) Regularc) Deterministic context free d) Recursive
- 19. GN-PDA2-S22.Solution:All are correct but the smallest class of formallanguages here is (b).GN-PDA2-Q23. Let G= ({S}, }, {a, b}, R, S) bea context-free grammar where the rule set R isS aSb SS Which of the following is true? (GATE 2003)a) G is not ambiguousb) There exist x, y L(G), Such that xy L(G)c) There is a deterministic PDA that accepts L(G)d) We can find a DFA that accepts L(G)GN-PDA2-S23.Solution:a)S SSSS SSSS *
- 20. & so is highly ambiguous. Any sentence generatedhas an infinite number of derivation trees. So (a) isfalse.b)S SSSS SSS * x ySo S x first & then * S y so S xy for * * all x & y so(b) is falsed) S {a nbn / n 0} + * other strings L(G) a*b*={a nbn / n 0} This is not regular so (d) is false.By elimination (c) is the answerS ah1bh1ah 2bh 2 ah 2h3 * The above can easily be checked by a DPDA. So (c)is trueGN-PDA2-Q24. FSM can recognize the languagegenerated bya) Any grammar b) only cfgc) Any unambiguous grammar d) Only a regulargrammar
- 21. GN-PDA2-S24.Solution:Consider {a}, a regular set , it is generated by theambiguous grammar S a, S aA, A , which is aregular grammar. So (c) is not true.GN-PDA2-Q25. The following cfg G does notgenerates the language denoted by the regularexpression.G: S aS bS b aa) (a*+ b)* b) (a + b)*c) (a + b)(a + b)* d) (a + b)*(a + b)GN-PDA2-S25.Solution:S aS bS b aThe grammar generates (a + b)* = (a + b)(a + b)*= (a + b)*(a + b)*
- 22. It does not generate (a) as is not generated by thegrammar.GN-PDA2-Q26. Any string of terminals that canbe generated by the following CFGS xy, X aX bX a, Y Ya Yb aa) Has at least one bb) Should end in two a’sc) Has no consecutive a’s or b’sd) Has at least two a’sGN-PDA2-S26.Solution:X (a b)* a * Y a(a b)* * S XY (a b)* aa(a b)* * a) Is not correct as b need not be thereb) Need not end on to a’sc) Has consecutive a’s & b’sd) Answer is (d) as two a’s must be there
- 23. GN-PDA2-Q27. The following cfgS aB bAA a aS bAAB b bS aBBgenerates strings of terminals that havea) equal number of a’s & b’sb) odd no. of a’s and odd no of b’sc) even no. of a’s and even no. of b’sd) odd no. of a’s and even no. of b’sGN-PDA2-S27.Solution:By elimination1. Try S aB abThis eliminates choices (c) & (d)2. S aB abS abaB ababThis eliminates (b) so the answer is (a)
- 24. GN-PDA2-Q28. To prove A = L(G)a) It is enough to prove that an arbitrary number ofstrings from A are generated by G.b) It is enough to prove that every arbitrary stringgenerated by G, belongs to Ac) Both (a) & (b) have to be provedd) Either (a) or (b) have to be provedGN-PDA2-S28.Solution:a) Says A A L(G)b) Says L(G) ASo both (a) & (b) have to be provedGN-PDA2-Q29. The set {an bn / n = 1, 2, 3, …..}Can be generated by the CFGa) S ab aSbb) S aaSbb abc) S ab aSb
- 25. d) S aaSbb ab aabbGN-PDA2-S29.Solution:The grammar generatesa) S (anbn , n 1) * b) S (aa)n S (bb)n / ab, n 1 (aa)n ab(bb)n , n 0 i.e odd no. of a’s * * followed by odd no. of b’s, with an equal no. of a’s &b’sc) S anbn , n 0 * S (aa) n S (bb) n / ab / aa bb, n 1 * (aa) n ab(bb) n / (aa) n 1 (bb) n 1 , n 0 * d) a mb m , m 1 *GN-PDA2-Q30. Choose the correct statementsa) All languages can be generated by CFGsb) Any regular language has an equivalent CFGgenerating itc) Some non-regular languages can’t be generatedby any CFGd) Some regular language can’t be generated by anCFG
- 26. GN-PDA2-S30.Solution:a) {an bn cn / n 1} cannot be generated by a CFG.“FALSE”b) Every right –linear & every left-linear grammar istrivially a CFG and here (b) is “TRUE”c) { an bn cn / n 1} is a non-regular language thatcannot be generated by any CFG. Hence c is “TRUE”d) All regular language can be generated by right-linear grammar, which are trivially CFGs so (d) is“FALSE”GN-PDA2-Q31. Which of the following languagegenerated by the given CFGs cannot berecognized by an FSM ?a) S Sa ab) S abXX cyY a aXc) S asb abd) None of the above
- 27. GN-PDA2-S31.Solution:a) S a , a regular set * b) X cy cd caXX (ca)* cd * So S ab(ca)* cd , a regular set * c) S anbn / n 1, which is a cfl that is not regular * GN-PDA2-Q32. The class of CFLs is not closedundera) Union b) Kleene starc) Complementation d) ProductGN-PDA2-S32.Solution:Standard theorem applied. We know that cfls are notclosed under complementation or intersection. Theyare closed under union, Kleene star & product.
- 28. GN-PDA2-Q33. The set A= {a^n b^n a^n/n 1}is an example of a set that isa) regular b) contc) not context free d) NonGN-PDA2-S33.Solution:By the pumping lemma for cfls the set A is not a cfl.However it can be shown to be a csl.GN-PDA2-Q34.Let L1={anbnam /n, m=1, 2, 3, …..}
- 29. L2= {anbmam /n, m=1, 2, 3, …..}L3= {anbnan /n=1, 2, 3, …..}Choose the correct answer.a) L3=L1 L2b) L1 and L2 are CFL but L3 is not CFLc) L1 and L2 are not CFL but L3 is CFLd) L1 is a subset of L3GN-PDA2-S34.Solution:L3 is not a CFL as it does not satisfy the pumpinglemma for CFL’sa) L3 L1 L2 a n b m a m / n, m 1 a b a / n, m 1 n m m a b a / n 1 , so is correct n n nb) L1 & L2 are cfls generated by the cfl sS1 AB S2 CDB a B / a & C ac / aA aAb / ab D b Da / bac) This is false as seen by (b)d) L3 L1 is true
- 30. GN-PDA2-Q35. L= {an bn cn /n=1, 2, 3,….} is anexample of a language that isa) Context free b) not context freec) Not context free but whose complement is CFLd) Context free but whose complement is not CFLGN-PDA2-S35.Solution:L is a standard language that is a CSL and not a CFL.Its complement is a CFL. So (b) & (c) are correct.GN-PDA2-Q36. The intersection of a CFL and aregular languagea) need not be regular b) need not becontext freec) is always regular d) is always CFL
- 31. GN-PDA2-S36.Solution:L R is always a cfl if L is a CFL & R a regular set.GN-PDA2-Q37. Choose the correct statements.a) The power of DFSM and NDFSM are sameb) The power of DFSM and NDFSM are differentc) The power of DPDM and NPDM are differentd) The power of DPDM and NPDM are sameGN-PDA2-S37.Solution:Standard result of theorem:1) Non-determinism does not add power to the finitestate machines. Every non-deterministic FSM can beconverted to an equivalent deterministic FSM by a
- 32. construction of the subset machine2) The language of even length palindromesL wwR / w a b * cannot be accepted by anydeterministic PDM as it cannot guess the center. Itréquires a non- deterministic PDM to accept this set.GN-PDA2-Q38. Which of the following isaccepted by an NDPDM, but not by a DPDM?a) All strings in which a given symbol is present atleast twiceb) Even palindromes (i.e palindromes made up ofeven number of symbols)c) Strings ending with a particular alphabetd) None of the aboveGN-PDA2-S38.Solution: (b) is a standad dcfl which is not a cfl.
- 33. GN-PDA2-Q39. P, Q, R are three languages. If Pand R are regular and if PQ=R, thena)Q has to be regular b) Q cannot be regularc) Q need not be regular d) Q has to be a CFLGN-PDA2-S39. The method of elimination can beemployed. 1. Let P=Q=R=EMPTY SET. The equation is satisfied. So this rules out (b). 2. Let P=R be ∑* then any Q will satisfy the equation. The demands of (a) & (d) are invalid. 3. So the answer is (c ).GN-PDA2-Q40.
- 34. Let L1={ai bj ck/i<j<k}L2={ijml /j=l2}L3={ai / i is prime}L4=the set of strings a’, b’s and c’s with anequal number of eachL5={anbncm/n m 2n}Which of the following statements is correct?a) L1 and L3 are not CFLs but the rest are CFLsb) L3 and L4 are not CFLs but the rest are CFLsc) All are not CFLs d) None of the aboveGN-PDA2-S40.Solution:Pumping Lemma for CFLs shows all are not CFLsGN-PDA2-Q41. Consider the following CFG Gdefined by productionsSaSbS / bSaS/
- 35. The language generated by this CFG isa) The set of all strings which contains even numberof a’s and even number of b’sb) The set of all strings which contains odd numberof a’s and even number of b’sc) The set of all strings which contains odd numberof a’s and odd number of b’sd) The set of all strings which contains equal numberof a’s and equal number of b’sGN-PDA2-S41.Solution:The strategy used is the method of elimination1) S asbs ab * This rule out (a) & (b). We here to choose between(c) & (d)S asbs aasbsbs a 2b2 * * This rule out (c). So by elimination (d) is the answer.GN-PDA2-Q42.
- 36. Let L1 = {an am c2(n+m) /n 0, m 0}L2 = {ai bj ck/i<j<k}L3 = {0n1m/ n m 2n}Which of the following is correct?a) L1 is context free but L2 and L3 are notb) L1 and L2 is context free but L3 is notc) All are context freed) L3 is regular and L1, L2 are context free42. Solution:At least two portions of the strings are related,1) a’s & c’s in L1 2) a’s & b’s in L2 3) 0’s & 1’s in L3They cannot be regular.Consider a homomorphism h(a) = b, h(c) = cThen h (L1) = b c / m 1 & is a cfl } m m L3 0n / n / n 1 0n / n / n 1 is a cflL2 alsois a cfl.G1 generates L1 :S AC / BDC C /cA aAbb / abbB aB / aD bb Dc / bbcC3 gonada L3 :S 0 S1 / 0 S11/
- 37. GN-PDA2-Q43. Consider the following grammarwith productionsS ABA BB / a,B AB / b,Choose the incorrect statementa) aabbb can be derived from the above grammarb) aabb can be derived from the above grammarc) abacas can be derived from the above grammard) aaabb can be derived from the above grammarGN-PDA2-S43.Solution:
- 38. a ) S AB AAB AAAB AABBB aabbb * (can be gorades)b) Assume A gereda only aneven no of B SS odd no. of B S * B odd no. of B s * A even no. of B s providing assumption * So S odd no.of B s * odd no.of b s * So b & d cannot bec) S AB AAB ABBB ABABAB ababab * d ) Assume A gereda only aneven no of B SS odd no. of B S * B odd no. of B s * A even no. of B s * So S odd no.of B s * odd no.of b s * Sob & d cannot beGN-PDA2-Q44.
- 39. Let L1={an bm cn+m: n 0, m 0}L2 = {an bn+m cm: n 0, m 1}L3 = {a3bncn: n 0}L4 = {an bm: n 0, m 3n}a) L3, L4 are context free but not L1 and L32b) L1, L3 and L4 are context free but not L2c) All are context freed) None of the aboveGN-PDA2-S44.Solution:a ) L1 is generates by the cfg L1S aSc bSc abScc ac bc abccb) L2 is generates by the cfgS ABA aAb / abB bBc / bcc) L3 is by the cfgS ABA aaaB bBc / bcd ) L4 is generated by the cfgS aSb / aSbb / aSbbb /
- 40. GN-PDA2-Q45.Consider the PDA {(q0, q1,q2), (a, b), (Z, S, A,B) , q0, Z, {q2}}1. (q0 ,, Z ) {( q1 , SZ)}2. (q1 , a, S ) {( q1 , SA), (q1 ,)}3. (q1 , b, A) {( q1 , B)}4. (q1 , b, B) {( q1 , )}5. (q1 ,, Z ) {( q 2 , )}a){an b2n /n 0} b) {an b2n+1 /n 0}c) {an+1 b2n /n 0} d) {an+1 b2n+1, n 0}GN-PDA2-S45.Solution:δ q1 , a, S q1, SA Keeps on pushing onto the stack. Forevery a in the input A is stacked.When b comes in the input q, b, A q, Bit converts the A on the top of the stack to a B q, b, B q,b in the input gets rid of the B.For n,a’s in the input are must here 2n, b’s in theinput.One more a is required on the start to get rid of thefalse bottom make S,
- 41. So L a n1 b2 n / n 0 is not accepted by the pda, one a is required Method of elimination:a) Is not accepted by the PDA. In the input putsfalse bottom make S, when requires an ‘a’ on theinput to remove. The q1 ,, z takes it to a final state.b) b is not accepted. So (b) is ruled outc) a alone should be accepted, this rules out (d)GN-PDA2-Q46.Choose the correct statementa) For any CFL L, there exist a DPDA M such that L =L(M)b) For any CFL L, there exist a NPDA M such that L =L(M)c) For any non regular language L there exist anNPDA M such that L=L(M)d) For any regular language L there exist an DPDA Msuch that L=L(M)
- 42. GN-PDA2-S46.Solution:a) The language of even length palindromesL= ww / w a b * cannot be accepted by a DPDA R‘FALSE’b) This is true as NPDA can reverse all the CFLsc) is non-regular but not a CFL . ‘FALSE’ L a nb n c n / n 1d) DPDA can accept all the regular sets ‘TRUE’GN-PDA2-Q47.Consider the following context free grammars1. SaSbb / a2. SaSA / a, AbB, BbWhich of the following is correct?a) The language generated by ‘1’ is subset of ‘2’b) The language generated by ‘2’ is subset of ‘1’c) The language generated by both the grammars ‘1’
- 43. and ‘2’ are equald) None of the aboveGN-PDA2-Q47.Solution:1. S aSbb / a * i.e. S a n S (bb) n / a, n 1 * a n 1 b 2 n , n 0 * 2. S aSA / a * aSbB / a * aSbb / a * a n b 2 n , n 0 * The languages are the same.GN-PDA2-Q48. Which of the following isincorrect?a) Every regular language is a non-deterministiccontext free languageb) If L1 is a deterministic context free and L2 isregular then the language L1 L2 is a deterministiccontext freec) If L1 is a deterministic context free and L2 is
- 44. regular then the language L1 L2 is a deterministiccontext freed) For every deterministic context free language thereverse also is a context free languageGN-PDA2-S48.Solution:a) is true, as the regular sets are a subclass of thedcflsb) Table a dpda accepting L1 and in the finite controlput in a dfa accepting L2. If either acceptsthenaccept, so L1 L2 is a dcflc) This is a standard theorem. In the constructionabove in (b), the input is accepted by both the faand dpda then acceptd) L a 0n / n / n 1 0n / 2n / n 1 is , but the revesel is notGN-PDA2-Q49. Deterministic context freelanguages are closed undera) Kleene closure or intersection b) UNION or
- 45. concatenationc) Homomorphism d) inversehomomorphism and complementationGN-PDA2-S49.Solution: a) a n b n c 0 / 0, n 1 a j b mc m / j , m 1 a n b n c n / n 1 is a csl that is not a dcfla b c n n i / i , n 1 is a & so is a j b m c m / j , m 1So @ is false b) 0 n / n / n 1 & 0 n / 2 n / n 1 arebut theunion is notSo (b) is false c) L a 0n / n / n 1 0n / 2 n / n 1 is a but h(a) , h(0) 0, h(1) 1 make h( L) a cfl that is not a so (c) is falseBy e lim ination (d ) is truea) L1/L2 where L2 is any language & L1 is a dcflcannot be a dcflb) DCFLs are not closed under union, concatenation,homomorphism or intersectionUnion: L 0n / n / n 1 0n / 2 n / n 1 is not a though theunderlined language L a 0n / n / n 1 0n / 2 n / n 1 is ah(a) , h(0) 0, h(1) 1h( L) is not a
- 46. GN-PDQ2-Q50.Read the following definitions1. The quotient of L1 with respect to L2 denotedby L1 / L2 is{X/there exists w in L2 such that xw is in L1}2. MIN (L) = {x/x is in L and no w in L is properprefix of x}3. MAX (L) ={x/x is in L and x is not a properprefix of any word in L}a) DCFL’s are closed under quotient, min, max,complement, inverse homorphism, intersection withregular sets, and regular difference (DCFL-Regular)b) DCFL’s are not closed under union, concatenation,kleene closure, homomorphism or Intersectionc) L1= {ww/w (0+1)*} L2= {anbncn: n 1} are notCFL’s but L1 and L 2 are CFL’sd) All of the above statements are true.
- 47. GN-PDAQ2-S50.Solution:Intersection:a b n n c i / i, n 1 a j b m c m / j , m 1 is a b n n c n / n 1 not a dcfl though thetwo languages are concatenation L1 0n / n / n 1 is a dcflL2 0 n / 2 n / m 1 is a dcflL L1 L2 is not a dcfl c) The set L1 ww / w 0 1 is a standard CSL that is not a CflConsider L1.This requires string Q 1 l1 1 l2 l1 0 l2 i) A string of odd length must be in L1Odd length strings are generated byii) If a string is if even length then to be in L1 thefirst hall of last half must error in at least oneposition 0 1 l1 1 l2 l1 0 l2 Can be written as 0 1 l1 1 l1 l2 0 l2 S A 0S A 0 S A 0S A 1 SA 0S B 0S B 0 S B 0S B S B 0 1
- 48. S S A SB / SB S A L a nb n c n / n 1 is a standard CSL that is not a CFL. Itscomplements are a CFL. Consider CFG given below1) The string is in a+b+c+ then it is in L2) If the string is on a+b+c+ then either a’s not thesame a, b’s b’s but the same as c’s, a’s but the sameas c’s a b c H P CMore acceptors a+b+c+ the –more a a b c H H,P,C P,C C P - P,C C C - - C a b c *H HPC HPC C *HPC HPC PC C * PC - PC C C - PC C
- 49. a a HPC HPC c b b c c C PC a R c b a,bConstruction of the complement dfaThe dfa a a H HPC c b b c c a a,b,c C PC R c b a,b H , HPC, C, PC , R * a b c *H HPC PC C HPC HPC PC C PC *R PC C C *R *R C R *R *R *R H , HPC , PC , C , R
- 50. a b b H P or PC a c a,b,c R C a,b cSetting up the regular expression equation H Ha (1) P Hb Pb (2) C Hc Cc Pc (3) R Pa Ca Cb R (a b c ) (4) Solve(1) : H a * (4) Substitions (2) P a * b Pb (5) So try (5) P a * bb * Substitions in (3) C a*c Cc Pa*b a*c a*b Cc (7) Solve(7) : C a*c a*b C * (8) Substiotion in (4) : R a* bb*a a*c a*b* c* a b c R a b c (9) So this R= a* bb*a a*c a*b c* a b c * Substituting 0 for a & 1 for b we can get the right productions from the dfa: for a*b*c*
- 51. H aH bp cCp bp aR cCC cC aR bRR aR bR R abcnowthe a here productions are on the grammar &a b c n n n / n 1A string is in a*b*c* but not ina b c n n n / n 1a) unequal no. of a s & b sb) unequal no.of b s & c sd ) unequal no.of a s & c sA aA / a , A a * B bB / b, B b * C cC / c, C C * Eab a Eab b / ab, Eab a nb n / n 1 * Ebc bEbc c / bc, Ebc b m c m / m 1 * nowS AEab AELab C Eab B Eab CS Ebc C AEbc C BEbc ABEbcS a c acX A C AB BC
- 52. GN-PDQ2-Q51.Choose the correct statementa) If L1= {anbn: n 0} then LK is context free for anyk1 u wb) {uvwvR: u, v, w {a, b}+, =z} is context freec) L= {w1cw2:w1,w2 {a, b}+, w1 w2R}, with = {a,b, c} is context freed) all of the above are correct statementsGN-PDA2-S51.Solution: Consider pda accepting the sets: a) A pda reads the input left to right. First the a’s are stacked & then compared with b’s coming in the input. Check that a’s and b’s are same. Repeat the process till the end of the strings. b) A pda (non-deterministic) reads L v3 v R v a, b * the input left to right. For every three symbols in the input X is pushed onto the stack.. Nondeterministically it checks for V^R, by guessing the V between V^3& VR c) A pda pushes w1 onto the stack. It pumps depending on W2. The change from push to pop state occurs at c. The stack should put be emptied out by w2.
- 53. GN-PDA2-Q52. Choose the incorrect statementa) {wwR:w {a, b*} is not inherently ambiguousb) SaSbS| bSaS| is an ambiguous grammarc) Let G= (V, T, S, P) be a context free grammarsuch that every one of its productions is of the formAV, with v =k>1. Then derivation tree for anyw L(G) has a height h such ( w 1)logk w h k 1d) None of the aboveGN-PDA2-S52.Solution: a) S asa bsb is an unambiguous grammar L wwR / w a, b * generating So (a) is TRUE b) Consider the string abab
- 54. S S aSbS aSbS bSaS a SbS So the grammar is ambiguous as abab has two parse treesGN-PDA2-Q53. A context free grammar is saidto be ambiguous if it hasa) w L(G) which has at least two distinct derivationtreesb) w L(G) which has at least two distinct left-mostderivationsc) w L(G) which has at least two distinct right-mostderivationsd) Any one of the above
- 55. GN-PDA2-Q54. Consider the two grammarsG1: SabAB| baAaaaBAa|bbG2:Sabaca.Choose the correct statementa) The language generated by G1 is a subset of G2b) The language generated by G2 is subset of G1c) There is no relation between G1 is and G2d) None of the above GN-PDA2-S54. Solution:
- 56. L(G1 ) : S ab AB / ba ab a 3 B / ba B aA / bb a h / b2 So, S aba 7 aba 3b 2 ba * L(G2 ) : S abAaA abAbb ba aba 3aa 3 aba 3b 2ba aba 7 aba 3b 2 ba L (G1) =L (G2)GN-PDA2-Q55. Choose the correct statement.a) CFLs are closed under reversalb) CFLs are not closed under set difference butclosed under regular set difference, that is, if L1 iscontext free and L2 is regular then L1-L2 is contextfreec) There exists an algorithm to determine whetherthe language generated by some context freegrammar contains any words of length less thansome given number n.d) Let L1 be a CFL and L2 be a regular set. Thenthere exist an algorithm to determine whether or not
- 57. L1 and L2 have common element.e) All of the above GN-PDA2-S55. Solution: a) CFLs are closed under reveral. In any cfg if reverse the rhs of all productions, we still have a cfg wnich generates the reversal of the original cfl. b) In the finite control of the pda accepting L1, put in the dfa accepting L2. If the strings in in L2 then the pda will reject otherwise it behave as if it were in L1-L2 c) Apply the CYK algorithm to the cfg for 0,1, 2, , R where R=n. d) L R is a cfl where L is a cfl & R is a regular set. Check if L R A cfl is empty.

No public clipboards found for this slide

×
### Save the most important slides with Clipping

Clipping is a handy way to collect and organize the most important slides from a presentation. You can keep your great finds in clipboards organized around topics.

Be the first to comment