Toc - Unit-4 Pushdawn Automata
Toc - Unit-4 Pushdawn Automata
BY
MR. VIPIN WANI
UNIT 4
➢ Pushdown automata is a way to implement a CFG in the same way we design DFA for a
regular grammar. A DFA can remember a finite amount of information, but a PDA can
remember an infinite amount of information.
➢ Pushdown automata is simply an NFA augmented with an "external stack memory". The
addition of stack is used to provide a last-in-first-out memory management capability
to Pushdown automata. Pushdown automata can store an unbounded amount of
information on the stack. It can 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.
➢ A 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.
PDA Components:
1. 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.
2. Finite control: The finite control has some pointer which points the current
symbol which is to be read.
3. 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.
The following diagram shows a transition in a PDA from a state q1 to state q2, labeled as
a,b → c −
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 α.
Prepared by: Mr. Vipin Wani
Examples on PDA
9
➢ δ (q0, b, a) = (q1, ε)
➢ δ (q1, b, a) = (q1, ε)
➢ Example 1:
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’ two 'a' should get
popped from the stack. The Instantaneous Description for this example can be given as
➢ δ (q0, b, a) = (q1, ε)
➢ δ (q1, b, a) = (q1, ε)
➢ Solution: This is a language of equal numbers of a’s and equal numbers of b’s.
Initially when stack is empty we may read either a or b, we will push any of the
symbol on the stack. If read a or b when stack is having the same element at top
then we will push the element on stack. Now if we read a and the top of the stack is
b then we will pop b from the stack similarly if we read b and the top of the stack
is a then we will pop a from the stack.
➢ Example 5:
5. δ (q0, a, b) = (q0, ε)
6. δ (q0, b, a) = (q0, ε)
again followed by n number of 0s. To construct PDA for this raed 1st zero and push
it to stack, on reading 1s do nothing and on reading last zero pop zero.
3. δ (q0, 1, 0) = (q1, 0)
4. δ (q1, 1, 0) = (q1, 0)
5. δ (q1, 0, 0) = (q1, ε)
➢ 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: L(PDA) = {w | (q0, w,
Z) ⊢* (p, ε, α), p ∈ F}
➢ On Reading the input string from the initial configuration for some PDA, the stack
➢ 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.
➢ 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 1: Design a PDA for accepting a language via Empty Stack {anbn | n>=1}.
➢ δ (q0, b, a) = (q1, ε)
➢ δ (q1, b, a) = (q1, ε)
➢ Example 1:
➢ Solution:
➢ R1: δ (q0, a, Z0) = (q0, aZ0)
➢ R2: δ (q0, b, Z0) = (q0, bZ0)
➢ R3: δ (q0, a, b) = (q0, ab)
➢ R4: δ (q0, b, a) = (q0, ba)
➢ R5: δ (q0, a, a) = (q0, aa)
➢ R6: δ (q0, b, b) = (q0, bb)
➢ R7: δ (q0, b, b) = (q1, ε)
➢ R8: δ (q0, a, a) = (q1, ε)
➢ R9: δ (q1, a, a) = (q1, ε)
➢ R10: δ (q1, b, b) = (q1, ε)
➢ R11: δ (q1, ε, Z0) = (q2, ε)
Prepared by: Mr. Vipin Wani
Non Deterministic PDA (Example)
32
q0 q1 q2
(a, a, ε) (ε ,Z0, Z0)
(b,b, ε)
(a, a,aa)
(b,b,bb)
(a, b,ab)
(b,a,ba)
➢ Solution:
➢ R12: δ (q0, b, b) = (q1, b)
➢ R1: δ (q0, a, Z0) = (q0, aZ0)
➢ R13: δ (q1, a, a) = (q1, ε)
➢ R2: δ (q0, a, Z0) = (q1, Z0)
➢ R14: δ (q1, b, b) = (q1, ε)
➢ R3: δ (q0, b, Z0) = (q0, bZ0)
➢ R15: δ (q1, ε, Z0) = (q2, ε)
➢ R4: δ (q0, b, Z0) = (q1, Z0)
➢ R5: δ (q0, a, b) = (q0, ab)
➢ R6: δ (q0, a, b) = (q1, b)
➢ R7: δ (q0, b, a) = (q1, ba)
➢ R8: δ (q0, b, a) = (q1, a)
➢ R9: δ (q0, a, a) = (q0, aa)
➢ R10: δ (q0, a, a) = (q1, a)
➢ R11: δ (q0, b, b) = (q0, bb)
Prepared by: Mr. Vipin Wani
Non Deterministic PDA (Example)
36
➢ The first symbol on R.H.S. production must be a terminal symbol. The following steps are
used to obtain PDA from CFG is:
➢ Step 1: Convert the given productions of CFG into GNF.
➢ Step 2: The PDA will only have one state {q}.
➢ Step 3: The initial symbol of CFG will be the initial symbol in the PDA
➢ Step 4: For non-terminal symbol, add the following rule:
δ(q, ε, A) = (q, α)
Where the production rule is A → α
➢ The first symbol on R.H.S. production must be a terminal symbol. The following steps are
used to obtain PDA from CFG is:
➢ For the given grammar we can accept the PDA accepted by Empty stack.
➢ Let us Consider
➢ G={V, T, P, S} Then PDA can be given as
➢ P=({q}, T, VUT, δ, q, s, Ф)
➢ Example 1: Construct PDA for CFG and also check weather 010000 is accepted by PDA
➢ S→ 0BB
➢ B→0S| 1S | 0
➢ Solution:
➢ Let PDA P= {{q}, {0,1}, {S, B, 0, 1}, δ, q, s, Ф}
➢ R1: δ(q, ε, S) = {(q, 0BB)}
➢ R2: δ(q, ε, B) = {(q, 0S), (q, 1S), (q, 0)}
➢ R3: δ(q, 0, 0) = (q, ε)
➢ R4: δ(q, 1, 1) = (q, ε)
➢ Now Let us check weather 010000 is accepted by PDA
➢ Example 2: Convert the following grammar to a PDA that accepts the same
language.
S → 0S1 | A
A → 1A0 | S | ε
➢ Solution:
➢ The CFG can be first simplified by eliminating unit productions:
S → 0S1 | 1S0 | ε
➢ Now we will convert this CFG to GNF:
S → 0SX | 1SY | ε
X→1
Y→0
The PDA can be:
➢ So these are the productions in equivalent grammar but it may have some useless
[q0, X, q1 ]→b
[q1, X, q1 ]→b
[q1, X, q2 ]→ ε