The Wayback Machine - https://web.archive.org/web/20240607083330/https://www.geeksforgeeks.org/pushdown-automata-acceptance-final-state/
Open In App

Pushdown Automata Acceptance by Final State

Last Updated : 30 May, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

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 any symbol left on the stack which can be depicted as:

L(P) = {w |(q0, w, Z) =>(qf, ɛ, s)}

Here, from start state q0 and stack symbol Z, the final state qf ɛ F is reached when input w is consumed. The stack can contain a string s which is irrelevant as the final state is reached and w will be accepted. 

Example: Define the pushdown automata for language {a^nb^n | n > 0} using final state. 

Solution: M = where Q = {q0, q1, q2, q3} and ∑ = {a, b} and Γ = { A, Z } and F={q3} and Îī is given by:

Îī( q0, a, Z ) = { ( q1, AZ ) }
Îī( q1, a, A) = { ( q1, AA ) }
Îī( q1, b, A) = { ( q2, ɛ) }
Îī( q2, b, A) = { ( q2, ɛ) }
Îī( q2, ɛ, Z) = { ( q3, Z) }

Let us see how this automaton works for aaabbb: 1 

Explanation: Initially, the state of automata is q0 and symbol on the stack is Z and the input is aaabbb as shown in row 0. On reading a (shown in bold in row 1), the state will be changed to q1 and it will push symbol A on the stack. On next a (shown in row 2), it will push another symbol A on the stack and remain in state q1. After reading 3 a’s, the stack will be AAAZ with A on the top. After reading b (as shown in row 4), it will pop A and move to state q2 and the stack will be AAZ. When all b’s are read, the state will be q2 and the stack will be Z. In row 7, on input symbol ɛ and Z on the stack, it will move to q3. As the final state q3 has been reached after processing input, the string will be accepted. This type of acceptance is known as acceptance by the final state. Next, we will see how this automata works for aab:

 2 

As we can see in row 4, the input has been processed and PDA is in state q2 which is a non-final state, the string aab will not be accepted. Let us discuss the question based on this: 

Que-1. Consider the transition diagram of a PDA given below with input alphabet ∑ = {a, b}and stack alphabet Γ = {X, Z}. Z is the initial stack symbol. Let L denote the language accepted by the PDA. (GATE-CS-2016)  

Solution: We first label the state of the given PDA as:

 3333 

Next, the given PDA P can be written as:

 Q = {q0, q1, q2} and ∑ = {a, b} 
And Γ = {X, Z} and F={q0,q2} and Îī is given by :
Îī( q0, a, Z ) = {( q0, XZ)}
Îī( q0, a, X) = {( q0, XX )}
Îī( q0, b, X) = {( q1, ɛ)}
Îī( q1, b, X) = {( q1, ɛ)}
Îī( q1, ɛ, Z) = {( q2, Z)}

As we can see, q0 is the initial as well as the final state, ɛ will be accepted. For every a, X is pushed onto the stack and PDA remains in the final state. Therefore, any number of a’s can be accepted by PDA. If the input contains b, X is popped from the stack for every b. Then PDA is moved to the final state if the stack becomes empty after processing input (Îī( q1, ɛ, Z) = {( q2, Z)}). Therefore, a number of b must be equal to the number of an if they exist. As there is only one move for a given state and input, the PDA is deterministic. So, the correct option is (D).


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
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
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 = {0n1m2(n+m) | m,n â‰Ĩ 0}
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: Ac
2 min read
Detailed Study of PushDown Automata
According to the Chomsky Hierarchy, the requirement of a certain type of grammar to generate a language is often clubbed with a suitable machine that can be used to accept the same language. When the grammar is simple, the language becomes more complex, hence we require a more powerful machine to understand the language and accept it. Example: Type
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
Practice Tags :