Upcoming SlideShare
×

# Push down automata gate type question bank i

1,061 views

Published on

archived theory of computation question bank ecil 2000-2005

Published in: Entertainment & Humor
2 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

Views
Total views
1,061
On SlideShare
0
From Embeds
0
Number of Embeds
62
Actions
Shares
0
0
0
Likes
2
Embeds 0
No embeds

No notes for slide

### Push down automata gate type question bank i

1. 1. CONTEXT FREE LANGUAGES(CFLS) & PUSH DOWN AUTOMATA(PDA) – IGN-PDA1-Q1. Consider the cfg’sG1: S → ∈ 0S11S 0 SSG2: S → A B A → 0 0 A 1AA A1A AA1 B → 11B 0 BB B0 B BBCG3: S → aSb abG4: S → aSa bSb a b ∈G5: S → SS ( S ) ( )G6: E → E + E / E.E / E* ( E ) a b ∈ ϕG7: S → aA1B aBA1 bA2 A1 → a aS bA2 A1 A2 → aA1 bA2 A2 B → aA1BB aBA1B b bSG8: S → aS aChoose the false statement a) L(G1) generates an equal number of 0’s & 1’s b) L(G2) generates an unequal number of 0’s & 1’s Naresh i Technologies, Opp. Satyam Theatre, Ameerpet, Hyderabad, Ph: 23746666, 9000994008 1
2. 2. c) L(G3) generates L = {an bn/n ≥ 1} d) L(G4) generates all palindrome e) L(G5) generates all the well balanced parenthesis f) L(G6) generates the set of well formed regularexpressions g) L(G7) generates the set of all strings in {a, b}+ withfree as many a’s and b’s h) 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 as S → aAS/a → aSSS/a → aaaa/a So S → a4GN-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; bus ridesgiven by b’s & car rides c. He can make any number ofauto, bus or car nodes. The order is auto nodes first, busnodes next and car nodes last. He must either make an Naresh i Technologies, Opp. Satyam Theatre, Ameerpet, Hyderabad, Ph: 23746666, 9000994008 2
3. 3. unequal number of auto & bus nodes or an unequal numberof bus & car nodes. So to make an unequal number of auto & bus nodes hemakes an equal number of auto & bus nodes and addssome 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 & auto nodes.Z0 make an unequal number of bus & car nodes, Ashokmakes an equal number of bus & car nodes and adds someauto nodes or bus nodes.Y → bYc bc , gives an equal no. of bus & car nodes.S 2 → Yc AYC BY ABY , given an unequal or no. of bus & car nodesS → A B C AC BC ABThis gives all other unequal no. of auto and bus nodesChoose the wrong statement a) S generates {ai bj cl/ i ≠ j as in the grammer above or 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 Naresh i Technologies, Opp. Satyam Theatre, Ameerpet, Hyderabad, Ph: 23746666, 9000994008 3
4. 4. b) is an ambiguous grammar where any sentence hastwo 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 the emptystring has an infinite number of derivations.GN-PDAQ1-Q4. Consider the grammarG: S → aAS / a A → sbA / SS / baChoose the correct statements a) L(G) =empty set b) L(G) = ( a + b)* c) aabbaa is generated by the grammar d) aaaa is not in L(G)GN-PDAS1-Q4: From rule Sa by eliminaton (a) canbe ruled out.Consider S->aAS->aSSS->aaaa.So (d) is the answer.As the empty string is not generated we can rule outchoice(b). Naresh i Technologies, Opp. Satyam Theatre, Ameerpet, Hyderabad, Ph: 23746666, 9000994008 4
5. 5. GN-PDA1-Q5. Eliminating ∈ from the cfg G obtain thegrammar G1I. G: S → Xa X → aX bX ∈The resulting grammar isG1: S → Xa ∈ X → aX a bX bII. G1: S → XY X → 2b Y → bw z → AB w→z A → aA/bA/ ∈ B → Ba/Bb/∈ G1 : S → XY 1 X → zb Y → bw z→ ∈ W→z A → aA bA a b B → Ba Ba Bb a bNext iterationS → XYX → 2bY → bwZ→ ∈W→ ∈A → aA bA a bB → Ba Bb a bNext iteration Naresh i Technologies, Opp. Satyam Theatre, Ameerpet, Hyderabad, Ph: 23746666, 9000994008 5
6. 6. S → 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 bG1 : A & C can generate terminal symbols. 11S → 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 generate 1111terminalS → 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, Naresh i Technologies, Opp. Satyam Theatre, Ameerpet, Hyderabad, Ph: 23746666, 9000994008 6
7. 7. 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 bbB → 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 1 A→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 iteration Naresh i Technologies, Opp. Satyam Theatre, Ameerpet, Hyderabad, Ph: 23746666, 9000994008 7
8. 8. S → ABA→aB→ a bChoose the correct statement a) The reduced grammar generate the same language b) The reduced grammar may not generate the samelanguage c) If we remove unit productions from a cfs the languagegeneration is different d) 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→bIterationS → XS x YS y a bSx → SXSy → SY Naresh i Technologies, Opp. Satyam Theatre, Ameerpet, Hyderabad, Ph: 23746666, 9000994008 8
9. 9. III 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 statement a) G as modified above is in the Chomsky normal form b) G as modified above is the Giebach normal form c) G as modified above changes the language generated d) None of the aboveGN-PDA1-Q6. Consider productionsA → Aα1 Aα 2 − − Aα rA → β1 β 2 − − β5 a) We can remove the left recursion by replacing theabove rule by A → β1 β 2 − − β5 β1Z − − β5 Z Z→ α1 − − α r α1Z − − α r Z Naresh i Technologies, Opp. Satyam Theatre, Ameerpet, Hyderabad, Ph: 23746666, 9000994008 9
10. 10. b) We cannot remove left recursion from a cfg c) Left recursion cannot be removed from a cfg d) None of the aboveGN-PDA1-S6. Choice (b) is wrong if we consider thegrammar, SSa|a which can be rewritten as SaS|a.Choice (c ) can be eliminated as we have the SS,Sa.Choice (a) is the standard theorem.So the answer is (a).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 greater thansymbol 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 b Naresh i Technologies, Opp. Satyam Theatre, Ameerpet, Hyderabad, Ph: 23746666, 9000994008 10
11. 11. A3 → 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 aZZ → 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 statement a) Conversion to a GNF does not change the languagegenerated. b) Convertion to a GNF does change the languagegenerated c) The language generated is (a + b)* d) The language generated is the empty set Naresh i Technologies, Opp. Satyam Theatre, Ameerpet, Hyderabad, Ph: 23746666, 9000994008 11
12. 12. GN-PDA1-Q8. Choose the wrong statement a) CFLs are closed under union, *, concatenation & INIT b) CFLs are closed under homomorphism, inversehomomorphism, substitution and Kleene closure c) If L is a cfl & R a regular set then L ∩ R, L-R & LR are allcfls d) CFLs are closed under intersection, complement andinverse substitutionGN-PDA1-S8. The only ‘nasty’ operation in the aboveis 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 a) Empty b) Finite c) infinite d){∈ }GN-PDA1-S9.Solution:A & C are useful as they generate the terminal string.S → AB CAB → BC AB Naresh i Technologies, Opp. Satyam Theatre, Ameerpet, Hyderabad, Ph: 23746666, 9000994008 12
13. 13. A→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 finiteGN-PDA1-Q10. Consider the cfg G S → AB A → BC a B → Cc b C→aThe language generated by G is a) Empty b) Finite c) Infinite d){∈ }GN-PDA1-Q10. Solution:A, B, C non terminals generate terminal strength S → AB A → BC a B → Cc b Naresh i Technologies, Opp. Satyam Theatre, Ameerpet, Hyderabad, Ph: 23746666, 9000994008 13
14. 14. C→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 G S → AB A → BC a B → Cc b C→a C → AB a) Empty b) finite c) infinite d) {∈ }11. SolutionGN-PDA1-S11:Non terminals A, B & C generate terminal strings S → AB A → BC a B → Cc b C→a C → ABDraw are graph of the grammar Naresh i Technologies, Opp. Satyam Theatre, Ameerpet, Hyderabad, Ph: 23746666, 9000994008 14
15. 15. S A B CThe graph contains cycles so L(G) is infinite.GN-PDA1-Q12. The membership problem for cfg’s is a) decidable b) partially solvable c) undecidable d) None of the aboveGN-PDA1-S12. Solution:1. We can consider the CYK algorithm for membershipproblem of cfl’s2. We can consider Floyd’s backtracking algorithm forparsing to determine membership in a cfl. Naresh i Technologies, Opp. Satyam Theatre, Ameerpet, Hyderabad, Ph: 23746666, 9000994008 15
16. 16. GN-PDA-Q13. Choose the cfl a) L = {an bn cn/n ≥ 1} b) L = {ww / w ∈ (a+b)*} c) L = {ai bj/j=i2} d) L = {ap/ p is prime} e) L = {ai bj ch dl / i, j, h, l ≥ 100}GN-PDA1-S13: The answer is (d) as there is no relatonshipor dependence on the number oa a’s, b’s,c’c or d’s. Naresh i Technologies, Opp. Satyam Theatre, Ameerpet, Hyderabad, Ph: 23746666, 9000994008 16
17. 17. Naresh i Technologies, Opp. Satyam Theatre, Ameerpet, Hyderabad, Ph: 23746666, 9000994008 17