Pushdown Automata - 2 May
Pushdown Automata - 2 May
FSM has very limited memory but PDA has more memory.
In a specified state, PDA will read the symbol which is at the top of the stack and the input
signal and move to a new state after changing the symbol of the stack.
DPDA
DPDA: For every input with the current state, there is only one move.
δ: Q*∑*Γ→Q*Γ
Non-Deterministic PDA
For every input with the current state, We can have multiple moves.
Difference between NPDA and DPDA:
S. NPDA(Non-deterministic
No DPDA(Deterministic Pushdown Automata) Pushdown Automata)
A PDA is said to be deterministic if all the derivations in the design have to give only a single
move.
Example 1:
DPDA for L
On the state q0, if the input symbol is a and the stack top is z, or a. we push onto the stack.
On the state q0, if we see the input symbol b, we are moving to state q1 and doing no operation.
On state q1, if we see the input symbol b, we pop the element from the stack because we have
seen the second b.
We move to state q2. and loop on to state q1 for every second occurrence of b.
On the state q2, if the input symbol is epsilon, move to the final state.
Deterministic Push Down Automata for a^n b^n
First we have to count number of a's and that number should be equal to number of b's.
That we will achieve by pushing a's in STACK and then we will pop a's whenever "b" comes.
So in the end of the strings if nothing is left in the STACK then we can say that language is
accepted in the PDA.
Let either 'a' or 'b' push in STACK. That means if 'a' comes first let it push.
After 'a' if again 'a' comes then let push it.
If 'b' comes first, push it in STACK ('a' did not come yet)
If again 'b' comes then push it in STACK.
Now if 'a' is present in top of STACK and 'b' comes then, pop 'a'
Similarily if 'b' is present in top of STACK and 'a' comes then, pop 'b'
So in the end of the strings if nothing is left in the STACK then we can say that CFL is
accepted in the PDA.
We have designed the PDA for the problem:
δ(q0, ε, Z) = (qf, Z)
Explanation
Lets see, how this DPDA is working:
We will take one input string: "aabbbbaa"
Example :
The reverse of 011 is 110. After the symbol c, we need to have the reverse of w.
The logic is simple. whatever we find before the symbol c we need to push onto the stack
After the symbol c, the first input should match the stack top. Because we need reverse of w.
After the symbol c, if the input symbol and stack top are the same, we do the pop operation.
The below diagram shows the DPDA for the language L1.
DPDA for L1
On the state q0, whatever we see, we need to push on to the stack.
On the state q0. If the input is c, move to state q1. Because from now we need to check for
reverse
on the state q1 if the input symbol and the stack symbol are the same pop the element.
On the state q1, if the input is epsilon and the stack top is z, we move to the final state.
NPDA
Problem: Design a non deterministic PDA for accepting the language L = {wwR w ∈ (a, b)+},
i.e.,
Explanation: In this type of input string, one input has more than one transition states, hence it
is called non-deterministic PDA, and the input string contain any order of ‘a’ and ‘b’. Each
input alphabet has more than one possibility to move next state. And finally when the stack is
empty then the string is accepted by the NPDA. In this NPDA we used some symbols which
are given below:
Γ = { a, b, z }
a = input alphabet
b = input alphabet
The approach used in the construction of PDA –
As we want to design an NPDA, thus every times ‘a’ or ‘b’ comes then either push into the
stack or move into the next state. It is dependent on a string. When we see the input alphabet
which is equal to the top of the stack then that time pop operation applies on the stack and
move to the next step.
So, in the end, if the stack becomes empty then we can say that the string is accepted by the
PDA.
Delta is transition
qf = Final state
Example:
We will take one input string: “abbbba”.