Automata ch4
Automata ch4
PDA Components:
Input tape: The input tape is divided in many cells or symbols. The input head is read-only and
may only move from left to right, one symbol at a time.
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.
Γ: a stack symbol which can be pushed and popped from the stack
δ: mapping function which is used for moving from current state to next state.
Turnstile Notation:
⊢ sign describes the turnstile notation and represents one move.
(p, b, T) ⊢ (q, w, α)
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 α.
Example 1:
Design a PDA for accepting a language {anb2n | n>=1}.
Solution: In this language, n number of a's should be followed by 2n number of b's. Hence, we
will apply a very simple logic, and that is 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.
Now when we read b, we will change the state from q0 to q1 and start popping corresponding 'a'.
Hence,
1. δ(q0, b, a) = (q1, ε)
Thus this process of popping 'b' will be repeated unless all the symbols are read. Note that popping
action occurs in state q1 only.
1. δ(q1, b, a) = (q1, ε)
After 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:
1. δ(q1, ε, Z) = (q2, ε)
Where
PDA = ({q0, q1, q2}, {a, b}, {a, Z}, δ, q0, Z, {q2})
Now we will simulate this PDA for the input string "aaabbbbbb".
Example 2:
Design a PDA for accepting a language {0n1m0n | m, n>=1}.
Solution: In this PDA, n number of 0's are followed by any number of 1's followed n number of
0's. Hence the logic for design of such PDA will be as follows:
Push all 0's onto the stack on encountering first 0's. Then if we read 1, just do nothing. Then read
0, and on each read of 0, pop one 0 from the stack.
For instance:
This scenario can be written in the ID form as:
Now we will simulate this PDA for the input string "0011100".
PDA Acceptance
A language can be accepted by Pushdown automata using two approaches:
1. 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, ∑, Γ, δ, q0, Z, F) be a PDA. The language acceptable by the final state can be defined
as:
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, ∑, Γ, δ, q0, Z, F) be a PDA. The language acceptable by empty stack can be defined
as:
o If L = N(P1) for some PDA P1, then there is a PDA P2 such that L = L(P2). That means
the language accepted by empty stack PDA will also be accepted by final state PDA.
o If there is a language L = L (P1) for some PDA P1 then there is a PDA P2 such that L =
N(P2). That means language accepted by final state PDA is also acceptable by empty stack
PDA.
Example:
Construct a 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:
We are going to design the first part i.e. 1 comes before 0'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 δ can be
Now, consider the second part i.e. if 0 comes before 1's. The logic is that read first 0, push it onto
the stack and change state from q0 to q1. [Note that state q1 indicates that first 0 is read and still
second 0 has yet to read].
Being in q1, if 1 is encountered then POP 0. Being in q1, if 0 is read then simply read that second
0 and move ahead. The δ will be:
The CFG which accepts deterministic PDA accepts non-deterministic PDAs as well. Similarly,
there are some CFGs which can be accepted only by NPDA and not by DPDA. Thus NPDA is
more powerful than DPDA.
Example:
Design PDA for Palindrome strips.
Solution:
Suppose the language consists of string L = {aba, aa, bb, bab, bbabb, aabaa, ......]. The string can
be odd palindrome or even palindrome. The logic for constructing PDA is that we will push a
symbol onto the stack till half of the string then we will read each symbol and then perform the
pop operation. We will compare to see whether the symbol which is popped is similar to the symbol
which is read. Whether we reach to end of the input, we expect the stack to be empty.
This PDA is a non-deterministic PDA because finding the mid for the given string and reading the
string from left and matching it with from right (reverse) direction leads to non-deterministic
moves. Here is the ID.
Simulation of abaaba
1. δ(q, ε, A) = (q, α)
Example 1:
Convert the following grammar to a PDA that accepts the same language.
1. S → 0S1 | A
2. A → 1A0 | S | ε
Solution:
1. S → 0S1 | 1S0 | ε
1. S → 0SX | 1SY | ε
2. X → 1
3. Y → 0
Example 2:
Construct PDA for the given CFG, and test whether 0104 is acceptable by this PDA.
1. S → 0BB
2. B → 0S | 1S | 0
Solution:
Example 3:
Draw a PDA for the CFG given below:
1. S → aSb
2. S → a | b | ε
Solution: