Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
72 views
Unit Iv
Theory of computation
Uploaded by
janani.m
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save UNIT IV For Later
Download
Save
Save UNIT IV For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
72 views
Unit Iv
Theory of computation
Uploaded by
janani.m
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save UNIT IV For Later
Carousel Previous
Carousel Next
Save
Save UNIT IV For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 36
Search
Fullscreen
y2ics4o2 THEORY OF COMPUTATION oni Ww PosHDows — AOTOM 8TA Riskadoun aubwnsta - Osfiadiona - Mewes - Tnstan tone descriptions - Determine sic pushdown automeda ~ Equivalence 4, Pushdewn and crL ~ Ramptng domme te 26. * Closure properties 4 cre° Unit-4 Pushdown Automata(PDA) Pushdown Automata is a finite automata with extra memory called stack which helps Pushdown automata to recognize Context Free Languages T Pushdown automata Finite automata implement a CFG 1. Pushdown automata is a way to DFA for a regular grammar amount of information. 2. PDA can remember an infinite DFA can remember a_ finite amount of information ‘A pushdown automata is simply an NFA augmented with an “external stack memory". The addition of stack is used to provide a last-inirst-out memory management capability to Pushdown automata. Itcan access a limited amount of information on the stack. A PDA can push an element onto the top of the stack and pop off an element from the top of the stack. To read an element into the stack, the top elements must be popped off and are lost. PDA is more powerful than FA. Any language which can be acceptable by FA can also be acceptable by PDA. PDA also accepts a class of language which even cannot be accepted by FA. Thus PDA is much more superior to FA. Input Tape Finite Control Accept or Reject —— Push or Pop ushdown AutomataPDA Components: mae SPOONS: Input tape: The input tape is divided in many cells or symbols. The input head is read-only ‘one symbol at a time and may only move from left to right, Finite control: The finite control has some pointer which points the current symbol which is to be read. ‘Stack: The stack is a structure in which we can push and remove the items from one end only. It has an infinite size. In PDA, the stack is used to store the items temporarily. finite control input tape Formal definition of PDA: The PDA can be defined as a collection of 7 components: Q: the finite set of states J: the input set T: a stack symbol which can be pushed and popped from the stack q0: the initial state Z: a start symbol which is in Fr. F: a set of final states 3: mapping function which is used for moving from current state to next state.in a given state, PDA will read input symbol and stack symbol (top of the stack) and move to a new state and change the symbol of stack.Graphical Representation of PDA Instantaneous Description (ID) ID is an informal notation of how a PDA computes an input string and make a decision that string is accepted or rejected. An instantaneous description is a triple (q, w, a) where: q describes the current state. w describes the remaining input. a describes the stack contents, top at the left. Turnstile Notation: + sign describes the turnstile notation and represents one move. * sign describes a sequence of moves. For example, (p,b, T) + (q, w, a) In the above example, while taking a transition from state p to q, the input symbol ‘b’ is consumed, and the top of the stack 'T’ is represented by a new string a._PDA Acceptance ‘A language can be accepted by Pushdown automata using two approaches: 4. Acceptance by Final State: The PDA is said to accept its input by the final state if it enters any final state in zero or more moves after reading the entire input. Let P =(Q, 5, I, 5, 90, Z, F) be a PDA. The language acceptable by the final state can be defined as: 1. L(PDA) = {w| (q0, w, Z) F* (p, €, €), 4 € FI 2. Acceptance by Empty Stack: On reading the input string from the initial configuration for some PDA, the stack of PDA gets empty. Let P =(Q, 5, F, 5, q0, Z, F) be a PDA. The language acceptable by empty stack can be defined as: 4, N(PDA) = {w | (QO, w, Z) F* (P, €, €), 4 € Q} Example 1: Define the pushdown automata for language {a"b" | n > 0} Solution : M = where Q= (40, q1 }and E={a,b} and ={A, Z}and dis given by 8(q0, a, Z) ={ (90, AZ) } 8( gO, a, A) ={ (0, AA) } (gO, b, A) ={( 1, €)} (qt, b, A) ={( at, €)} (qt, €,2Z)={( at, €)} Creed Boa Pe Pen z Bloaz-iqoay) Sloaarteoa) M2 Slaoaalstooaay ANZ Bieobariane) M2 Siarbai-tinen Slatbactaney — 2 Sarerrinen — €=> Explanation: Initially, the state of automata is q0 and symbol on stack is Z and the input is aaabbb as shown in row 1. On reading ‘a’ (shown in bold in row 2), the state will remain qO and it will push symbol A on stack. On next ‘a’ (shown in row 3), it will push another symbol A on stack. Alter reading 3 a's, the stack will be AAAZ with A on the top. After reading ‘b’ (as shown in row 5), it will pop A and move to state q1 and stack will be AAZ. When all b’s are read, the state will be q1 and stack will be Z. In row 8, on input symbol ‘e” and Z on stack, it will pop Z and stack will be empty. This type of acceptance is known as acceptance by empty stack. = >>Push Down Automata State Diagram: State Diagram for above Push Down Automata Note : + The above pushdown automaton is deterministic in nature because there is only one Move from a state on an input symbol and stack symbol. + The non-deterministic pushdown automata can have more than one move from a state on an input symbol and stack symbol + Itis not always possible to convert non-deterministic pushdown automata to deterministic pushdown automata + The expressive power of non-deterministic PDA is more as compared to expressive deterministic PDA as some languages are accepted by NPDA but not by deterministic PDA which will be discussed in the next article. The pushdown automata can either be implemented using acceptance by empty stack or acceptance by final state and one can be converted to another => Example 2: Design a PDA for accepting a language {a*b® | n=aR ens APene Solution: In this language, n number of a's should be followed by 2n number of b's. Hence, Sell apply a very simple logic, and that i if we read single ‘a’, we will push two a's onto the stack. As soon as we read ‘b' then for every single ‘b’ only one ‘a! should get popped from the stack. The ID can be constructed as follows: . 8(QO, a, Z) = (q0, aaZ) (a0, a, a) = (q0, 28a) Now when we read b, we will change the state from q0 to qt and start popping corresponding ‘a’. Hence, + 8(Q0, b, a) = (at, €) “Thus this process of popping 'b' will be repeated unless all the symbols are read. Note that popping action occurs in state qt only. . 541, b, a) = (a1, €) Aiter reading all b's, all the corresponding a's should get popped. Hence when we read & as input symbol then there should be nothing in the stack. Hence the move will be: (qt, €, Z) = (42, €) Where PDA = ({a0, a1, 42}, {@, b}, {a Z}, 5, 0, Z, (423) We can summarize the ID as: (0, a, Z) = (a0, aazZ) 8(Q0, a, a) = (a0, aaa) 8(q0, b, a) = (a1, €) (a1, b a) = (41, &) dat, e, Z) = (a2, €) Now we will simulate this PDA for the input string "aaabbbbbb". 5(qO, aaabbbbbb, Z) F 5(40, aabbbbbb, aaZ) + (QO, abbbbbb, aaaaZ) + 8(q0, bbbbbb, aaaaaaZ) + 8(q1, bbbbb, aaaaaZ) + (qt, bbbb, aaaaZ)© 2nw #8 + 8(q1, bbb, aaaZ) F (a1, bb, aaZ) + 8(q1, b, az) + 8(q1,€, Z) + 8(q2, €) ACCEPT co Example: aS Construct @ PDA that accepts the language L over {0, 1} by empty stack which accepts all the string of 0's and 1's in which a number of 0's are twice of number of 1's. ‘Solution: There are two parts for designing this PDA: o If 1 comes before any 0's © If 0 comes before any 1's, We are going to design the first part i.e. 1 comes before O's. The logic is that read single 1 and push two 1's onto the stack. Thereafter on reading two 0's, POP two 1's from the stack. The 5 can be ~ 5(0, 1,Z)=(0, 11) Here Z represents that stack is empty . (90, 0, 1) = (90, e) Now, consider the second part i.e. it 0 comes before 1's. The logic is that read first 0, push it conto the stack and change state from gO to q1. [Note that state q1 indicates that first 0 is read and still second 0 has yet to read]. Being in qj, if 1 is encountered then POP 0. Being in q1, if 0 is read then simply read that second 0 and move ahead. The 3 will be: + 8(q0, 0, Z) = (q1, 0Z) (at, 0, 0) = (qt, 0) . 5(q1, 0, Z)= (0, ¢) (indicate that one 0 and one 1 is already read, so simply read the se cond 0) . 841, 1, 0) = (qt, €) Now, summarize the complete PDA for given L is:PArons &(q0, 1, Z) = (G0, 112) 5(qO, 0, 1) = (a1, €) (gO, 0, 2) = (q1, 02) (G1, 0, 0) = (G1, 0) (a1, 0, Z) = (40, £) (90, €,Z) = (0, «) ACCEPT state Exercises. Ss 1. Consider the transition diagram of a PDA given below with input alphabet > = {a, band stack alphabet I = {X, Z}. Zis the initial stack symbol. Let L denote the language accepted by the PDA.(GATE-CS-2016) 2. b,xX/e ORE Gp san 5 wt ‘Which one of the following is TRUE? (A) L= {a"b"|n = 0} and is not accepted by any finite automata (B) L= {a"\n > OF U {e*b"[n > 0} and is not accepted by any deterministic PDA (© Lisnot accepted by any Turing machine that halts on every input () L= {a"|n > 0} U {a"b"|n > O} and is deterministic context-free 3. Design a PDA for accepting a language {ab o° | n: 4. Design a PDA for accepting a language {a?b# c [p+ 0}.Prcvlems on PDA Design a L=fo™e™|naih. pushdawr autamator. ushide aceopls Soln* ay &. € 8 © stepi2 Construction Logic zany ndf ols : per qutomata ta? « ey Sor each. ‘Asad pop 2ath Tal. Sten :3 Rules | S(4», a, Ze) = Sl4097) $(40%0) = S040 a2) S(4o bay = §Can &) S4q1% + §(4 S(4£,2%2) = S40) Step:4 Defining 1 tuples @s t Te 4,1 Ig} Z = fap} r La faz.) § = as dofined above. a, & 4 a gud 4stop:s Gaapricol acpsentaion «=f PDA a,20/920 bale sales Step:b Demo lebas Gondidex ot stay Ae ote $qo, aabb, 20) F $ (40, abe, 020) t $ C40 2, aaze) + §C4,/ 220) F&(4i, & 22) b §(45>&20) F Cy 20) The Shing aabb iw accepted toy the. PDA @® Design a PPA which actors eqyal. ne-4, as art bs oer £2 far} Soln : Step Constructing automate. ae a é Step:2 Consiwuttion ogic x push the fist iP Synbs Caither oo » * tod the next Symboot, Cif ty are some push, else pop) teStep: 3 Rules 2 Starting T§ ilp=? $ (40 ,0/20) = §(4o, a2) yy? : Laval of web — §(qo,,20) = 8 (Lo b22) if Ups g(q,,a, 0 = S (4, 09) | We =* $Ca_ ab) = 8 (10%) = pea g(4o,b = Sl408) LJ web S4e, Bb) = § C40, Hb) $(d0.€-20) = § (4g, 22) uy Step:4 Defining 1 tuples bana «ad Fo2%o Ba lawah Fe ful {Snitial Sade Symoal) S$ = as Aotined aboe Steps Graphical aepeosentaisn 4 PPA a, jade a blé b,Zolb20 bal& a) alan by pIBL Step:b Demo Consider He string w= abbaab YG , abbaab, Ze) + 5C40; bbaah, ae) F SC4., boob, 0) + £40. dab. b20F othe, ab, Zo) F §(%40,b, 020) + $45. &, 2) § (45,22) “. The string abbaah u accepted by PDA a (=> Design, a gpa which. accopls L= Lwew| w & (arb) Sohn Step: | Cons tructering automata ab aie oe ge Step: Constructing Logic For Of no.d ales : push For Symbol c : nO operation, Change State For other als bb's : pop Ceate a,b) Step:z Rules " EG. 1A, Zo) C40, 970) 5(40, ©/%0) = (qo, be) 8(40/912) = (4,00) $ (40,015) = (40, ab) $ (40,642 = C4) §(401%) = qo, bb) S$(4o0,6120)= C4), 20) $C40,C,a) = (4,2) Sloe) = C40§ (4% 9 = C44) §(4,/) = €4,,©) S(4,,€,2)= CY) Z0) Step:4 Defining 1 tuples B= {F445 Z = fab S= q@ Astral sn step3 Jo = f4oh Zo= F209 E> tay} Step:s Graphical acpicsentation \ 2, Ze laze g, aloe bralee a, ble oe cetad aale b, 20 %4, as, 2e\°2%, (4) ——"—___s/G € Zl e, bb Ghesesy (y) C, 2120 See 6 pemo censtdon “the Stang © = abe bo 5 (40, abtka, 2) +5 (4o,bcbe, 220) +5040, cha, 220) +09), ba, bore) +$C,,4%, A222) $$C 9) &: Zo) + $(4a/€ 120 ; $C 42,20 ~The ip Abing abcha is BDA ig actapted by the.yw exses! pee D Design & PDA bide acceplt UL = Late%c* | n201. 5 Geek A that aciopl she. Aanguoge Le alle” | \ =i 4], ijzes wide attests L= fal bY c™] pmarl 3) Const ag PDA which accept U= § TPT] wd aD Design @ PPAThe Aanguage fo BDA _ We Rave. ausumad thot PPA Sie a vi by conguming TL and entering an aciopting stato calttnis — approach. “accaptania by final Stole! There is a 24 appicach ces Aofinfing, the language 4, a PDA that hax on fmportant application . He may alto a Aojne for any ppa tae —Ranquage * accepted by emply stack ine the set oy shrings that came the PPA to empty its Stake, Stosing "som sha tnital We These 2 metheds aw aqyfvatent, in te send that « language Lhasa Ppa that aceopts it by final state. Yee has a PPA Hat accoplh ft by empty stack > 1 Acceptance bg Sral. sinte Leb P= (Q 4,71, $140,206) be a PDA. Thon LCP) the fanguage accopted by a P by frab state 1%, fu| (1) W 20) im (4,4) 5- Wresez TEF oo. stock string 7 EAeceptance Fy Rawls. Stak ili aie For each PDA P=, 4, 1, $,dor Zor F), We Asfine NCP) = Sus] C40 0 20) p& Cee, 0}. Jor amg State 4. That , Cp) is tha sek 4 inpuls « Pat Po can consume and at the amp time emply Pls stack Isiets, 2d, sie li wales, Thoovern? TZ L=NCPy) for Soma PDA Py = COZ, MSP) thon thre igs a PDA R Suth tok L= UCPr) Fesot The — specification 4 fe is as follows : Fe = (QUI ay x, Nv tel, Se, B, xe. fs) whee Se i okofined by, O % Ch.e,%) = fC4e20%)} Tn this state, Pr makes & Spontaneous transfHion 4o tra” state 4 Pu, Pun We stat symbol 2, amto te stat: @) For ak states q ih @, inpuls ‘o' mm Elo) as & and suas Symbols Y in 7 & (gray) contains all the pees be Sulge y) Tr adketition. to auto (1), Se (LZ, €, x.) Contains Fe.) So every state gin Q EAS €, Xe[Zo%o Star 7) AD Ex WD Find the ecgqutvalent PDA +t accepts bay final state foo the following PDA that accepts by empl, Sack - Solni gee vale 2 0,2 /)Az UAzlez OFlaAa 1 RIRRfy = (fat, fod, S2,08} Sa, % 2) now dofing fe af 14,2. %4, So, g2, % eh, Se.P,%4) Whee Sf i dofinod as. O Sopa = 4257 ® §,04,02) = 04,42 SCUNA = CBD Se0%,OrA) = C4, AA) S°0%0/89) = CHE) SeCUua) = (46) Se C48) = C4,88) Se4,42) ~ Cu ©) ® S2la,64) = (4,6) ory one stale fog, in. @ >}. bottom 4, the stack Faom. final state fe mel. state A Theorems Let 1 be LC) for Some PPR (e227, S#, Ver%o, F) Then, tres ls a PDA Py such that L= RCP) Proof Let ue (Qo srr, Z, MU Fx}, Su, Pos %)Where Sn is Aetined by, O Si Chien) = fe,Zoxe)}, WE start by pushing the ston Symbol 4 fe onto. the sinth ahd going tothe stort state 4 @® For ay states ¢ in Q input Symbols a fn € or are and Y mT, Sy Carary) contains exon pair Thal is in 5 (4,41y) That it Py simelater %. @ Fr at Attepting states qn Fand stack Symbols Vial Or ake *ey (a,2,y)" dontains (p6). By this aule , whenae Fe accols, Ban Start amptying ths stack male Consuming any move. byp. ® Fo al stak symbo Y an Th x Vere, Sp(REy=! $070}. One in the state P, which only occars when R tas accepted, Pr pops every Symbols on Us stack, until the stack is emply. fle fectrer ijp 8 Consumed) . ‘J. Find a PDA Pp, such that LCh) =NCP): no P accept by final state What P accops by emphy Stack Where Sp iy gen by, P= {aad fot dxnet, 8, 0, 2,{2f) 8 l4e,0,2) = (4,2) 3 Choi BZ) = C12) $(40,% x) = (4,,€) SCI *) = CG, xx 5 (4y,1,2) = ny SC4,0) = Ch ryy) 54, wy) = (4 €) 10,2) C4, yz) IsSol nr Lek as define Py = CQV EMPL, Z, TUE Keb, Sos Xe) Where, Sy is Aofinad ® £n Cho Xo) = Ge 2xe) by Ave ® by cule (2) $n (40, 0,2) = C4, 2) En 4oru2) = C4o/X2) En 040,0,x) = 4%) OnCQort, x) = C4—r**) nla, 0/2) = (4,2) 500 4,,1,2) = G42) & (4, oY) > (avy) Su(@ hy)» (4,2) by alts) for all ateopting states, ere, Pel ues by ut) = Cpe) Sn Ger y) = CRS) Salts t, = (60 @ whew. we EN Y) = Cre) ENCHE2)= CRO)Non Deterministic Pushdown automata The Non-deterministic Push down Automata (NPDAs) are like finite automata (FA), except they also have a stack memory where they can store an arbitrary amount of information. It is more powerful than a deterministic PDA. => Formal Definition of NDPAs_ Pushdown automaton M is formally defined as a 7-tuple M = (Q, ,F, T, q0, 1, F) where, + Qis the finite set of states Lis the finite set of input alphabet q0 €Q isthe initial state F ¢ Qiis the set of final states T is the stack alphabet, specifying the set of symbols that can be pushed onto the stack Lis the start stack symbol (1 € T) + Tis the transition function: T:QxDU{A}xP >I xQ Difference between NPDA and DPDA: DPDA(Deterministic Pushdown Automata) NPDA(Non-deterministic Pushdown Automata) Itis less powerful than NPDA. It is more powerful than DPDA. It is possible to convert every DPDA to a corresponding NPDA. Itis not possible to convert every NPDA to a corresponding DPDA. The language accepted by DPDA is a subset of the language accepted by NDPA. The language accepted by NPDA is not a subset of the language accepted by DPDA. The language accepted by DPDA is called DCFL (Deterministic Context-free Language) which is a subset of NCFL(Non-deterministic Context-free Language) accepted by NPDA. The language accepted by NPDA is called NCFL(Non-deterministic Context-free Language). => NPDA is more powerful that 2 NOPA is more powerful than DPDA because * we can add more transitions to it. It is possible for every language to add a transition. This is more powerful when it accepts more sets of languages than other automata.‘© In fact, it is more powerful than DFA(Deterministic finite automata) and NFA(Non- deterministic finite automata) also because, In the case of DFA and NFA, they are equivalent in power. So for every language accepted by DFA there exist an NFA and Vice-Versa. There is not any language for which we construct NFA but not DFA. Hence, we can't convert NPDA to DPDA always and we can convert NFA to equivalent DFA always. Equivalence of pushdown automata and CFL. > Application This equivalence allows a CFG to be used to specify a programming language and the equivalent PDA to be used to implement its compiler. > Equivalence of PDA's and CFG’s _ “The goal is to prove that the following three classes of the languages are all the same class. 4. The context-free languages (The language defined by CFG’s). 2, The languages that are accepted by empty stack by some PDA 3. The languages that are accepted by final state by some PDA. If agrammar G is context-free, we can build an equivalent nondeterministic PDA which accepts the language that is produced by the context-free grammar G. A parser can be built for the grammar G. Also, if P is a pushdown automaton, an equivalent context-free grammar G can be constructed where L(G) = L(P) In the next two topics, we will discuss how to convert from PDA to CFG and vice versa. — = Algorithm to find PDA corresponding to.a given CFG al Input - A CFG, G = (V, T, P, S) Output ~ Equivalent PDA, P = (Q, 5, §, 3, do, |, F) Step 1 - Convert the productions of the CFG into GNF. Step 2 - The PDA will have only one state {a}. Step 3 - The start symbol of CFG will be the start symbol in the PDA. Step 4 — All non-terminals of the CFG will be the stack symbols of the PDA and all the terminals of the CFG will be the input symbols of the PDA. Step 5 — For each production in the form A—> aX where ais terminal and A, X are combination of terminal and non-terminals, make a transition 6 (q, a, A). a2pacoiems on. Cenvarsise «= from CFG to PDA Convert, the fellsuing cra tbs ib aquflant PDA. PP: I= o|b) Tal Sol Tol S E> z)exe) exe) Ce) @ vefiel, Fer cad AT, 5 (44/2) = Sea, Cab), rte), C4 TH), 40), ca n)) SLED = § tex), tg, er), Ca ERE), (4, te) G@Dror cod terminals Te fa, bot, *,43, 65 8l4,a0 2 (40) 6(@,5>6) = ae 5(4,0,0) = (€) $4, 41) = (w¢) 5(4,C,0) = ¢@,€) 8(4,%-) = (46) 8(4,%, *)> (a,¢) _ Sette) = fe) @ 7. o = eh, 2 fa,bo,1, #3,4,64 bo>tdof n if acone. D,%, 4h mtConvert the foun ny ore mo equivalent rs FS 33a) as] pss)
1a Exercises Genvert dee sollosing, cra s mito PDAS eae abl ba, pvolas)ba, 8? bibs laBa- 25 Asal ab) SS AD aalA B> belA ww yee) C2) E>» Tlert © > Tolteste ti\a@lb osFuem PDp's jo vomners — New we complete the pregfs aquivalona by ung thot ooy PPA P We wr find a ert = pang: 4 sare ranguoge that P acceph & emery Atack - Theorem Let Miz [8,2 8, 1,40, 201 be @ PDA Tho Thom to CFO G Such that LCG) = NGM) Proo} woe anak — Const auc G: (vy, £,2, 4), whore the seb d, varfables VY omstt 4, 0 Fhe spacial Symbd S, which i¢ He stark -symbcl, and ~ AL symbde 4 the doom Lpxq]}, where P and q are Slates in Q, and k is A Stack Symbol in 1 Jho productions 4 6 ce as follacss (o> The productions for Atort Symbol § ve given by, Aor eath. State pin & tke with S—> [4 20F] & For each move thak pops a symba pom la transition. az |OCT, % Ze) = (4.4) Mrekudes tho Puodustin os, £ 420q'J pa pop Symbols prom 222294 © Fe each, move +that doesnt Stack within trauition as $4) a, 26) > (4, indude oa production as, 0.4'20q"] > 2 [4-4] 04.2.4) [12724) for eoth. ag” Ph oe LGm2m4 |After dosining all the ardes, apply simplification. 4 qpommert to gek Acdurcod greene ~ Geer LC 20P) "> wy yicawiz.) K CRO be Thus LCG) = Nlm) ys ™ atoph Wb ampty eee perbems gn PDA bo EPG ty Convert tha PDA P= ( {Rat fol, Lxzh SL to cr whew § is qrer bY » $(ayaey) = 4 Ca,Xaeyh 2 SCI xX) = £ Ca,xxdf 3 $04,0,x + § ¢p,x)} 4 Slax - £ €4,£9) = SCHL = Fepeys & S(Ro,2) = $ Ca,20)4 Solution The Variables ate: ©) Special symbol ¢, is the
[42,71 © oy f la,arxX) acntaink the paix Cr, Y, YoY) then ptoduckon. is quer by Carry a [ry rl ye wah Lye, Yer) “We have fo @ > [42.P) S> [420 4] Mle have for by ® $4,120) = § Ca, ee) J [120° = sp axa} re zee] £4204] = 'T2% PIL pan 6y [425 q+ 4 Lax) £4 20?) [4209 * 4 Caxel £ p204) M Slax) = € car} Caxp) = 4 Caxq\Caxh) Cexed = 4 Caxrdcpred 4, Et — | Laxey cara) cane) = irqaw £ (ae) = CAD) La xP] > orpxp) [4 xa\> oLpxa] W s(q,¢0 = flees (Caxayrey wy S (Px) =f cred (pxp) =) “Seda « £ 4,20) § [P 204] = 0£¢ 24) CP 2.9) = oLa2o8) Sas Heanotrex Example [Problem Construct a PDA from the following CFG. G =({S, X}, {a, b}, P, S) where the productions are — S—XS|e,A— aXb| Ab] ab Solution Let the equivalent PDA, P = ({q), {@, b}, {a, b, X, S), 3, 4, 8) where 5 — (a, € , S) = (4, XS), (a, € )} (a, € , X) = {(q, aXb), (q, Xb), (4, ab)} (a, a, a) = {(a,£)} (a, 1, 1) ={(.£)} Algorithm to find CFG corresponding to a given PDA Input - A CFG, G =(V,T, P, ) Output - Equivalent PDA, P = (Q, 5, S, 5, qo, |, F) such that the non- terminals of the grammar G will be (Xwx | w,x € Q} and the start state will be Ago. Step 1 — For every w, x, y, 2 € Q, m€ S anda, b € 5, if 5 (w, a, €) contains (y, m) and (2, b, m) contains (x, €), add the production rule Xue —» a Xyab in grammar G. Step 2 - For every w, x, y, Z € Q, add the production rule Xx —> XwyXyx in grammar G. ‘Step 3 — For w€ Q, add the production rule Xw — € in grammar a) 4Pumping lemma for CFL ‘The pumping lemma for context-free language is used to solve that language is not a context-free language. what i a context-free language? ‘Acontext-free grammar generates context-free languages (CFLs). The set of all context- free languages is the same as the set of languages accepted by the pushdown automata. The set of regular languages is a subset of context-free languages. Pumping Lemma for CFL states that for any Context-Free Language L, it Is possible to find two substrings that can be ‘pumped’ any number of times and still be in the same languags We break its strings into five parts for any language L and pump the second and fourth substring, If any string does not satisfy its conditions, then the language is not CFL. If Lis a context-free language, there is a constant 'n’ that depends exclusively on L, such that if w? L and |w{ >= n, w can be divided into five pieces, w = uvxyz, meeting the following requirements. + [yxyl>sn > lite + Forall k>=0, the string uv‘xy’zeL Steps to apply pumping lemma + Assume that L is context-free. + The pumping length will be n. + All strings longer than the length(n) can be pumped-> |w>=n. «Now we have to find a string 'w’ in L such that |wl>=n. + We will divide string 'w' into uvxyz. + Now show that uvéxyiz @L for some constant k. «Then, we have to consider the ways that w can be divided into uvxyz. «Show that none of these can satisfy all the 3 pumping conditions simultaneously. + Astring 'w cannot be pumped (contradiction).Intersection and complementation : IFL1 and If L2 are two context free languages, their intersection L1 N L2 need not be context free. For example, Lt = (arb’c™ | n >= 0 and m >= 0} and L2 = (ambre" | n >= 0 and m >= 0} L3=L1 1 L2={a%b%o" | n >= 0 } need not be context free. L1 says number of a's should be equal to number of b’s and L2 says number of b's should be equal to number of c's. Their intersection says both conditions need to be true, but push down automata can compare only two. So it cannot be accepted by pushdown automata, hence not context free. Similarly, complementation of context free language L1 which is 5*—L1, need not be context free. Note : So CFL are not closed under Intersection and Complementation. 4Closure Properties of Context-Free Languages under different operations Context Free Languages (CFLs) are accepted by pushdown automata. Context free languages can be generated by context free grammars, which have productions (substitution rules) of the form ‘A->p (where A € Nand p € (T UN)* and N is a non-terminal and T is a terminal) Properties of Context Free Languages Union : If Lt and L2 are two context free languages, their union L1 U L2 will also be context free. For example, Lt = {aPb°o" | m >= O and n >= 0} and L2 ={a%b"c" | n >= 0 and m >= 0} L3=L1 UL2=(a"b'c™ U ab"c" | n >= 0, m >= 0 Fis also context free. Lt says number of a’s should be equal to number of b’s and L2 says number of b’s should be equal to number of c's. Their union says either of two conditions to be true. So itis also context free language. Note: So CFL are closed under Union. Concatenation : IfLt and If L2 are two context free languages, their concatenation L1.L2 will also be context free. For example, L1={anbn |n>=0}and L2={cmdm|m>=0} L3 = L1.L2 = { anbnomdm | m >= 0 and n >= 0} is also context free. Lt says number of a’s should be equal to number of b’s and L2 says number of c's should be equal to number of d's. Their concatenation says first number of a’s should be equal to number of b's, then number of c’s should be equal to number of d’s. So, we can create a PDA which will first push for a’s, pop for b's, push for c's then pop for d's. So it can be accepted by pushdown automata, hence context free Note: So CFL are closed under Concatenation. Kleene Closure : If L1 is context free, its Kleene closure L1* will also be context free. For example, Lt ={arb"|n>=0} ab" | n >= 0 }* is also context free. Note :So CFL are closed under Kleen Closure.Frebloms on jpemies Asrnma fer CFLs:- ore] O Use ik prove that the danquage L=f cFL, the pumping Jemma. n>} is nok Soln q Gwen L= f ot™2™| noi} L= for, coma, coomza2.... f @ Let whe any constant Calue) for the language given © Consider a String 2 = cool 222. @) Brak 2 > Uvw xyz fe 2 = 00 Jol] mn} 2a fa U=00 =o) yee veal Xe od w Vise, vlun ny ra Coodtoy ci) taa7 a f-0 coe!) 1 (22) 2 =0ONn2 &L The given. Janguoge Le fo Jans Jes ns Context free . ant ae (> Show Het ape Languoge L = Lo"ln is a primal is net context. foo darquoge.. 3 San: Given. fe. ©0, 000, O0000, 0090000, Oo00cE0e000... | L= got |n Be prime} {ne nssai3..d ai2 for tha. given Language- W@W Leb n be Some Senstant 2 a oc0oo EL Gm Gnstder a stingy 2 = 00000 OPFENDING-COMGNBimage sence (W Bacak Z>= uvwryz jee 7 O° Tot tT use = ©8089 — y=00 vr00 &=00 = eae = e @ Vise Uv wD wy eu © (00)(00e)(00) 00 ize Covcceeo EL fel, é 1 Ce)Cee)ecce) Coo) cos) OC00DeC0008 EL. ° 2 2 bea, Co) Cee) Coen) (oc) coo) © 8e00 C000 Ccee 0o EL The given Language Le Soh|n ig gq pumas le not Conbexk free. Exercises WoL fahynt a>
You might also like
Automata ch4
PDF
No ratings yet
Automata ch4
13 pages
TOC Lecture 13
PDF
No ratings yet
TOC Lecture 13
19 pages
Pushdown Automata
PDF
No ratings yet
Pushdown Automata
12 pages
At Module-4
PDF
No ratings yet
At Module-4
17 pages
Toc - Unit-4 Pushdawn Automata
PDF
No ratings yet
Toc - Unit-4 Pushdawn Automata
54 pages
chapter-4-PushDownAutomata.pptx
PDF
No ratings yet
chapter-4-PushDownAutomata.pptx
65 pages
Pushdown Automata (PDA) : UNIT-4
PDF
100% (1)
Pushdown Automata (PDA) : UNIT-4
16 pages
Flat Unit-4
PDF
No ratings yet
Flat Unit-4
24 pages
Pushdown Automata
PDF
No ratings yet
Pushdown Automata
5 pages
Vision 2022 Toc Chapter 6 Pushdown Automata 15
PDF
No ratings yet
Vision 2022 Toc Chapter 6 Pushdown Automata 15
10 pages
Unit 4 - Theory of Computation - WWW - Rgpvnotes.in
PDF
No ratings yet
Unit 4 - Theory of Computation - WWW - Rgpvnotes.in
14 pages
Unit-5 Push Down Automata
PDF
No ratings yet
Unit-5 Push Down Automata
47 pages
Chapter-4-pushdown-modified (2)
PDF
No ratings yet
Chapter-4-pushdown-modified (2)
12 pages
Unit-3 TOC
PDF
No ratings yet
Unit-3 TOC
20 pages
Unit - 3 Second Half-PDA
PDF
No ratings yet
Unit - 3 Second Half-PDA
16 pages
Pushdown Automata
PDF
No ratings yet
Pushdown Automata
8 pages
Push Down Automata
PDF
No ratings yet
Push Down Automata
13 pages
Chapter 5 PDA
PDF
No ratings yet
Chapter 5 PDA
107 pages
Pushdown Automata - 2 May
PDF
No ratings yet
Pushdown Automata - 2 May
10 pages
Flat (Unit IV)
PDF
No ratings yet
Flat (Unit IV)
25 pages
Pushdown Automata
PDF
No ratings yet
Pushdown Automata
11 pages
Unit-Iv: Pushdown Automata (PDA)
PDF
No ratings yet
Unit-Iv: Pushdown Automata (PDA)
9 pages
Pushdown Automata
PDF
No ratings yet
Pushdown Automata
29 pages
Unit 4 - Pda-Basics
PDF
No ratings yet
Unit 4 - Pda-Basics
7 pages
202005121135047143pankaj-Unit 4 Notes PDF
PDF
No ratings yet
202005121135047143pankaj-Unit 4 Notes PDF
35 pages
toc 3
PDF
No ratings yet
toc 3
36 pages
Unit 3 - Pda
PDF
No ratings yet
Unit 3 - Pda
52 pages
Pushdown Automata
PDF
No ratings yet
Pushdown Automata
16 pages
Automata
PDF
No ratings yet
Automata
26 pages
ToC Notes - Unit 3
PDF
No ratings yet
ToC Notes - Unit 3
10 pages
Automata - Unit 4
PDF
No ratings yet
Automata - Unit 4
19 pages
Class 19 Pushdown Automata
PDF
No ratings yet
Class 19 Pushdown Automata
35 pages
Pushdown Automata - Dalpat Songara
PDF
No ratings yet
Pushdown Automata - Dalpat Songara
49 pages
FLA Unit IV PDA
PDF
No ratings yet
FLA Unit IV PDA
16 pages
Pushdown Automata
PDF
No ratings yet
Pushdown Automata
23 pages
Pushdown Automata
PDF
No ratings yet
Pushdown Automata
8 pages
6 Pda
PDF
No ratings yet
6 Pda
35 pages
Notes 21
PDF
No ratings yet
Notes 21
7 pages
VNW - Ce - Toc - Un - 04 !
PDF
No ratings yet
VNW - Ce - Toc - Un - 04 !
26 pages
Automata ch4
PDF
No ratings yet
Automata ch4
7 pages
Pushdown Automata
PDF
No ratings yet
Pushdown Automata
7 pages
Pushdown Automata: Moves of The PDA Languages of The PDA Deterministic PDA's
PDF
No ratings yet
Pushdown Automata: Moves of The PDA Languages of The PDA Deterministic PDA's
33 pages
Bwu Bta 22-326 Chirantan Mondal
PDF
No ratings yet
Bwu Bta 22-326 Chirantan Mondal
9 pages
Unit V Push Down Automata
PDF
No ratings yet
Unit V Push Down Automata
59 pages
Toc 5 TH Unit Notes
PDF
No ratings yet
Toc 5 TH Unit Notes
43 pages
Pushdown Automata: Unity University Dept. of Computer Sci. SECTION: N1-2/12
PDF
No ratings yet
Pushdown Automata: Unity University Dept. of Computer Sci. SECTION: N1-2/12
49 pages
Section 12.2 Pushdown Automata
PDF
No ratings yet
Section 12.2 Pushdown Automata
9 pages
CS242_Module 6
PDF
No ratings yet
CS242_Module 6
42 pages
CS372 Formal Languages & The Theory of Computation
PDF
No ratings yet
CS372 Formal Languages & The Theory of Computation
43 pages
Chapter 5 - Pushdown Automata
PDF
No ratings yet
Chapter 5 - Pushdown Automata
22 pages
PDA6
PDF
No ratings yet
PDA6
22 pages
FL 4
PDF
No ratings yet
FL 4
43 pages
CMP3008 LN6 PushdownAutomata PDF
PDF
No ratings yet
CMP3008 LN6 PushdownAutomata PDF
38 pages
PDA
PDF
No ratings yet
PDA
52 pages
Pushdown Automaton
PDF
No ratings yet
Pushdown Automaton
8 pages
PDA-7 Tuple Machine
PDF
No ratings yet
PDA-7 Tuple Machine
23 pages
Introduction Pushdown Automata
PDF
No ratings yet
Introduction Pushdown Automata
9 pages
Pushdown Automata: Moves of The PDA Languages of The PDA Deterministic PDA's
PDF
No ratings yet
Pushdown Automata: Moves of The PDA Languages of The PDA Deterministic PDA's
32 pages
UNIT V PUSH DOWN AUTOMATA
PDF
No ratings yet
UNIT V PUSH DOWN AUTOMATA
51 pages
Unit V
PDF
No ratings yet
Unit V
30 pages
Unit Ii
PDF
No ratings yet
Unit Ii
38 pages
Unit I
PDF
No ratings yet
Unit I
24 pages
Unit Iii
PDF
No ratings yet
Unit Iii
42 pages