You are on page 1of 21
oy Lic arte(ile:) A Theory of Computation Comprehensive Theory with Solved Examples and Practice Questions La Ee MADE EASY MADE EASY Publications Corporate Otic: 44-A/4, Kal Sarai (Near Hauz Khas Moto Station), New Delhi-110016 Email. infomep@madeeasyin ‘Contact; 011-45124860, 8860378007 Visi us at. ww madevasypublicatons org Theory of Computation Copyright © 2016, by MADE EASY Publications, Allrights are reserved, No part of tis publication may be repraduced, stored in or introduced into a rattieval system, of tansmitted in any form or by any means (electronic, mechanical, photo-copying, recording ot otherwise), without the prior written permission of the above mentioned publisher of this book. First Edition: 2015 Second Edition Revised & Updated) :2018 © Alrights reserved by MADE EASY PUBLICIONS No art of this took may be reproduced rule in any writen permission fom ine shee Preface ‘This book was motivated by the desire to further the evolution of aconcise book on Theery ef Computation. Keeping in focus the importance of this subject in GATE, we have done a proper study and thereafter developed the content of the book accordingly. This edition has an expanded discussion / ofall relevant topics in the subject Initially, we compiled the perceptions of our students on their problems in GATE while dealing with the questions from this subject. We identified B. Singh (&« IES) their various problems lke- lack of fundamentals ofthe subject, lfficulty in solving simple questions, shortage of a complete study package, ete, These strengthened our determination to present a complete edition of Theory ef Computation textbook The book addresses all the requirements of the sludents, Ie. comprehensive coverage of theory, fundamental concepts, objective type problems and conventional problems, articulated in a lucid language. The concise presentation will help the readers grasp the concepts with clarity and apply them with ease to solve problems ‘quickly The book not only covers the entire syllabus of GATE, but also addresses the need of many other competitive ‘examinations, Topics lke ‘Set operations, Chomsky hierarchy, OFA, NFA, Regular expressions, CFL, PDA, TM, Closure properties of regular, CFL, Recursive enumerable languages, Decidabilty and undecidabilly’ are given {ull coverage inline with of our research on their importance in competitive examinations. We have put in our sincere efforts to present elaborate solutions for various problems, different problem solving methodology, some useful quick techniques to save time while attempting MCQs without compromising the accuracy ‘of answers, A summary of important points to remember is added at the end of each topic. For the convenience of the readers, points to remember are specifically highlighted in the form of a note- both in theory as well as solved ‘examples. AL the end of each chapter, sets of practice question are given with their keys, thal will allow the readers 10 evaluate their understanding of the topics and sharpen their problem solving skills ‘Our team has made their best efforts to remove all possible errors of any kind. Nonetheless, we would highly appreciate and acknowledge if you find and share with us any printing, calculation and conceptual errr. Itisimpossibie to thankeall the individuals who helped us, but we would ike to sincerely thank allthe authors, editors. and reviewers for putting in their efforts to publish this book. With Best Wishes B.singh (OMD, MADE EASY Contents Theory of Computation Chapter 1 Chapter 3 Grammars, Languages & Automata........2 Context Free Languages & Push down 1.1 Introduction. 2 Automata .. .90 12. Chomsky Hierarchy 4 321 Context Free Grammars %0 13. Automaton 5 22 Context Free Language se 14 Grammars 6 33 PushDown Automata PDA %8 1.5 Equivalence of Languages, Grammars and 3.4 Equivalence between CFL and CFG. 107 hetomete ; 35 Closure Properties of CFLs 108 36 Closure Properties of DFS 10 1.6 Expressive Power of Automata 8 27 Decision Properties of CFLS m 1.7 Applications of Automata 8 38 Non-Content Free Languages 18 39 Nom-Regulr Languages and CFs na Chapter 2 Regular Languages & Finite Automata....13 Chapter 4 2.1. Introduction. 13 REC, RE Languages & Turing Machines, 22 Deterministic Finite Automata (OFA) 15 Decidability. 123 23. Non-determiisic Finite Automata 421 Tating Machine (TM) 1 (NFA or NOFA. 30 42. Variation of Turing Machines. 24 24 Epson NFACeNEA 9 43 Tuting Machine Computation 135 25. ReguarExpesions 2 4A Turing Machine Recognizabe Languagesenu 127 45 Closure Properties ne 26 Equivalence between Finite Automata and 46 _ Resticted Turing Machines ns Regular Expressions 45 : 47 Tuting Machine Construction, 28 27 Regular Grammar, 52 48 Post Correspondence Problem (PCP). 133 28 Closure Properties of Regular Languages...56 49 Some beadoble Problems tecursve 29 Decision Properties ofReguar Language ...61 Languages on Tring Machines 2 2.10 Moore and Mealy Machines 22 410 Chomsky Hierarchy Vs Other las ons 134 2.11 Pumping Lemma 6 4:11. Decidabity of Formal Languages 134 2:12 Minimization of Finite Automata 69 412 Terminology of Problems. 136 213. Myhill-Nerode Theorem n 4413 Important Points of Undecidabilty a7 4.14 Reduction. 137 (iv) CHAPTER Context Free Languages & Push down Automata 3.1 Bad a S Context Free Grammars Definition Acontext-roe grammar Gis a quadruple (V, T, P, $), where. ‘+ Visthe set of non-terminals. (Non-terminals used in the grammar and they do not appear in strings of the language) ‘+ Tis the set of terminals, ‘+ Pis the sot of productions. Itis a finite subset of Vx (T+ Vy" PV—9(T+ ‘+ Sis the start symbol, Se T. Example: The following context tree grammar generates all strings of balanced parentheses. Sossl(S)le Derivation of a String +. Left Most Derivation (LMD): In each sentential form, the left most non-terminal is substituted with corresponding production to derive a string Example: Let G be the following grammar Sabla A> aBAla Bob Then LMD derivation for a string = “aabab” is: $ > aAB = aaBAB= 2abAB = aabaB = aabab 2. Right Most Derivation (RMD): In cach sontontial form, the right most ron-torminal is substituted with corresponding production to derive a string, Example: Lot G be the following grammar Sabla A>aBbAla Bob Thon RMD derivation fora string = “aabab* is: S— 2AB= aAb= aaBAb— aaBab— aba Publloatone Gr aDESESypUICRHONS OT MADE EASY © Copyright | — D MADE EASY Context Free anguages&Pushdown Automata | 93 3. Parse tree (derivation tree): Let G = (VT. P, S) be a CFG where each production of G can be represented with a tree satisfying the following () If Aa, a,... a,is a production in G, then A becomes parent of nodes labeled a,, a... a (i) The collection of childron from left to right yields a, a, ay. 2, If we L(G), then it can be represented by a tree called derivation tree satisfying the following: (i). The toot has label $ (the starting symbol), (i) Alinternal vortices are labeled with variables, (ii) The terminal nodes are labeled with ¢ or terminal symbols, (is) If A> a4 04.6, is a production in G, then A becomes the parent of nodes labeled «, of,..ch, (0) The collection of leaves from left to right yields the string w. Example: Let be the following grammar Sr aAsla A>aBAla Bob Then parse tree construction for a string = “aabab’ is: © "kN © oO & fo 3.1.3 Unambiguous Grammar and Ambiguous Grammar Unambiguous grammar: The grammar is called as unambiguous grammar it + Every string derived from the grammar has exactly one LMD. or ‘+ Every string derived from the grammar has exactly one RMD. or ‘+ Every string generated from the grammar has exactly one parse tree For every string derived from the context free grammar has: Number of parse tree's = Number of LMD's = Number of RMD's = 1 Example: Consider the following CFG Soasla Every string derived from the above grammar contain one parse tree. Hence the given grammar is Unambiguous, ‘Ambiguous grammar: The grammars called as ambiguous grammar i ‘+ There exists a string which is derived from the grammar has more than one LMD. or ‘+ There exists a string which is derived from the grammar has more than one RMD. or ‘+ There exists a string which is generated from the grammar has more than one parse tree. 4 + © Copyright MADE EASY wwwmadeeasypublications.org | a 92 | Computer Science & IT * Theory of Computation MADE EASY For some string derived trom grammar has: Number of parse tree's >1 Example: Consider the following CFG SaslAla Asasla For string “a’, more than one parse tree is possible. Hence the given grammar is ambiguous Inherently Ambiguous Context Free Grammar ‘+ If there is no equivalent unambiguous grammar present for a given grammar, then such a grammar is called as inherently ambiguous grammar. ‘+ Fora given language ifthere is no equivalent unambiguous CFG then such language is called as inherently ambiguous context free language. + = {alb/c4} U {ambe"} is inherently ambiguous CFL. Because L has no equivalent unambiguous CFG. Reduced CFG and Simplified CFG ‘+ Reduced CFG (non-redundant CFG): Reduced CFG is a CFG without any useless symbols + Simplified CFG: Simplified CFG is a CFG without any null-productions, unit-productions and useless symbols Conversion of CFG into Simplified CFG The following order applied on a given CFG to convert into simplified CFG. 1. Elimination of null productions: X — « is called null production where X is a variable, 2. Elimination of unit productions: A> 8 is called unit production where A,B are variables, 3. Elimination of useless symbols: The symbols that can't be used in any derivation are known as useless symbols, Elimination of Null Productions * Xi a null production in the grammar. All such null productions should be eliminated. ‘* I language contains a null string for given grammar G, afler removal of null productions from G equivalent language will not contain the null string, ‘+ Let Gbe a CFG and G’ be an equivalent to G but without null productions. Then L(G’ Stops to Eliminate Null productions: 1. Find the nullable non-terminal set: A set of all non-terminals where every non terminal derives “e asa string either directly or indirectly. Example: Consider the following CFG with null productions S— aAl bB| AB Avadle Bo bBle In above CFG Ae and B+ are null productions, so both A and 8 non-terminals are included in the nullable set. Scan also derive e from $ -» AB whore Aand B both derives «. Nullable non-terminal set = (A, B, S} MADE EASY © Copyright | MADE EASY Context Free anguages&Push down Automata | 93 2. Elimination of null production: For every non-terminal in nullable set, first remove null production then add new productions in the grammar by substituting e inplace of that particular non-terminal. Saal bB|AB Asadle B bble In above CFG Ae and 8+ are eliminated. Add new productions by substituting e. From S— aA production, by substituting ein place of A the new production S— ais added. Similarly S— bis added for S bB, SA and $— Bare added for S AB, A ais added for A> aA, and B bis added for B— bB. Aiter removal of Null-productions from the above given grammar is: Saal bal ABlalolAlB Asadla B= bBlb Elimination of Unit Productions Lot X-+ Yb the unitproduetion. Then unt production X-> Yis oliminated by substituting all Yprocluctions. Example: Consider the following grammar which contain unit productions, S—ablbAlA A> aBIB B= bAlb Alter removal of unit productions (SA and A — B), the resultant grammar is S—ab|bAlaAlbAlb A->aBlbAlb B= bAlb Elimination of Useless Symbols 1. Find useless productions: Find the non-terminals which cannot derive the string (any sequence of terminal symbo's) either directly or indirectly from the grammar and'then eliminate productions associated with these non-terminals. Example: Consider the following CFG with useless productions SAB Aaclaala 8 bBlbClb Doe Aderives a, Bderives b, Ddetives e and Sderives ab but Can not derive any string. So, eliminate C from all productions which contain non-terminal C. Therefore A—> aC and B—> bCare eliminated. SAB Avadla Bo bBlb Doe 2. Find the useless symbols: Find the symbols (terminals and non-terminals) which never appear in any sentential form and then eliminate the productions associated with these symbols. —— as © Copyright MADE EASY wwwmadeeasypublications org ) Publleadone 94 Computer Science & IT * Theory of Computation MADE EASY Publications inate all symbols which are not reachable through start symbol Seither directly or indirectly inthe grammar. + Non-terminals A and & are reachable from S, the terminal a can be reachable from A (hence reachable indirectly from S), bis reachable from B (hence reachable indirectly from S). ‘+ Eliminate the productions which contain the symbols D and e, because D and e are useless symbols, Example: Consider the following CFG with useless symbols SAB Avadla Bo bBlb Doe The following grammar is ater elimination of useless symbols where D> eis eliminated from the grammar, SAB A>adla B> bBlb ‘Chomsky Normal Form (CNF) * |falanguage L without null string (e) is generated by a CFG Gthen there exists a CNF grammar G’ which is also generates the language L. + There ae two types of productions in CNF grammar: ~> + InRHS of every production of the CNF grammar contain only women ferminals ora single terminal. A> BC Ava + CNFis also called as binary standard form. + The number of productions are requited for generating slength sting from the given CNF context free grammar is: (2x- 1) Example: lo produce the string “ab", the number of productions are required is 3. ie. 2*]abl = 1 = "2-1 =3, The productions are as follows: S-» AB. A» aand B-»b. © Let'G be the given CNF grammar and 'T’ be the derivation tree for some string ‘x in G. If the length of the longest path is equal to k then yield length < 2*-7 + For the generation of length yield, the minimum height o 12 derivation tree for the given CNF conte, «free grammar is [logp/]+ 1 and maximum height will be Leth be the minimum height of the derwation tree, which gives yiold of length T= 2h = ho 1=og,/ > h=log, t+ 1 ‘+ Let 'G’ be the given CFG without null productions and unit productions and 'k’ be the maximum number of symbols on the right hand side of any production, ‘Then the equivalent CNF contain a maximum of: (k- 1)IP|+ IT| productions. where, |P|= the number of productions in‘@’, |T|= the number of terminals, k = maximum number ‘of symbols on right hand side ~ MADE EASY Sepa) —— D Publloatone MADE EASY Context Free Languages&Push down Automata | 5 Example: Consider the following CFG. $9 aAbB Avadla B= bBlb The equivalent CNF grammar for the above CFG is S30X XoAv ¥o6,8 AsCAla 83 0,Blb Ca C3 b Ingiven CFG: [Pl =6, ITI=2,k=4 The resultant CNF CFG has 9 produetions. EEEEEEESIE Find the maximum yield length for the following CNF CFG. SAB Ava Bob Sol Longest path length = 2= k Derivation tree forthe string ab: ia imum ye length = 2"= : 2 .d the maximum yield length for the following CNF CFG. SAB As EF Bac E F Solution: a a +b ,~ a a > ® Derivation tree for the string ab: wea Maximum yield length = 2'= 4 “Copyright MADE EASY www.madeeasypublications.org 96 | Computer Science & IT * Theory of Computation MADE EASY Conversion from CFG to CNF-CFG ‘+ fright hand side of any production contain more than two variables then consecutive two variables canbe replaced by a now variablo. Example: A— XYZis converted to A> XPand P—> YZ. ‘+ IFRHS of productions contain combination of terminal and non-terminal symbols then each terminal symbol is replaced by a new non-erminal Example: 1, A-vaBis replaced by A> C,Band C,>a 2. S-+ABCDEFGis replaced by the following productions SAA, A, > BA, A, CA, ADA, A, EAs AsO FG EEEEEEENE | Construction of an equivalent CNF for the following CFG. S—aSalbsblalb Solution: P,:S—>aSa_(NotinCNF) P,: $9 bSb_(Notin CNF) PyiSa — (InCNF) Py:S>b — (InCNF) Consider P,: Replace the terminal a by a new variable A, we get S—> ASA, Now. replace SAby anew variable X, and so, S > AX,, where X,> SA, A> aare in CNE SAX, X9 SA, and A aare new productions equivalent to S—> aSa Consider P,: Replace the terminal b by anew variable B, we get S—» BSB.Now, replace SB by anew variable X, and so, S BX,, where X,— SB, B— bate in CNF. $— BX, Xp» SB: and B= b are now productions equivalent to S$ bb. he resultant CFG in CN $3ax,laxlalb, Ava Bob, X99 SA, X,> SB. EEEEEIEEZI «Construction of an equivalent CNF for the following CFG. Sa bAlaB Aa bAAlasla B—apalbsib . “wwwumadeeasypublcations.org MADE EASY ©copyright) MADE EASY Context Free anguages&Pushdown Automata | 7 Publications Solutior h production which is not in CNF converted as following S>bA + SAGAC,>b Saab + S308, A>bDAA = A4C,AA +A C,Eand E> AA Avas + A+OS,A+a B+aBB 3 BCE F488 Bobs = B96 oquivalont CNF for given CFG is So0,le,8 A>CEIC Sl BC FIG, Slb E> AA Faea G,>b Coa ‘otal productions ofan eauivalent CNF grammar = 12 EEEEEIEERE «Construction of an equivalent CNF for the following CFG. S$ aAD An ablbas Bob Dod Solution: valent CNF for the above CFG is S26 E> AD ACB A> BF FAB Bob Dod C+ ‘otal 8 productions in CNF CFG. 3.1.8 Greibach Normal Form (GNF) ACFG G=(V, T, P, S)is in Greibach normal form (GNF) if its all productions are of type A—> act, where ae V (siting of variables including null string) and ais single terminal (ac T). ‘+ Every CFG production of GNF grammar contains a single terminal (a) followed by any sequence of non-terminals (a). .., A» aot ‘* Every CFL Lwithout null string (e) can be generated by GNF grammar has productions are of type A > aa, where ae Vand ae T. —— as © Copyright MADE EASY vveimadceasypubliations.or 9g. | Computer Science & IT * Theory of Computation MADE EASY ublestlone No CNF orno GNF context tree grammar generates the null string, Hence for e-free CFG's only we can construct an equivalent CNF or an equivalent GNF ‘+ InGNF context free grammar, the restrictions only on the pasitions, but not on length of right side of a production. ‘+The number of productions required to generate the s-length string from the given GNF-context tree grammaris: [x] Example: To produce a string “ab! Number of productions = length of the string = | abl = 2. The productions are: S— aB and B= b. ‘+ Substitution (Lemmat): If A 6c: and 88, |p... B,then following productions are without Bat left most place in RHS of production of A. it's called as substitution of Bin the production of A A> B.a1B,al...B,o + Elimination of Left Recursion (Lemma2): |f A > Ac, |Aczl..... Aa, and A> B,1B,|... B, then following productions are without left recursion for 1 sis mand 1 BIBZ Za) a2 3.2 Context Free Language + Lol G = (V, T, P, $)is context free grammar, The language generated by Gis L(G) = {wlveT and $ derives w), A language L is a CFL iff here is a CFG G so that L = L(G) CFL's are type-2 formal languages. Push down automata recognizes the context free language Class of Context free languages are superset of regular languages: * Class of Context free languages are subset of context sensitive languages. 3.3 Push Down Automata (PDA) he push down automaton is an automaton that accepts a context free language. Push down automaton 's non-deterministic by defaut. The language accepted by push down automaton also called as non-deterministic context free language, PDA also called as NPDA and CF is also called as NCFL. 33.1 ‘+ It contains a finite control, an input tape and a stack. ‘+ Finite control contain finite number of states. ‘+ Read head (read pointer) is used to read the input symbol from the input tape. ‘+The symbols can be pushed or popped from the stack, used to keep track of previous symbols. ‘+ For every string, finite control starts from the initial stale. If the string is valid, either finite control reaches to the final state at the end of input or it makes the stack is empty. Input Tape ] Frnie Conta Stack PDA Configuration ~ MADE EASY Sepa) —— D Publloatone MADE EASY Context Free anguages&Pushdown Automata | 9g 33.2 333 33.4 335 PDA Acceptance ‘+ Acceptance by a final state (universal mechanism): To accept the valid string, PDA reaches to the final stato, This mechanism is used infinite automata, push down automata and turing machine Hence this mechanismis called “universal mechanism" + Acceptance by an empty stack (local mechanism): Empty stack indicated for acceptance of the input string instead of reaching final state, This mechanism used only in push down automata hence itis called local mechanism. No final state is needed for this mechanism. ‘+ Acceptance by both empty stack and final state: String can be accepted by reaching the final state and by making the stack is empty. CFL = PDA by empty stack = PDA by final state « PDA by empty stack and final state = CFG. PDA Specifications PDA =(Q, 2.1.8, dy, Zy Fis a seven tuple notation, where, Qis the set of finite states is an input alphabet Tis the stack alphabet which contains a finite number of stack symbols is a transition function, © (OPDA)S: Qx@ule))xP> Qxr" + (NPDA)B: Qx (EU {e})xT—> 29" (only finite subsets) dyis.a start state where q,<€ Q. Z's the intial top of stack symbol Z, € I. Fis the set of final states Fc Q. (If acceptance is by empty stack method then F= 6) PDA Operations The operations on push down automata are as follows: ‘+ PUSH: Symbol is pushed onto the stack by reading some input symbol 8 (present state; ifp symbol, top of stack’symbol) = (next state, (fp symbol) (top of stack symbol)) ‘+ POP: Symbol at the top of the stack is popped by reading some input symbol 8 (present state, input symbol, top of stack symbol) = (next state, ¢). ‘+ BIPASS: Stack content is unchanged by reading some input symbo) 8 (present slate, input symbol, top of stack symbol) = (next state, top of stack symbol). PDAModels 1. Non-deterministic PDA (NPDA or PDA) ( NPDAaccepts non-deterministic CFL (ii) PDA\s by default non-deterministic (iii) NPDA has non-deterministic transition for the input and stack combination, (i) NPDA accepts an input if a sequence of choices leads to some final state or empty slack, depends on acceptance mechanism. (0) NPDA transition function 8 : Qx (2:U {e))x P+ 29*™. For example the following transition is non- deterministic on input a and top of the stack symbol a, &(q, a, a) = {(@. 8), (g, aa) .@., pop operation or push operation, < + © Copyright MADE EASY wwwmadeeasypublications org ) € a 100 | Computer Science & IT * Theory of Computation MADE EASY 2. Deterministic PDA (DPDA) () DPDA accepts deterministic CFL (OCFL) (ii) DPDA has exactly one transition for every input and stack combination. (ii) OPDA accepts an input ita sequence of choices leads to a final state (iv) OPDA is less powerful than PDA and every DPDA is an NPDA but every NPDA and not be a DPDA, )) PDA transition function 8 : Qx (2 U (e)) x P+ @ x1". For example the following transition is deterministic on input a &(g, a, a) = (q. €) ie., pop operation. NOTE: Assume all PDA's are having by default z, or Z, as intial top of stack symbol otherwise z, can be pushed with the special transition 8(qp €, €) = (qo. 23) 3.3.6 PDA Construction ept L = ( a*b"In2 1} (i) PDA transitions: PDA = ({q., 4. 4.12.6). P.8, I 25. a = fo 279 Go Batt ar push onto stack 8lda, & a) = (4g, 2a) Bap. b, a) i} One ‘a’ is popped for each (gy, b, a) = (a, 8) 8 (a,.€. %) = (44. €) Acceptance by emoty stack, (No final state is needed) = (qj. %) Acceptance by final state, (No need to empty the stack) = (qj) Acceptance by both empty stack and fina state. (i) PDA transition diagram: Empty stack, Final stato Both Empty stack and Final stat ‘alee ede ‘aaa az, bake bate ajar, bale QQ oY a or (ii) PDA transition table: PDA Acceptance by Empty Stack = B Tr, ea = a wT a (as.8) a B = ~% ela Ga Gee a ay. ae az ~ (wrmumadeeasypublicationsorg MADE EASY ©Copyright) MADE EASY Context Free Languages & Push down Automata PDA that accept L = {a"b"c"|m,nz 1) Construct t Sol (A PDAtransitions: PDA = ((4, 4 4p, 4 (AB, 6). T.8, A, Zp Bao. & 20)= (Go. 220) ® Ail input a's are pushed onto stack BQ, & a) = (dq, aa) | Bla», B.a)= (ay 8 (20, B @)=(@ © Ong ais popped foreach input‘ B(q, B, a) = (a, 8) Bqy. 6 20) = (Qe. % Bar & 20) = (9: 70) Ay input c's are ignored Bde, ©, 20) = (Ga: Z0)) tno operation premed on te tack) (dp, €, 2) = (dp, £) Acceptance by empty stack. = (4,, 2) Acceptance by tinal state: = (qj, €) Acceptance by both empty stack and final state (i) PDA transition diagram: ‘Acceptance by empty stack Acceptance by final state ‘alas ead aalaa lt 2.20% bale alt Tare Tae FEES «Construct the PDA that accept L = {a” b™".c"| m,n 1) Sol (PDA transitions: PDA = ({45, 4. dp. 4. (1B, 6).T.8, AZ 8(Go, & 20) = (Go: 20)| ay input a's are pushed onto slack 8(qp, &, a) = (Gg, 28) (qo, B, a) = (44, €)] } One ‘a’ is popped for each input (4). ©, a) = (4). €) | Bla, b. 29)= (a. bz), fe pushed onto the stack (qb, B)= (4, bb) | Remaining all input b's BQ, ©, B)= (ae, €)| } Pap one b for each input ¢ Biqy, ©, b)=(q,. 0) P Blgp €, %) = (dp. £) Acceptance by empty stack. = (qj, %) Acceptance by final state = (qj, €) Acceptance by both empty stack and final stato “Copyright or Q & rar aa 8 eae 101 MADE EASY (RMA ore 102 Computer Science & IT * Theory of Computation MADE EASY (i PDA transition diagram: ‘Accoptance by empty stack ‘Accoptance by final stato 262, baba, aafaa bbb eee alan bite azJaz, bale ple Onl a(e) ae) ms: PDA = (Ay, dy Gp Gy) (8.6). 18, Gy 28) B(Qg: &: 2) = (Gas AZo) Ala’ are pushed B(dp, 8, €) = (@y, 22) | p Blo, B, a) = (4,4) 8(qy,b.a) = (az. a) 8(qp, b.) = (G58) B(q, 6.) = (@y 8) For every 3 input b's: Bypass 2 b's and one a is popped for the third b Blaye, %) = (dy); Acceptance by empty stack (i) PDAtransition diagram: ‘Acceptance by empy stack Bae I EEEEEEERE «Construct PDA for £ = {w e(a + b)*Inumber of a’s(w) 2 number of b's (w)} Sol PDA transitions: PDA = ((q,}. 14.01.15, dy. 2) Bd, 2) = (Ig. 2) Bl qo, B. 2) = (Gy, BZ) Bq, @. a) = (yaa) (qa, a, b) = (dy, 8) Blqp,b. a) = (dy. ) Blqy, B. B) = (dy. BE) Bq. a) 8g, €, 2) = (qy €); Acceptance by emply stack. dp, €}; Slack contain a’s after reading entire input ‘wownwmadeeasypublications.org MADE EASY ‘© Copyright | MADE EASY Context Free Languages & Push down Automata Construct PDA that accept all strings of balan: Solution: PDA transitions: PDA = ((q,).((.)).1.8. dy 29) 2) = (dy: (2) OF (4 (0. O= (42) 2) = (A €) FEGEEIEREN «Construct PDA that accepts a language L = (ww#lwe(a + b)*t Soluti () PDAtransitions: PDA= ({q. gy). {@. B.T.8, dy. 25-9) Blqp. a, 2) = (dy. 225) Blqy, B. 2) = (Gy, Bz) Bld, ab) = (4, ab) Bq, b, a) = (4, ba) (gy 28) or (44, €) b, b) = (dp, bb) oF (qa, €) 8g... Bq, b, (ae) 448) Bly £29) = (dy 8) (i) PDA transition diagram (PDA acceptance by empty stack): oan 0, zlbey ovale aloe baie | bee sale 2. ale0 | % a) FEEEEEREN «Construct PDA that accepts a language L = {a bIm n} Sol (a bm! = np Sol L=(a"b'lm nh Construct PDA that accepts a language L = {w C w'lwe(a, b}* Cis a special input symbol} Sol byw, l=11) Solution: abe, ake oie Get abo Sab] bee (a) LOO “www.madeeasypublications.org MADE EASY ‘© Copyright MADE EASY Context Free anguages&Push down Automata | 405 Construct PDA that accepts a language L = {wlwe (a+ 6)", whas equal number of a's and b's) Solution: EEEEEEREN «Construct PDA that accepts a language L = (w|we (a + b)*, whas more b's than a's} Solution: ae yin, e Construct PDA that accepts a language L= {a"b"|(m=n) or (2m=n), m,n2 1) fa”b?ck|m + n= k, m,n, k21} EEE «Construct PDA that accepts a language L Solution: ‘be ob ‘aba Babb eae Saba ta® EEEEEEESH «Construct PDA that accepts a language L = {a”b’c"lm= n+ km, n= 1} Solution: ae cae poet aziet, se ee © “copyright MADE EASY wwwimadeeasypublications.org | 106 | Computer Science & IT © Theory of Computation MADE EASY EEGEEEESN «Construct PDA that accepts a language L = (a"brc'lm +k =n, m, n= 1) Sol (aba @ eb OrE 588.) azjez, bee oe ‘ale b2Ibz, bbb EEEEEEEZY «Construct PDA that accepts a language L = {ab"c"lif (mis even) then m20,n, k20} Solution: L={atprerli, n20) U (a2 bella, j k2 0} ‘Construct PDA that accepts a language L = {a™b*c*lif (n is even) then m=k, make) Solution: aay ae aaa “www.madeeasypublications.org MADE EASY ‘© Copyright

You might also like