Ce diaporama a bien été signalé.
Le téléchargement de votre SlideShare est en cours. ×

UNIT III.docx

Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Prochain SlideShare
QB104543.pdf
Chargement dans…3
×

Consultez-les par la suite

1 sur 35 Publicité

UNIT III.docx

Ques and Answer UNIT 3 TOC

Ques and Answer UNIT 3 TOC

Publicité
Publicité

Plus De Contenu Connexe

Publicité

UNIT III.docx

1. 1. 1 SYLLABUS CS6503 THEORY OF COMPUTATION L T P C 3 0 0 3 UNIT III PUSHDOWN AUTOMATA 9 Pushdown Automata- Definitions – Moves – Instantaneous descriptions – Deterministic pushdown automata – Equivalence of Pushdown automata and CFL - pumping lemma for CFL – problems based on pumping Lemma. LIST OF IMPORTANT TWO MARK QUESTIONS PART A 1. Differentiate PDA accepted by empty stack method with acceptance by the final state method. (April/May2017,2015) 2. When is pushdown automata (PDA) said to be deterministic? (April/May2017)(Nov/Dec2016) 3. What are the conventional notations of pushdown automata? (or) Define pushdown automaton. (Nov/Dec,May/June2016) 4. Does a pushdown automaton have memory? Justify. (May/June 2016) 5. What are the different ways of language acceptances by a PDA and define them? (Nov/Dec2015) 6. Convert the following CFG to a PDA. S  aAA, A  aS |bS |a. (Nov/Dec2015) 7. Define pumping lemma for CFL. (April/May2015,2014) 8. Compare NFA and PDA. (Nov/Dec 2013) 9. What are the closure properties of CFL? (Nov/Dec,May/June 2013) LIST OF IMPORTANT SIXTEEN MARK QUESTIONS PART B 1. (i). Construct a DPDA for even length palindrome. (Or) Construct PDA for the language L = {wwR |w in (a +b)*}. (Or) Construct a pushdown automaton to accept the following language L on ∑ = {a, b} by empty stack. L = {wwR | w ∈ ∑+}. (April/May2017,2016,2013)
2. 2. 2 (ii). Prove If PDA P is constructed from CFG G by the above construction, then N(P) = L(G). (Or) If L is context free language prove that there exists a PDA M, such that L = N(M). (Or) Prove the equivalence of PDA and CFL. (Or) Explain in detail about equivalence of pushdown automata and CFG. (Or) With an example, explain the procedure to obtain a PDA from the given CFG. (Or) Construct a PDA for the given grammar S  aSa | bSb | c. (April/May2017,2015,2013,Nov/Dec2016,2014,2013) 2. Convert the following CFG to PDA and verify for (a + b) and a++ I  a | b | Ia | Ib | I0 | I1 E  I | E + E | E * E | (E). (April/May2017) 3. (i). Outline an instantaneous description of a PDA. (or) What is an Instantaneous description of a PDA? How will you represent it? Also give the three important principles of ID and their transactions. (Or) Design a PDA to accept {0n 1n | n>1}. Draw the transition diagram for the PDA. Show by instantaneous description that the PDA accepts the string ‘0011’. (Or) Construct a pushdown automata to accept the language L = {an bn | n >1} by empty stack and by final state. (Nov/Dec2016,2015,May/June 2016,2014) (ii). State and explain the pumping lemma for CFG. (Or) Explain in detail about Pumping lemma for CFL (Nov/Dec2016,May/June2013) 4. (i). Explain acceptance by final state and acceptance by empty stack of a pushdown automata. (May/June 2016) (ii). State pumping lemma for CFL. Use pumping lemma to show that the language L = { ai bj ck | i < j < k} is not a CFL. (May/June 2016) 5. Show that the language L = {an bn cn | n >=1} (or) L = {0n 1n 2n | n > 1} (or) L = { ai bi ci | i > 1}is not a CFL. (Nov/Dec 2015,2014,May/June2014) 6. (i). Convert PDA to CFG. PDA is given by P = ({p, q}, {0, 1}, {X, Z}, δ, q, Z), δ is defined by δ(p, 1, Z) = {(p, XZ)}, δ(p, ε, Z) = {(p, ε), δ(p, 1, X) = {(p, XX)}, δ(q, 1, X) = {(q, ε )}, δ(p, 0, X) = {(q, X)}, δ(q, 0 ,Z) = {(p, Z)}. (Nov/Dec2015) (ii). What are deterministic PDA’s? Give example for Non-deterministic and deterministic PDA. (Nov/Dec2015)
3. 3. 3 7. Construct PDA for the language L = {x ∈ {a, b}* | na (x) > nb (x)}. (April/May2015) 8. Prove that If L is N(M1) (the language accepted by empty stack) for some PDA M1, then L is N(M2) (the language accepted by final state) for some PDA M2. (Nov/Dec2014) 9. Let M = ({q0, q1}, {0, 1}, {x, z0}, δ, q0, z0, Φ) where is given by δ (q0,0, z0 ) = {(q0,x z0)} δ (q1,1,x) = {(q1, ε)} δ (q0,0,x) = {(q0,xx)} δ (q1, ε,x) = {(q1, ε)} δ (q0,1,x) = {(q1, ε)} δ (q1, ε, z0 ) = {(q1, ε)} Construct a CFG for the PDAM. (May/June2014) 10.Convert the grammar S  0S1 / A; A  1A0 / S / ε into PDA that accepts the same language by empty stack. Check whether 0101 belongs to N(M). (May/June2014) 11.Give formal pushdown automata that accepts {wcwR | w in (0 +1)*} by empty stack. (Nov/Dec2013) 12.Explain in detail about the closure properties of CFL. (May/June2013)
4. 4. 4 IMPORTANT QUESTIONS AND ANSWERS PART A 1. Differentiate PDA accepted by empty stack method with acceptance by the final state method. (April/May2017,2015) Let P = (Q, ∑, Γ, δ, q0, z0, F) PDA ACCEPTED BY FINAL STATE: The PDA accepts the input by consuming it and entering into an accepting state or final state. Let P be a PDA, then L(P) be the language accepted by a final state. L(P) = {w/ (q0, w, z0) ⊢* (q, ε, γ)} Where w - The input string q0 - The initial state q - The final state After consuming w, it enters into q state and empties the input. The content of the stack is irrelevant. PDA ACCEPTED BY EMPTY STACK: It is the set of strings that empties its stack starting from the initial ID in PDA. Let P be PDA, then the language accepted by empty stack is L(P). N(P) = {w/ (q0, w, z0) ⊢* (q, ε, ε,)} Where w - The input string q0 - The initial state q - The final state PDA P will consume all the inputs of w and at the same time the stack will be empty. The accepting states are irrelevant. 2. When is pushdown automata (PDA) said to be deterministic?( April/May2017) (Nov/Dec2016) PDA SAID TO BE DETERMINISTIC: A PDA P = (Q, ∑, Γ, δ, q0, z0, F) is deterministic if and only if it satisfies the following conditions. 1. δ(q, a, x) has only one member for any q in Q, a in ∑ or a = ε and x in Γ.
5. 5. 5 2. If δ(q, a, x) is nonempty, for some a in ∑, then δ(q, ε, x) must be empty 3. What are the conventional notations of pushdown automata? (or) Define pushdown automaton. (Nov/Dec,May/June2016) PDA: A pushdown automaton consist of 7 tuples. P = (Q, ∑, Γ, δ, q0, z0, F) Where Q – A finite non-empty set of states ∑ - A finite set of input symbols Γ – A finite non-empty set of stack symbols δ – The transition Function (Q x (∑ ∪ {ε}) x Γ  Q x Γ* q0 - The start state (q0 ∈ Q) z0 – Initial start symbol of the stack F – Set of accepting states or Final states (F ⊆ Q) 4. Does a pushdown automata has memory? Justify. (May/June 2016) Yes, Pushdown automata have memory by means of having an external stack. With the help of the stack, the PDA can remember an infinite amount of information. 5. What are the different ways of language acceptances by a PDA and define them? (Nov/Dec2015) TWO WAYS OF LANGUAGE ACCEPTED BY PDA: 1. Accepted by Final State 2. Accepted by Empty stack ACCEPTED BY FINAL STATE: Let M = (Q, ∑, Γ, δ, q0, z0, F) be a PDA, then the language accepted by a final state is L(M) = { w | (q0, w, z0) ) ⊢* (p, ε, γ) for some P in F and γ in Γ *} ACCEPTED BY EMPTY STACK: Let M = (Q, ∑, Γ, δ, q0, z0, F) be a PDA, then the language accepted by a empty stack is N(M) = { w | (q0, w, z0) ) ⊢* (p, ε, ε) for some P in Q}
6. 6. 6 6. Convert the following CFG to a PDA. S  aAA, A  aS |bS |a. (Nov/Dec2015) SOLUTION: The PDA is given by P = ({q}, {a, b}, {S, A, a, b}, δ, q, S) Where δ is defined by δ (q, ε, S) = {(q, aAA)} δ (q, ε, A) = {(q, aS), (q, bS), (q, a)} δ (q, a, a) = {(q, ε)} δ (q, b, b) = {(q, ε)} 7. Define pumping lemma for CFL. (April/May2015,2014) PUMPING LEMMA FOR CFL: Let L be any CFL, then there exists a constant n, depending only on L such that if z is in L and |z| > n, then z = uvwxy such that (i) |vx| > 1 (ii) |vwx| < n (iii) for all i > 0, uvi wxi y ∈ L 8. Compare NFA and PDA. (Nov/Dec 2013) S.NO NFA PDA 1 NFA consist of finite set of states, a finite set of input symbols with one start state and a set of accepting states. The PDA consists of a finite set of states, a finite set of input symbols and a finite set of pushdown symbols. 2 Finite Automata without stack Finite Automata with stack
7. 7. 7 3 M = (Q, Σ, δ, q0, F) where, Q - Finite set of states Σ - Finite set of input alphabets δ - Transition function Q X Σ  Q q0 -Initial state q0 ∈ Q F- Set of final or accepting states. F ⊆ Q P = (Q, ∑, Γ, δ, q0, z0, F) Where, Q – Finite non-empty set of states ∑ - Finite set of input symbols Γ – A finite non-empty set of stack symbols δ – Transition Function (Q x (∑ ∪ {ε}) x Γ  Q x Γ* q0 - Start state q0 ∈ Q z0 – Initial start symbol of the stack F – Set of accepting states or Final states F ⊆ Q 9. What are the closure properties of CFL? (Nov/Dec,May/June 2013) CLOSURE PROPERTIES OF CFL: 1. Substitution 2. Application of Substitution a. Union b. Concatenation c. Closure(*) and Positive closure(+) d. Homomorphism 3. Reversal 4. Intersection with a Regular Language 5. Inverse Homomorphism
8. 8. 8 IMPORTANT SIXTEEN MARK QUESTIONS AND ANSWERs PART B 1. (i). Construct a DPDA for even length palindrome. (Or) Construct PDA for the language L = {wwR |w in (a +b)*}. (Or) Construct a pushdown automaton to accept the following language L on ∑ = {a, b} by empty stack. L = {wwR | w ∈ ∑+}. (April/May2017,2016,2013) SOLUTION: The Language L = {wwR |w in (a +b)*} refer as “w-w-reverse” is the even length palindrome over alphabet {a, b}. 1. In state q0 read the input symbols and store them on stack by push 2. Assume that if w is seen at the middle or end position then change the state to q1. 3. In state q1 compare the input symbol with the top of the stack. If they match, the input string is consumed and pops the stack. Else w is not followed by wR and it is not a palindrome. 4. If stack is empty then w is followed by wR and the input is accepted. PDA: PRODUCTION: Where δ is defined by, δ (q0,0, z0 ) = {(q0, 0 z0)} δ (q0,1, z0 ) = {(q0, 1 z0)} δ (q0,0, 0 ) = {(q0, 00)} δ (q0,1, 0 ) = {(q0, 10)} Push δ (q0,0, 1 ) = {(q0, 01)} δ (q0,1, 1 ) = {(q0, 11)} δ (q0, ε, 1 ) = {(q1, 1)} New State δ (q0, ε, 0 ) = {(q1, 0)} δ (q0, ε, z0 ) = {(q1, z0)}
9. 9. 9 δ (q1,0, 0 ) = {(q1, ε)} δ (q1,1, 1 ) = {(q1, ε)} POP δ (q1, ε, z0 ) = {(q2, z0)} Accept by Final State δ (q1, z0, ε ) = {(q2, ε)} Accept by Empty Stack TRANSITION DIAGRAM(ACCEPT BY FINAL STATE): TRANSITION DIAGRAM(ACCEPT BY EMPTY STACK): 0, z0/0z0 1, z0/1z0 0,0/00 1,1/11 1,0/10 0,1/01 0,0/ ε ε, z0/z0 1,1/ ε ε,0/0 ε,1/1 ε, z0/ ε q0 q1 q2
10. 10. 10 (ii). Prove If PDA P is constructed from CFG G by the above construction, then N(P) = L(G). (or) If L is context free language prove that there exists a PDA M, such that L = N(M). (or) Prove the equivalence of PDA and CFL. (or) Explain in detail about equivalence of pushdown automata and CFG. (Or) With an example, explain the procedure to obtain a PDA from the given CFG. (Or) Construct a PDA for the given grammar S  aSa | bSb | c. (April/May2017,2015,2013,Nov/Dec2016,2014,2013) CFG TO PDA: Let G = (V, T, Q, S) be a CFG. Construct the PDA P that accepts L(G) by empty stack as follows. P = ({q}, T, V ∪ T, δ, q, S} Where δ is defined by 1. For each variable A, δ(q, ε, A) = {(q, β) | A  β is a production in G} 2. For every terminal symbol a, δ(q, a, a) = {(q, ε )} STATEMENT: If PDA P is constructed from CFG G, then N(P) = L(G) TO PROVE: w is in N(P) if and only-if w is in L(G) i.e., N(P) = L(G) [q X p] ⇒* w if and only if (q, w, X) ⊢* (p, ε, ε) IF PART: If (q, w, X) ⊢* (p, ε, ε), then to show [q X p] ⇒* w BASIS: (p, ε) in (q, ε, X) and w = ε , then by construction of G, [q X p]  w is a production, so [q X p] ⇒ w INDUCTION HYPOTHESIS: Suppose the sequence (q, w, X) ⊢* (p, ε, ε) takes n steps and n>1, then first move is (q, w, X) ⊢ (r0, x, Y1 Y2 ... Yk) ⊢* (p, ε, ε) and w = ax The pair (r0, x, Y1 Y2 ... Yk) must be in (q, a, X) By construction of G, there is a production [q X rk]  a[r0Y1 r1] [r1Y2 r2]... [rk-1Yk rk] Where rk = p and r1, r2, ..rk-1 are any states in Q
11. 11. 11 Choose pi be the state of PDA IF Yi is popped out i = 1, 2,.. k-1. Let x = w1 w2 ...wk, where wi = Input consumed while Yi is popped off from the stack Where rk = p. ONLY IF PART: Induction on number pf steps in derivation BASIS: [q X p]  w is a production if there is a transition of P in which X is popped and state q changes to state p. (p, ε) in (q, a, X) and w = a, then (q, w, X) ⊢(p, ε, ε) INDUCTION HYPOTHESIS: Assume for all i, (ri-1, wi ,Yi) ⊢* (ri, ε, ε) is true INDUCTION: Suppose [q X p] ⇒* w takes n steps and n>1, then first sentential form is Where rk = p. Since (r0, Y1 Y2 ... Yk) in δ(q, a, X) w = a w1 w2 ...wk such that [ri-1Yi ri] ⇒* wi for all i = 1, 2,.. k. By inductive hypothesis, for all i, (ri-1, wi ,Yi) ⊢* (ri, ε, ε) String beyond wi on the input and below Yi on the stack,
12. 12. 12 For all sequences together Since rk = p, (q, w, X) ⊢* (p, ε, ε) [q X p] ⇒* w if and only if (q, w, X) ⊢* (p, ε, ε) Thus N(P) = L(G). Hence Proved. EXAMPLE: Grammar S  aSa | bSb | c PDA: P = ({q}, {a, b, c}, {S, a, b, c}, δ, q, S) PRODUCTION: Where δ is defined by δ (q, ε, S) = {(q, aSa), (q, bSb), (q, c)} δ (q, a, a) = {(q, ε)} δ (q, b, b) = {(q, ε)} δ (q, c, c) = {(q, ε)} 2. Convert the following CFG to PDA and verify for (a + b) and a++ I  a | b | Ia | Ib | I0 | I1 E  I | E + E | E * E | (E). (April/May2017) SOLUTION: PDA: P = ({q}, {a, b, 0, 1, +, *, (,)}, {E, I, a, b, 0, 1, +, *, (,) }, δ, q, I) PRODUCTION: Where δ is defined by δ (q, ε, I) = {(q, a), (q, b), (q, Ia), (q, Ib), (q, I0), (q, I1)} δ (q, ε, E) = {(q, I), (q, E + E), (q, E * E), (q, (E)} δ (q, a, a) = {(q, ε)} δ (q, b, b) = {(q, ε)}
13. 13. 13 δ (q, 0, 0) = {(q, ε)} δ (q, 1, 1) = {(q, ε)} δ (q, +, +) = {(q, ε)} δ (q, *, *) = {(q, ε)} δ (q, (, () = {(q, ε)} δ (q, ), )) = {(q, ε)} CHECK STRING: (a + b) and a++ (q, (a + b), E) ⊢ (q, (a + b), (E)) ⊢ (q, a + b, E + E) ⊢ (q, a + b, I + E) ⊢ (q, a + b, a + E) ⊢ (q, b, I) ⊢ (q, b, b) ⊢ (q, ε, ε) Therefore the String (a + b) is accepted by the above PDA. (q, a++, E) ⊢ (q, a++, E) ⊢ (q, a++, E + E) ⊢ (q, a++, I + E) ⊢ (q, a++, a + E) ⊢ (q, +, E) Therefore the String a++ is not accepted by the above PDA. 3. (i). Outline an instantaneous description of a PDA. (or) What is an Instantaneous description of a PDA? How will you represent it? Also give the three important principles of ID and their transactions. (Or) Design a PDA to accept {0n 1n | n>1}. Draw the transition diagram for the PDA. Show by instantaneous description that the PDA accepts the string ‘0011’. (Or) Construct a pushdown automata to accept the language L = {an bn | n >1} by empty stack and by final state. (Nov/Dec2016,2015,May/June 2016,2014) INSTANTANEOUS DESCRIPTION OF A PDA: The configuration of PDA is represented by triple (q, w, γ) Where q = state w = remaining input γ = stack contents Such a triple is called as instantaneous description or ID of a PDA.
14. 14. 14 Let P = (Q, ∑, Γ, δ, q0, z0, F) be a PDA. Then (q, aw, x β) ⊢ (p,w, α β) if (q, a, x) = (p, α ) This move reflects the idea that, by consuming α from the input and replacing x on top of the stack by α, the state changes from q to state p. The symbol used is ⊢* 3 IMPORTANT PRINCIPLES: EXAMPLE: L = {0n 1n | n>1} (Or) L = {an bn | n >1} 0 = a; 1 = b. PDA: P = ({q0, q1, q2}, {0, 1 }, { 0, 1, z0}, δ, { q0}, { q2}) PRODUCTION: δ is given by δ (q0,0, z0 ) = {(q0, 0 z0)} δ (q0,0, 0 ) = {(q0, 00)} δ (q0,1, 0 ) = {(q1, ε)} δ (q1,1, 0 ) = {(q1, ε)} δ (q1, ε, z0 ) = {(q2, ε)} Accepted by Empty Stack (Or) δ (q1, ε, z0 ) = {(q2, z0)} Accepted by Finite State
15. 15. 15 TRANSITION DIAGRAM (EMPTY STACK): 0, z0/ 0z0 0,0/ 00 1,0 / ε 1,0 / ε ε, z0/ ε TRANSITION DIAGRAM (FINITE AUTOMATA): 0, z0/ 0z0 0,0/ 00 1,0 / ε 1,0 / ε ε, z0/ z0 CHECK STRING: 0011(ID FOR STRING 0011): (q0, 0011, z0) ⊢ (q0, 011, 0z0) ⊢ (q0, 11, 00z0) ⊢ (q1, 1, 0z0) ⊢ (q1, ε, z0) ⊢ (q2, ε, ε) Hence the string 0011 is accepted by the above PDA (ii). State and explain the pumping lemma for CFG. (Or) Explain in detail about Pumping lemma for CFL (Nov/Dec2016,May/June2013) PUMPING LEMMA FOR CFL: Let L be any CFL, then there exists a constant n, depending only on L such that if z is in L and |z| > n, then z = uvwxy such that (i) |vx| > 1 (ii) |vwx| < n (iii) for all i > 0, uvi wxi y ∈ L PROOF: The first step is to find a Chomsky normal form grammar G for L. q0 q1 q2 q0 q1 q2
16. 16. 16 Let G = (V, T, P,S) such that L(G) = L – { ε }. There are M variables in G. Choose n = 2M. Suppose z in L is of length at least n. By theorem, any parse tree whose longest path is of length M or less must have a yield of length 2M-1 = n/2 or less. Such a parse tree cannot have yield z, because z is too long. Thus any parse tree with yield z has a path of length atleast M+1. But such a path has at least M + 2 vertices. Thus there must be two vertices v1 and v2 on the path. It is possible to divide the tree, string w is yield of the subtree whose root is Aj. For the yield w, at Aj string v and x are the strings to the left and right. There will be no unit productions in the grammar, so v and x could not both be ε, but one could be. Then at Ai, strings u and y are to its left and right.
17. 17. 17 Suppose Ai = Aj = A construct a new parse tree Fig (a) replacing the root Ai and Aj by A, which has yield w. The resultant tree is given in Fig (b), which has yield uwy and corresponds to the case i = 0 in the pattern of strings uvi wxi y.
18. 18. 18 Suppose Aj is replaced by the subtree Ai. The yield of this tree is uv2 wx2 y. Likewise we can expand the tree for any number of times. Thus there are parse trees in G for all strings of the form uvi wxi y. Then |vwx|<n, for this choose Ai to be bottom of the tree i.e., k-i < M. Thus the longest path in the subtree rooted at Ai is no greater than M + 1. Accordig to thye theorem, the subtree rooted at Ai has a yield whose length is not greater than 2M = n. Thus the lemma is proved. 4. (i). Explain acceptance by final state and acceptance by empty stack of a pushdown automata. (May/June 2016) ACCEPTED BY FINAL STATE: Let M = (Q, ∑, Γ, δ, q0, z0, F) be a PDA, then the language accepted by a final state is L(M) = { w | (q0, w, z0) ) ⊢* (p, ε, γ) for some P in F and γ in Γ *} Where w - The input string q0 - The initial state q - The final state After consuming w, it enters into q state and empties the input. The content of the stack is irrelevant. EXAMPLE: L = {wwR |w in (a +b)*} PRODUCTION: Where δ is defined by, δ (q0,0, z0 ) = {(q0, 0 z0)} δ (q0,1, z0 ) = {(q0, 1 z0)} δ (q0,0, 0 ) = {(q0, 00)} δ (q0,1, 0 ) = {(q0, 10)} Push δ (q0,0, 1 ) = {(q0, 01)} δ (q0,1, 1 ) = {(q0, 11)} δ (q0, ε, 1 ) = {(q1, 1)} New State δ (q0, ε, 0 ) = {(q1, 0)} δ (q0, ε, z0 ) = {(q1, z0)}
19. 19. 19 δ (q1,0, 0 ) = {(q1, ε)} δ (q1,1, 1 ) = {(q1, ε)} POP δ (q1, ε, z0 ) = {(q2, z0)} Accept by Final State TRANSITION DIAGRAM(ACCEPT BY FINAL STATE): ACCEPTED BY EMPTY STACK: Let M = (Q, ∑, Γ, δ, q0, z0, F) be a PDA, then the language accepted by a empty stack is N(M) = { w | (q0, w, z0) ) ⊢* (p, ε, ε) for some P in Q} Where w - The input string q0 - The initial state q - The final state PDA P will consume all the inputs of w and at the same time the stack will be empty. The accepting states are irrelevant. EXAMPLE: L = {wcwR | w in (0 +1)*}
20. 20. 20 PDA: P = ({q0, q1, q2}, {0, 1, c}, { 0, 1, c, z0}, δ, { q0}, { q2}) PRODUCTION: Where δ is given by δ (q0,0, z0 ) = {(q0, 0 z0)} δ (q0,1, z0 ) = {(q0, 1 z0)} δ (q0,0, 0 ) = {(q0, 00)} δ (q0,1, 0 ) = {(q0, 10)} Push δ (q0,0, 1 ) = {(q0, 01)} δ (q0,1, 1 ) = {(q0, 11)} δ (q0,c, 1 ) = {(q1, 1)} Accept the separator c δ (q0,c, 0 ) = {(q1, 0)} δ (q1,0, 0 ) = {(q1, ε)} δ (q1,1, 1 ) = {(q1, ε)} POP δ (q1, ε, z0 ) = {(q2, ε)} TRANSITION DIAGRAM: 0, z0/ 0z0 1, z0/ 1z0 0,0/00 1,1/11 1,0/10 0,1/01 0,0/ ε 1,1/ ε c,0/0 c,1/1 ε, z0/ ε (ii). State pumping lemma for CFL. Use pumping lemma to show that the language L = { ai bj ck | i < j < k} is not a CFL. (May/June 2016) PUMPING LEMMA FOR CFL: Let L be any CFL, then there exists a constant n, depending only on L such that if z is in L and |z| > n, then z = uvwxy such that (i) |vx| > 1 q0 q1 q2
21. 21. 21 (ii) |vwx| < n (iii) for all i > 0, uvi wxi y ∈ L SOLUTION: L = { ai bj ck | i < j < k} (i) Assume L is context free Take z = an bn+1 cn+1 and |z|>=n (ii) Define z = uvxy such that |vwz|<n, |vx|>=1 (iii) Possible combinations of uvwxy where vwx is a. ap for some p<=n, p>=1 b. ap bq for some p+q <= n, p+q >= 1 c. bp for some p<= n, p>=1 d. bp cq for sme p+q <=n, p+q >=1 e. cq for some q<=n, q >= 1 Case a: Take i = 2 uvi wxi y = uv2 wx2 y = |uvwxy|. |vx| = an bn+1 cn+2an-p = a2n-p bn+1 cn+2 ∉ Case e: Take i=0 uvi wxi y = uv0 wx0 y = uwy = an bn+1 cn+2-q Since q <=n, uwy = an bn+1 c2 ∉ L K is less than j Therefore L is not regular. 5. Show that the language L = {an bn cn | n >=1} (or) L = {0n 1n 2n | n > 1} (or) L = { ai bi ci | i > 1}is not a CFL. (Nov/Dec 2015,2014,May/June2014) SOLUTION: (I) Assume L is context-free. By pumping lemma let n be the natural number.
22. 22. 22 (II) Let z = an bn cn . |z| = 3n > n Then z = uvwxy where |vx| > 1 (III) uvwxy = an bn cn As 1 | < | vx | < n, v or x cannot contain all the three symbols a, b, c. So v or x is of the form. Case (i): 1. a’s 2. b’s 3. c’s Case (ii): 4. ai bj for some i, j 5. bi cj for some i, j Case (i): When both v and x are formed by the repetition of a single symbol, For eg: u = ai and v = bj Then uv wx y Let i = 0, z = uv0 wx0 y = uwy = ai (wy) uwy contains at most ai bn-j cn which is not of the form uvi wxi y. uwy ∉ L Likewise for v = ai , ci Case (ii) v or x has ai bj If i = 0, uvi wxi y = uwy uwy contains atmost an-i bn cn which is not of the form uvi wxi y ∉ L.
23. 23. 23 Like so for bj cj Therefore L is not context – free. 6. (i). Convert PDA to CFG. PDA is given by P = ({p, q}, {0, 1}, {X, Z}, δ, q, Z), δ is defined by δ(p, 1, Z) = {(p, XZ)} δ(p, ε, Z) = {(p, ε) δ(p, 1, X) = {(p, XX)} δ(q, 1, X) = {(q, ε )} δ(p, 0, X) = {(q, X)} δ(q, 0 ,Z) = {(p, Z)}. (Nov/Dec2015) SOLUTION: The variables involved in the grammar are V = {S, [p, X, p], [p, X, q], [q, X, p], [q, X, q], [p, Z, p], [p, Z, q], [q, Z, p], [q, Z, q] PRODUCTION: S  [p, Z, p] S  [p, Z, q] δ(p, 1, Z) = {(p, XZ)} [p, Z, p]  1[p, X, p][p, Z, p] | 1[p, X, q][p, Z, p] [p, Z, q]  1 [p, X, p][p, Z, q] | 1[p, X, q][p, Z, q] δ(p, 1, X) = {(p, XX)} [p, X, p]  1[p, X, p][p, X, p] | 1[p, X, q][q, X, p] [p, X, q]  1[p, X, p][p, X, q] | 1[p, X, q][q, X, q] δ(p, 0, X) = {(q, X)} [p, X, p]  0[q, X, p] [p, X, q]  0[q, X, q] δ(p, ε, Z) = {(p, ε) [p, Z, p]  ε δ(q, 1, X) = {(q, ε )} [q, X, q] 1 δ(q, 0 ,Z) = {(p, Z)}
24. 24. 24 [q, Z, p] 0[p, Z, p] [q, Z, q]  0[p, Z, q] After eliminating the unwanted variables, The CFG is given by: S  [p, Z, p] [p, Z, p]  {1[p, X, q][q, Z, p], ε } [p, X, q]  {1[p, X, q][q, X, q], 0[q, X, q]} [q, X, q] 1 [q, X, p]  0[p, Z, p]  S  [p, Z, p] [p, Z, p]  1[p, X, q][q, Z, p] | ε [p, X, q]  1[p, X, q][q, X, q] | 0[q, X, q] [q, X, p]  0[p, Z, p] [q, X, q] 1 (ii). What are deterministic PDA’s? Give example for Non-deterministic and deterministic PDA. (Nov/Dec2015) DETERMINISTIC PDA (DPDA): A PDA P = (Q, ∑, Γ, δ, q0, z0, F) is deterministic if and only if it satisfies the following condition. 1. δ (q, a, x) has only one member for any q in Q, a in ∑or a = ε and x in Γ. 2. If δ (q, a, x) is nonempty, for some a in ∑, then δ (q, ε, x) must be empty. EXAMPLE(DPDA): L = {wcwR | w in (0 +1)*} The PDA for this is designed in such a way that DPDA is to store 0’s and 1’s on it stack until it sees the middle end marker. After this , it goes to another state in which it matches input symbols against stack symbols and pops the stck if they match 0r else rejected. Thus the PDA is strictly deterministic. It does not have a choice of move in the start state using the same input and stack symbol. DPDA: P = ({q0, q1, q2}, {0, 1, c}, { 0, 1, c, z0}, δ, { q0}, { q2})
25. 25. 25 PRODUCTION: δ is given by δ (q0,0, z0 ) = {(q0, 0 z0)} δ (q0,1, z0 ) = {(q0, 1 z0)} δ (q0,0, 0 ) = {(q0, 00)} δ (q0,1, 0 ) = {(q0, 10)} Push δ (q0,0, 1 ) = {(q0, 01)} δ (q0,1, 1 ) = {(q0, 11)} δ (q0,c, z0 ) = {(q1, z0)} δ (q0,c, 1 ) = {(q1, 1)} Accept the separator c δ (q0,c, 0 ) = {(q1, 0)} δ (q1,0, 0 ) = {(q1, ε)} δ (q1,1, 1 ) = {(q1, ε)} POP δ (q1, ε, z0 ) = {(q2, z0)} TRANSITION DIAGRAM: 0, z0/ 0z0 1, z0/ 1z0 0,0/00 1,1/11 1,0/10 0,1/01 0,0/ ε c, z0/z0 1,1/ ε c,0/0 c,1/1 ε, z0/ z0 7. Construct PDA for the language L = {x ∈ {a, b}* | na (x) > nb (x)}. (April/May2015) SOLUTION: PDA: P = ({q0, q1, q2}, {a, b}, {a, b, z0}, δ, { q0}, { q2}) q0 q1 q2
26. 26. 26 PRODUCTION: δ is given by δ (q0,a, z0 ) = {(q1, a z0)} δ (q1,a, a ) = {(q1, aa)} PUSH δ (q1,a, a ) = {(q2, ε)} δ (q2,b, a ) = {(q2, ε)} δ (q2, ε, z0 ) = {(q3, ε)} POP TRANSITION DIAGRAM: b, a/ ε a,a/aa a,a/aa a, z0/ az0 a,a/ ε ε, z0/ z0 8. Prove that If L is N(M1) (the language accepted by empty stack) for some PDA M1, then L is N(M2) (the language accepted by final state) for some PDA M2. (Nov/Dec2014) PROOF: The theorem states that if there is a PDA which has acceptance by empty stack then there should be a PDA which also has acceptance by final state. M1 = (Q, ∑, Γ, δN, q0, z0, F) be a PDA It is planned to have M2 simulates M1 and find when M2 empties its stack. M2 (Q ∪{p0, pf}, ∑, Γ∪{X0}, δ, p0, X0, pf) Where δ is given by 1. δ (p0, ε, X0) = {( q0, z0, X0)} 2. For all q in Q, a in ∑ ∪{ ε } and Z in Γ, δ(q, a z) = δ(q, a, z) 3. For all q in Q, δ(q, ε, X0) contains (pf, ε) q0 q1 q3 q2
27. 27. 27 TO PROVE: w is in N(M2) if and only if w is in N(M1) IF PART: (p0, w, X0) ⊢M2 (q0, w, z0X0) ⊢* (q0, ε, X0) ⊢M2 (pf, ε, ε) Since is at the bottom of the stack, then (p0, w, X0) ⊢* (p, ε, X0) This M2 accepts w by final state. ONLY IF PART: Rule (1) causes M1to enter the initial ID of M2 except that M2 will have its own bottom of stack marker which is the symbol of M2’s stack. It is to prove that (q0, w, z0) ⊢M1* (q, ε, ε) That is w is i N(M1) 9. Let M = ({q0, q1}, {0, 1}, {x, z0}, δ, q0, z0, Φ) where is given by δ (q0,0, z0 ) = {(q0,x z0)} δ (q1,1,x) = {(q1, ε)} δ (q0,0,x) = {(q0,xx)} δ (q1, ε,x) = {(q1, ε)} δ (q0,1,x) = {(q1, ε)}
28. 28. 28 δ (q1, ε, z0 ) = {(q1, ε)} Construct a CFG for the PDAM. (May/June2014) SOLUTION: The variables involved in the grammar are V = {S, [q0, x, q0], [q0, x, q1], [q1, x, q0], [q1, x, q1], [q0, z0, q0], [q0, z0, q1], [q1, z0, q0], [q1, z0, q1]} PRODUCTON: S [q0, z0, q0] S[q0, z0, q1] where q0 = Start State z0 = Initial Stack Symbol δ (q0,0, z0 ) = {(q0,x z0)} For q0 [q0, z0, q0]  0[q0, x, q0] [q0, z0, q0] [q0, z0, q0]  0[q0, x, q1] q1, z0, q0] For q1 [q0, z0, q1] 0[q0, x, q0] [q0, z0, q1] [q0, z0, q1]  0[q0, x, q1] [q0, z0, q1] δ (q0,0,x) = {(q0,xx)} [q0, x, q0]  0[q0, x, q0] [q0, x, q0] | 0[q0, x, q1] [q1, x, q0] [q0, x, q1]  0[q0, x, q0] [q0, x, q1] | 0[q0, x, q1] [q1, x, q1] δ (q0,1,x) = {(q1, ε)} [q0, x, q1] 1 δ (q0,1,x) = {(q1, ε)} [q1, x, q1]  1 δ (q1, ε,x) = {(q1, ε)} [q1, x, q1]  ε δ (q1, ε, z0 ) = {(q1, ε)} [q1, z0, q1]  ε
29. 29. 29 After analyzing all the productions, it is clear that there are no productions for the variables. [q1, x, q0], [q1, z0, q0] And the variables [q0, x, q0], [q1, z0, q0] have [q1, x, q0] or [q1, z0, q0] on the right, which do not derive any terminal strings. Like so for the variables [q0, x, q0], [q1, z0, q0] Deleting all the productions which involve these variables, the following productions were left. S[q0, z0, q1] [q0, z0, q1] 0[q0, x, q1] [q1, z0, q1] [q0, x, q1]  0[q0, x, q1] [q1, x, q1] [q0, x, q1] 1 [q1, z0, q1]  ε [q1, x, q1]  ε [q1, x, q1]  1 The resultant productions are: S[q0, z0, q1] [q0, z0, q1] 0[q0, x, q1] [q1, z0, q1] [q0, x, q1]  0[q0, x, q1] [q1, x, q1] [q1, z0, q1]  ε [q1, x, q1]  {ε, 1} 10.Convert the grammar S  0S1 / A; A  1A0 / S / ε into PDA that accepts the same language by empty stack. Check whether 0101 belongs to N(M). (May/June2014) SOLUTION: PDA: P = ({q}, {0, 1}, {S, A, 0, 1}, δ, q, S)
30. 30. 30 PRODUCTION: Where δ is defined by δ (q, ε, S) = {(q, 0S1), (q, A)} δ (q, ε, A) = {(q, 1A0), (q, S), (q, ε)} δ (q, 0, 0) = {(q, ε)} δ (q, 1, 1) = {(q, ε)} CHECK STRING: 0101 (q, 0101, S) ⊢ (q, 0101, 0S1) ⊢ (q, 101, S1) ⊢ (q, 101, 1A01) ⊢ (q, 01, A01) ⊢ (q, 01, 01) ⊢ (q, 1, 1) ⊢ (q, ε, ε) Thus the string 0101 is accepted by the above PDA by empty stack. 0101 ∈ N(P) 11.Give formal pushdown automata that accepts {wcwR | w in (0 +1)*} by empty stack. (Nov/Dec2013) SOLUTION:  For each move, the PDA writes a symbol on the top of the stack.  If the tape head reaches the input symbol c, stop pushing onto the stack.  Compare the stack symbol with the input symbol, if it matches, pop the stack symbol.  Repeat the process till reaches the final state or empty stack. PDA: P = ({q0, q1, q2}, {0, 1, c}, { 0, 1, c, z0}, δ, { q0}, { q2}) PRODUCTION: δ is given by δ (q0,0, z0 ) = {(q0, 0 z0)} δ (q0,1, z0 ) = {(q0, 1 z0)} δ (q0,0, 0 ) = {(q0, 00)} δ (q0,1, 0 ) = {(q0, 10)} Push
31. 31. 31 δ (q0,0, 1 ) = {(q0, 01)} δ (q0,1, 1 ) = {(q0, 11)} δ (q0,c, 1 ) = {(q1, 1)} Accept the separator c δ (q0,c, 0 ) = {(q1, 0)} δ (q1,0, 0 ) = {(q1, ε)} δ (q1,1, 1 ) = {(q1, ε)} POP δ (q1, ε, z0 ) = {(q2, ε)} TRANSITION DIAGRAM: 0, z0/ 0z0 1, z0/ 1z0 0,0/00 1,1/11 1,0/10 0,1/01 0,0/ ε 1,1/ ε c,0/0 c,1/1 ε, z0/ ε 12. Explain in detail about the closure properties of CFL. (May/June2013) CLOSURE PROPERTIES OF CFL: a. Substitution b. Application of Substitution c. Reversal d. Intersection with a Regular Language e. Inverse Homomorphism SUBSTITUTION: Let ∑ be an alphabet. For each symbol a in ∑, choose a language La and S(a) defines the substitution function. If w = a1 a2 ….an is a string in ∑, then s(w) is the language of all strings x1 x2 … xn such that strings xi is in the language S(ai) for I = 1, 2,…n. S(L) is the union of S(w) for all strings w in L. q0 q1 q2
32. 32. 32 EXAMPLE: Let S(0) = {0n 1n | n > 1} then S(1) = {00, 11} [a = 1] It contains only two strings 00 and 11. But S(0) contains one or more a’s followed by an equal number of b’s. Let w = 10, then S(w) is the concatenation of S(1) and S(0). S(w) = S(1).S(0) = 000n 1n , 110n 1n. APPLICATION OF SUBSTITUTION: The context free languages are closed under following operations. 1. Union 2. Concatenation 3. Closure(*) and Positive closure(+) 4. Homomorphism REVERSAL: Let G = (V, P, T, S) be a CFG and L(G) be in grammar. Then G’ = (V, T, P’, S) Where P’ – Reverse of each production in P.
33. 33. 33 Construct P’ where If A  α is a production of G, then A α’ is a production of G’. Let A  a1 a2 … an be a production in G. Then A α’  an an-1 …a2 a1 Since all the sentential forms of G’ are reverses of sentential forms of G and vice versa. The CFL’s areclosed under reversal. INTERSECTION WITH A REGULAR LANGUAGE: Construct a PDA which contains both PDA and Finite Automaton. Let P = (Qp, ∑, Γ, δp, qp, z0, Fp) be a PDA that accepts L by reaching its Final state. Let A = (QA, ∑, δA, qA, FA) be a DFA for R. Construct a new PDA produced due to the intersection of P and A P’ = (Qp X QA, ∑, Γ, δ, (qp, qA) z0, Fp X FA) Where δ((q, p), a, x ) = set of all pairs of (r, s),)such that 1. s = δA^(p, a) 2. δp(q, a, x) = pair(r, γ) For each move of PDA P and for each move of finite automata A, there should be a corresponding move in PDA P’. Note that a where a is any symbol or ε. If a = any value, then δ^(p, a) = δA(p) If a = ε, then δ(p, a) = P i.e., A does not change state while P makes ε moves. And the number of moves made by the PDA’s that Where p = δA^(p, w)
34. 34. 34 Since (q, p) is the accepting state of P’ if and only if q is the accepting state of P, and p is the accepting state of A. Therefore P’ accepts w if and only if both P and A do. i.e., w is in L ∩ R INVERSE HOMOMORPHISM:
35. 35. 35