Cflpdai

263 views
174 views

Published on

archived theory of computation question bank ecil 2000-2005

Published in: Entertainment & Humor
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
263
On SlideShare
0
From Embeds
0
Number of Embeds
57
Actions
Shares
0
Downloads
0
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Cflpdai

  1. 1. CONTEXT FREELANGUAGES(CFLS) & PUSH DOWNAUTOMATA(PDA) – IGN-PDA1-Q1. Consider the cfg’sG1: S   0S11S 0 SSG2: S  A BA  0 0 A 1AA A1A AA1B  11B 0BB B0B BBCG3: S  aSb ab aSa bSb a b G4: S G5: S  SS (S ) ( )G6: E  E  E / E.E / E* ( E) a b  G7: S  aA1B aBA1 bA2
  2. 2. A1  a aS bA2 A1A2  aA1 bA2 A2B  aA1BB aBA1B b bSG8: S  aS aChoose the false statementa) L(G1) generates an equal number of 0’s & 1’sb) L(G2) generates an unequal number of 0’s & 1’sc) L(G3) generates L = {an bn/n  1}d) L(G4) generates all palindromee) L(G5) generates all the well balanced parenthesisf) L(G6) generates the set of well formed regularexpressionsg) L(G7) generates the set of all strings in {a, b}+with free as many a’s and b’sh) L(G8) generates a*GN-PDA1-S1. Solution:A) Is not correct as S  aB) Is not correct as  is not generated by GC) S  aAS aSbAS aabAS aabaS aabaaD) is put correct asS  aAS/a aSSS/a aaaa/aSo S  a4
  3. 3. GN-PDA1-Q2. Consider the languageL= {ai, bj, cl) | i  j or j  h}We are given as followsAshok has to make auto nodes, a for auto ride; busrides given by b’s & car rides c. He can make anynumber of auto, bus or car nodes. The order is autonodes first, bus nodes next and car nodes last. Hemust either make an unequal number of auto & busnodes or an unequal number of bus & car nodes.So to make an unequal number of auto & bus nodeshe makes an equal number of auto & bus nodes andadds some auto nodes or bus nodesA  aA a , gives one or more auto nodesB  bB b , gives one or more bus nodes.X  aXb ab , gives an equal no. of bus & car nodesC  cc c , gives one or more car nodesS1  Xb Xbc aX aXc , gives an unequal no. of bus & autonodes.
  4. 4. Z0 make an unequal number of bus & car nodes,Ashok makes an equal number of bus & car nodesand adds some auto nodes or bus nodes.Y  bYc bc , gives an equal no. of bus & car nodes.S2  Yc AYC BY ABY , given an unequal or no. of bus & carnodesS  A B C AC BC ABThis gives all other unequal no. of auto and busnodesChoose the wrong statementa) S generates {ai bj cl/ i  j as in the grammer aboveor j  l}b) The missing productions are S  S1 & S  S2 for thelanguage {ai bj ch || i  j or j  l}c) S does not generate d) S does not generate {anbncn/n  1}GN-PDA1-Q3. The grammar S  a / SS / a) Is an unambiguous grammar
  5. 5. b) is an ambiguous grammar where any sentencehas two distinct derivatives.c) is an ambiguous grammar where any sentencegenerated has an infinite number of parse trees.d) is a grammar when the left must & might mustdurations for all sentences are the same.GN-PDA1-Q3. The grammar is ambiguous as theempty string has an infinite number of derivations.GN-PDAQ1-Q4. Consider the grammarG: S  aAS / aA  sbA / SS / baChoose the correct statementsa) L(G) =empty setb) L(G) = ( a + b)*c) aabbaa is generated by the grammard) aaaa is not in L(G)GN-PDAS1-Q4: From rule Sa by eliminaton (a)can be ruled out.Consider S->aAS->aSSS->aaaa.
  6. 6. So (d) is the answer.As the empty string is not generated we canrule out choice(b).GN-PDA1-Q5. Eliminating  from the cfg Gobtain the grammar G1I. G: S  XaX  aX bX The resulting grammar isG1: S  Xa X  aX a bX bII. G1: S  XYX  2bY  bwz  ABw zA  aA/bA/ B  Ba/Bb/  G1 : S  XY 1X  zbY  bw
  7. 7. zW zA  aA bA a bB  Ba Ba Bb a bNext iterationS  XYX  2bY  bwZWA  aA bA a bB  Ba Bb a bNext iterationS  XYX  2b bY  bw bA  aA bA a bB  Ba Bb a bNext iterationS  XYX bY bA  aA bA a bB  Ba Bb a bIII. G11 : S  AB CA A a B  BC AB C  aB b
  8. 8. G1 : 11 A & C can generate terminal symbols.S  AB CAB  BC ABC  aB bB is a useless non terminal so elements atS  CAA aC bIs the reduced grammarIV: G1111: S  AB, A  a, B  b, B  c, E  dG1 : Find iterative A, B, E are useful and can 1111generate terminalS  AB, A  a, B  b, B  c, E  dCu useless, demands itS  AB, A  a, B  b, E  dDraw the graph of the grammar A S E BE is not readable from S,So elements isS  AB, A  a, B  bIs the required grammarV. G2: S  A bb A B b B S aEliminate the unit productersS  A  B  S *  *  * We haveS  B b bb
  9. 9. B  S a Next iterationS  S a b bbAS a bBS aHowever A & B are not readable from S. So S  a b bbIs the required grammarV. G2 : S  AB 1A aB C DC DD EE aG2 : Eliminate unit production 11First iterationS  ABA aB C bC DD aE  a(delete this)Second iterationS  ABA aB C bC aD  a(delete this)Third iterationS  ABA aB a bChoose the correct statement
  10. 10. a) The reduced grammar generate the samelanguageb) The reduced grammar may not generate the samelanguagec) If we remove unit productions from a cfs thelanguage generation is differentd) None of the aboveGN-PDA1-Q6. Consider the modified cfgI. G1: S  aSb abG1 mod: S  XSY XY , X  a, X  bIteration:S  XZ XYZ  SYX  a, X  bII. G2:S  asa bSb a bG2mod: S  XSX YSY a bX aY b
  11. 11. IterationS  XS x YS y a bSx  SXSy  SYIII G3: S  bA aB A  a as bAA B  b bS aBBG3mod: S  Cb A Ca B Cb  b, Ca  a A  a Ca S Cb AA B  b Cb S Ca BBIteration:S  Cb A Ca B Cb  b, Ca  a A  a Ca S Cb X X  AA B  b Cb S Ca BB Y  BBChoose the correct statementa) G as modified above is in the Chomsky normalformb) G as modified above is the Giebach normal formc) G as modified above changes the languagegeneratedd) None of the above
  12. 12. GN-PDA1-Q6. Consider productionsA  A1 A 2   A rA  1 2   5a) We can remove the left recursion by replacing theabove rule byA  1 2   5 1Z   5 Z     Z   ZZ 1 r 1 rb) We cannot remove left recursion from a cfgc) Left recursion cannot be removed from a cfgd) None of the aboveGN-PDA1-S6. Choice (b) is wrong if we consider thegrammar, SSa|a which can be rewritten asSaS|a.Choice (c ) can be eliminated as we have theSS,Sa.Choice (a) is the standard theorem.So the answer is (a).
  13. 13. GN-PDA-Q7. Let G be a CFG inn CNF. G is S  AB,A  Bs b , B  SA aStep1:Rename S, A & B asA1  A2A3A2  A3A1 bA3  A1A2 aStep 2: The first symbol on RHS should be greaterthan symbol on lhsA1  A2A3A2  A3A1 bA3  A2A3A2 aStep 3: Repeat as in step 2A1  A2A3A2  A3A1 bA3  A3A1A3A2 bA3 A2 aStep 4: Eliminate the left recursion of A3A1  A2A3A2  A3A1 bA3  bA3 A2 a bA3 A2 Z aZZ  A1 A3 A2 A1 A3 A2 ZStep 5: Substitute for A3 in A2 productionA1  A2A3A2  bA3 A2 A1 aA1 bA3 A2 ZA1 aZA1 bA3  bA3 A2 a bA3 A2 Z aZ
  14. 14. Z  A1 A3 A2 A1 A3 A2 ZStep 6: Substitute for A2 in A1 productionA1  bA3 A2 A1 A3 aA1 A3 bA3 A2 ZA1 A3 aZA1 A3 bA3A2  bA3 A2 A1 aA1 bA3 A2 ZA1 a2 A1 bA3  bA3 A2 a bA3 A2 Z aZZ  A1 A3 A2 A1 A3 A2 ZStep 6: Substitute for A1 in Z productionsA1  bA3A2A1A3 aA1 A3 bA3 A2 zA1 A3 azA1 A3 b A3A2  bA3 A2 A1 aA1 bA3 A2 zA1 azA1 bA3  bA3 A2 a bA3 A2 z aZZ  bA3 A2 A1 A3 A3 A2 aA1 A3 A3 Az bA3 A2 z A1 A3 A3 A2 azA1 A3 A3 A2 bA3 A3 A2Z  bA3 A2 A1 A3 A3 A2 Z aA1 A3 A3 A2 z bA3 A2 z A1 A3 A3 A2 z azA1 A3 A3 A2 z bA3 A3 A2 zChoose the correct statementa) Conversion to a GNF does not change thelanguage generated.b) Convertion to a GNF does change the languagegeneratedc) The language generated is (a + b)*d) The language generated is the empty set
  15. 15. GN-PDA1-Q8. Choose the wrong statementa) CFLs are closed under union, *, concatenation &INITb) CFLs are closed under homomorphism, inversehomomorphism, substitution and Kleene closurec) If L is a cfl & R a regular set then L  R, L-R & LRare all cflsd) CFLs are closed under intersection, complementand inverse substitutionGN-PDA1-S8. The only ‘nasty’ operation in theabove is inverse substitution.So the answer is (d).GN-PDA1-Q9. Consider the cfg GS  AB CAB  BC ABA aC  aB bThe language generated by G is
  16. 16. a) Empty b) Finite c) infinite d) {}GN-PDA1-S9.Solution:A & C are useful as they generate the terminalstring.S  AB CAB  BC ABA aC  aB bB is a useless non terminal. So eliminate it.S  cAA ac bDraw the graph of the grammar. S C AThere are no loops on the graph so L(G) is finite
  17. 17. GN-PDA1-Q10.Consider the cfg GS  ABA  BC aB  Cc bC aThe language generated by G isa) Empty b) Finite c) Infinite d){ }GN-PDA1-Q10. Solution:A, B, C non terminals generate terminal strengthS  ABA  BC aB  Cc bC aDraw the graph of the grammar s C A BThere are no loops on the graph so L(G) infiniteGN-PDA1-Q11. Consider the cfg GS  ABA  BC aB  Cc b
  18. 18. C aC  ABa) Empty b) finite c) infinite d) {  }11. SolutionGN-PDA1-S11:Non terminals A, B & C generate terminal stringsS  ABA  BC aB  Cc bC aC  ABDraw are graph of the grammar S A B CThe graph contains cycles so L(G) is infinite.
  19. 19. GN-PDA1-Q12. The membership problem forcfg’s isa) decidable b) partially solvablec) undecidable d) None of the aboveGN-PDA1-S12. Solution:1. We can consider the CYK algorithm formembership problem of cfl’s2. We can consider Floyd’s backtracking algorithmfor parsing to determine membership in a cfl.GN-PDA-Q13. Choose the cfla) L = {an bn cn/n  1}b) L = {ww / w  (a+b)*}c) L = {ai bj/j=i2}d) L = {ap/ p is prime}
  20. 20. e) L = {ai bj ch dl / i, j, h, l  100}GN-PDA1-S13: The answer is (d) as there is norelatonship or dependence on the number oa a’s,b’s,c’c or d’s.

×