The Wayback Machine - https://web.archive.org/web/20240607081830/https://www.geeksforgeeks.org/construct-pushdown-automata-for-l-0n1m2nm-mn-%e2%89%a5-0/
Open In App

Construct Pushdown automata for L = {0n1m2(n+m) | m,n ≥ 0}

Last Updated : 29 Oct, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

Prerequisite – Pushdown automata, NPDA for accepting the language L = {ambnc(m+n) | m,n ≥ 1} PDA plays a very important role in task of compiler designing. That is why there is a need to have a good practice on PDA. Our objective is to construct a PDA which accepts a string of the form {(0^n)(1^m)(2^(n+m))} Example- 

Input: 00001112222222
Output: Accepted

Input: 00011112222
Output: Not Accepted 

Approach used in this PDA – There can be four cases while processing the given input string. Case 1- m=0: In this cases the input string will be of the form {0n2n}. In this condition, keep on pushing 0’s in the stack until we encounter with 2. On receiving 2 check if top of stack is 0, then pop it from the stack. Keep on popping 0’s until all the 2’s of the string are processed. If we reach to the end of input string and stack becomes empty, then reached to the final state i.e. Accepts the input string else move to dead state. Case 2- n=0: In this cases the input string will be of the form {1m2m}. In this condition, keep on pushing 1’s in the stack until we encounter with 2. On receiving 2 check if top of stack is 1, then pop it from the stack. Keep on popping 1’s until all the 2’s of the string are processed. If we reach to the end of input string and stack becomes empty, then reached to the final state i.e. Accepts the input string else move to dead state. Case 3- m, n>0: In this cases the input string will be of the form {0n1m2(n+m)}. In this condition, keep on pushing 0’s and 1’s in the stack until we encounter with 2. On receiving 2 check if top of stack is 1 or 0, then pop it (1 or 0) from the stack. Keep on popping 1’s or 0’s until all the 2’s of the input string are processed. If we reach to the end of input string and stack becomes empty, then reach to final state i.e. accept the input string else move to dead state. Case 4- m=0, n=0: In this case the input string will be empty. Therefore directly jump to final state.


Previous Article
Next Article

Similar Reads

Difference between Pushdown Automata and Finite Automata
Pushdown Automata: A Pushdown automata (PDA) is a finite state machine with an added stack storage. Additional stack is used in making the decision for transitions apart from input symbols and current state. It contains the following 7 tuples: Finite Automata: A Finite Automata is a mathematical model of any machine by which we can calculate the tr
2 min read
Construct Pushdown Automata for given languages
Prerequisite - Pushdown Automata, Pushdown Automata Acceptance by Final State A push down automata is similar to deterministic finite automata except that it has a few more properties than a DFA.The data structure used for implementing a PDA is stack. A PDA has an output associated with every input. All the inputs are either pushed into a stack or
4 min read
Construct Pushdown Automata for all length palindrome
A Pushdown Automaton (PDA) is like an epsilon Non deterministic Finite Automata (NFA) with infinite stack. PDA is a way to implement context free languages. Hence, it is important to learn, how to draw PDA. Here, take the example of odd length palindrome: Que-1: Construct a PDA for language L = {wcw' | w={0, 1}*} where w' is the reverse of w. Appro
6 min read
Construct Pushdown automata for L = {0<sup>n</sup>1<sup>m</sup>2<sup>m</sup>3<sup>n</sup> | m,n ≥ 0}
Prerequisite - Pushdown automata, Pushdown automata acceptance by final state Pushdown automata (PDA) plays a significant role in compiler design. Therefore there is a need to have a good hands on PDA. Our aim is to construct a PDA for L = {0n1m2m3n | m,n ≥ 0} Examples - Input : 00011112222333 Output : Accepted Input : 0001122233 Output : Not Accep
3 min read
Construct Pushdown automata for L = {a(2*m)c(4*n)dnbm | m,n ≥ 0}
Prerequisite – Pushdown automata, Pushdown automata acceptance by final state PDA plays a very important role in task of compiler designing. That is why there is a need to have a good practice on PDA. Our objective is to construct a PDA for L = {a(2*m)c(4*n)dnbm | m,n ≥ 0} Examples - Input: aaccccdb Output: Accepted Input: aaaaccccccccddbb Output:
3 min read
Construct Pushdown automata for L = {0<sup>m</sup>1<sup>(n+m)</sup>2<sup>n</sup> | m,n &ge; 0}
Prerequisite – Pushdown automata, NPDA for accepting the language L = {amb(n+m)cm | m, n &gt;= 1} Problem: Construct Pushdown automata for L = {0m1(n+m)2n | m,n &ge; 0} Example: Input: 011122 Output: Accepted Input: 00000112222 Output: Not Accepted Approach used in this PDA – There can be four cases while processing the given input string. Case 1-
2 min read
Construct Pushdown automata for L = {0<sup>(n+m)</sup>1<sup>m</sup>2<sup>n</sup> | m, n &ge; 0}
Prerequisite – Pushdown automata Problem: Construct Pushdown automata for L = {0(n+m)1m2n | m, n &ge; 0} Similar PDA's- This PDA seems to be similar to PDA of S2 = {0m1(n+m)2n} but the production is different. S2 will produce output which have no of 1's equal to the sum of no of 0's and 2's, while S1 does not. This PDA seems to be similar to PDA of
3 min read
Construct Pushdown automata for L = {a^n b a^2n | n ≥ 0}
Prerequisites: Introduction of Pushdown AutomataConstruct Pushdown Automata for given languagesProblem- Construct PDA for the language L = {anba2n | n ≥ 0}. This means the PDA should have twice as many as a's after b than before b, and there should be one and only one b. Examples: INPUT : aaabaaaaaaOUTPUT : AcceptedINPUT : aaaaabaaaaOUTPUT : Reject
1 min read
Introduction of Pushdown Automata
We have already discussed finite automata. But finite automata can be used to accept only regular languages. Pushdown Automata is a finite automata with extra memory called stack which helps Pushdown automata to recognize Context Free Languages. A Pushdown Automata (PDA) can be defined as : Q is the set of states∑is the set of input symbolsΓ is the
4 min read
Pushdown Automata Acceptance by Final State
We have discussed Pushdown Automata (PDA) and its acceptance by empty stack article. Now, in this article, we will discuss how PDA can accept a CFL based on the final state. Given a PDA P as: P = (Q, Σ, Γ, δ, q0, Z, F) The language accepted by P is the set of all strings consuming which PDA can move from initial state to final state irrespective of
4 min read