0% found this document useful (0 votes)
26 views29 pages

Push Down Automata With Exampless

Uploaded by

rehan gull
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views29 pages

Push Down Automata With Exampless

Uploaded by

rehan gull
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 29

Theory of Computation

Push Down Automata

Imdad ullah Khan

Imdad ullah Khan (LUMS) Push Down Automata 1 / 29


Push Down Automata

Imdad ullah Khan (LUMS) Push Down Automata 2 / 29


Models of Computation: Push Down Automata

Automata are distinguished by type/amount of working memory


A Push Down Automata has LIFO (stack) working memory

Automaton
Working Memory
Stack
Input
Memory Output
CPU Memory
n bits

Program Memory

Pushdown Automaton

Imdad ullah Khan (LUMS) Push Down Automata 3 / 29


Models of Computation: Push Down Automata

A push down automaton (PDA) is a finite automaton with a stack


The stack can store an infinite number of symbols from a stack alphabet Γ
The PDA reads an input symbol and stack top, changes state, and pushes
onto the stack in one transition

input string 1 0 1 ···

stack
top
Finite State Control

δ
q
..

Accept/Reject

Imdad ullah Khan (LUMS) Push Down Automata 4 / 29


Anatomy of PDA

A PDA over alphabet Σ and stack alphabet Γ is depicted as a directed


graph with self-loop
▷ called state diagram of the PDA

states
0, ϵ → 0 1, 0 → ϵ

ϵ, ϵ → $ 1, 0 → ϵ stack push
q0 q1 q2 stack top
symbol
input symbol
symbol
ϵ, $ → ϵ
initial state
accepting states a, b → c
qi qj
transition for every state, input symbol, and stack symbol

Imdad ullah Khan (LUMS) Push Down Automata 5 / 29


Anatomy of PDA

A PDA over alphabet Σ and tape alphabet Γ is depicted as a directed


graph with self-loop
▷ called state diagram of the PDA

states
0, ϵ → 0 1, 0 → ϵ

ϵ, ϵ → $ 1, 0 → ϵ stack push
q0 q1 q2 stack top
symbol
input symbol
symbol
ϵ, $ → ϵ
initial state
accepting states a, b → c
qi qj
transition for every state, input symbol, and stack symbol

Imdad ullah Khan (LUMS) Push Down Automata 6 / 29


Anatomy of PDA

A PDA over alphabet Σ and stack alphabet Γ is depicted as a directed


graph with self-loop
▷ called state diagram of the PDA

states
0, ϵ → 0 1, 0 → ϵ

ϵ, ϵ → $ 1, 0 → ϵ stack push
q0 q1 q2 stack pop
symbol
input symbol
symbol
ϵ, $ → ϵ
initial state
accepting states a, b → c
qi qj
transition for every state, input symbol, and stack symbol

$ ∈ Γ: Initial stack symbol that is helpful to check if the stack is empty.


By convention, it is pushed in the first transition in a PDA
ϵ: Empty string indicates read nothing, pop nothing or push nothing

Imdad ullah Khan (LUMS) Push Down Automata 7 / 29


Working of PDA

input input
··· a ··· ··· a ···

a, b → c
qi qj
stack stack
top top
b c

.. ..

$ $

Imdad ullah Khan (LUMS) Push Down Automata 8 / 29


Working of PDA

input input
··· a ··· ··· a ···

a, ϵ → c
stack
qi qj stack
top
c
top
b b

.. ..

$ $

Imdad ullah Khan (LUMS) Push Down Automata 9 / 29


Working of PDA

input input
··· a ··· ··· a ···

a, b → ϵ
qi qj
stack stack
top
b
top
x x

.. ..
$ $

Imdad ullah Khan (LUMS) Push Down Automata 10 / 29


Working of PDA

input input
··· a ··· ··· a ···

a, ϵ → ϵ
qi qj
stack stack
top top
b b

.. ..

$ $

Imdad ullah Khan (LUMS) Push Down Automata 11 / 29


Working of PDA

No transition is allowed to be followed when stack is empty (except


pushing $)
input
··· a ··· a, ϵ → c
a, b → c
qi qj

stack
top
HALT

The PDA halts in qi and rejects the input string

Imdad ullah Khan (LUMS) Push Down Automata 12 / 29


Non-Deterministic PDA

c
→ transition on ϵ
a ,b
ϵ, ϵ → c
multiple ϵ, b → c
transitions
a,
b→
c
no symbol consumed

Imdad ullah Khan (LUMS) Push Down Automata 13 / 29


Working of PDA: Example

0, ϵ → 0 1, 0 → ϵ

ϵ, ϵ → $ 1, 0 → ϵ ϵ, $ → $
q0 q1 q2 q3

A string is accepted if there is a computation from start state (with


non-deterministic choices) such that all input is consumed and the last
state is final state

At the end of computation, we do not care about content of stack

Imdad ullah Khan (LUMS) Push Down Automata 14 / 29


PDA: Formal Definition

A PDA P is a 7-tuple P = (Q, Σ, Γ, δ, q0 , $, F )

Q is a finite set of states


Σ is a finite input alphabet
Γ is a finite stack alphabet
δ : Q × (Σ ∪ {ϵ}) × Γ → P(Q × Γ∗ ) is the transition function
q0 ∈ Q is the initial state
$ ∈ Γ is the initial stack symbol
F ⊆ Q is the set of final states

Imdad ullah Khan (LUMS) Push Down Automata 15 / 29


NPDA for L = {0n 1n |n ≥ 0}

Consider the language L = {0n 1n |n ≥ 0}


L is not regular, but we can design a PDA to recognize L as follows:

As each 0 is read, push it onto the stack


As each 1 is read, pop a 0 from the stack
If the input is exhausted and the stack is empty, accept
Otherwise, reject.

0, ϵ → 0 1, 0 → ϵ

ϵ, ϵ → $ 1, 0 → ϵ ϵ, $ → $
q0 q1 q2 q3

Imdad ullah Khan (LUMS) Push Down Automata 16 / 29


Simulating the PDA for L = {0n 1n |n ≥ 0}

Configuration of PDA: (q, u, s) denotes the PDA configuration, q is the


current state, u is the remaining input, and s is the current stack contents
0, ϵ → 0 1, 0 → ϵ

ϵ, ϵ → $ 1, 0 → ϵ ϵ, $ → $
q0 q1 q2 q3

Consider the string w = 0011 ∈ L The PDA runs as follows:

Pre-transition configuration Transition Post-transition configuration


(q0 , 0011, ϵ) ϵ, ϵ → $ (q1 , 0011, $)
(q1 , 0011, $) 0, ϵ → 0 (q1 , 011, 0$)
(q1 , 011, 0$) 0, ϵ → 0 (q1 , 11, 00$)
(q1 , 11, 00$) 1, 0 → ϵ (q2 , 1, 0$)
(q2 , 1, 0$) 1, 0 → ϵ (q2 , ϵ, $)
(q2 , ϵ, $) ϵ, $ → ϵ (q3 , ϵ, $)

The PDA accepts the string w by empty stack


Imdad ullah Khan (LUMS) Push Down Automata 17 / 29
Simulating the PDA for L = {0n 1n |n ≥ 0}

Configuration of PDA: (q, u, s) denotes the PDA configuration, q is the


current state, u is the remaining input, and s is the current stack contents
0, ϵ → 0 1, 0 → ϵ

ϵ, ϵ → $ 1, 0 → ϵ ϵ, $ → $
q0 q1 q2 q3

Consider the string w = 0101 ∈


/L The PDA runs as follows:

Pre-transition configuration Transition Post-transition configuration


(q0 , 0101, ϵ) ϵ, ϵ → $ (q1 , 0101, $)
(q1 , 0101, $) 0, ϵ → 0 (q1 , 101, 0$)
(q1 , 101, 0$) 1, 0 → ϵ (q2 , 01, $)
(q2 , 01, $) No δ Reject

The PDA rejects the string w because there is no transition possible from
the configuration (q2 , 01, $)

Imdad ullah Khan (LUMS) Push Down Automata 18 / 29


PDA vs DFA

A PDA is an extension of a DFA with an additional stack memory


A DFA can only remember a finite amount of information, but a PDA
can remember an infinite amount of information using the stack
A DFA can recognize regular languages, which are a subset of
context-free languages
A PDA can recognize context-free languages, which are more
expressive and complex than regular languages
A DFA can be simulated by a PDA by ignoring the stack and using
the same transitions as the DFA
A PDA cannot be simulated by a DFA in general, because a DFA
cannot handle the stack operations and the nondeterminism of the
PDA

Imdad ullah Khan (LUMS) Push Down Automata 19 / 29


Deterministic PDA

Allowed Transitions Not Allowed Transitions

d d

a,
b b→ d d
ϵ, b → b→
a, ϵ,

a, ϵ, c
c→ → a, ϵ, b
d d b→ →
e e

Imdad ullah Khan (LUMS) Push Down Automata 20 / 29


Models of PDA and NPDA

A PDA can be either deterministic (DPDA) or nondeterministic


(NPDA)
A DPDA is a PDA that has at most one possible transition for any
given state, input symbol, and stack symbol
A NPDA is a PDA that can have more than one possible transition
for some state, input symbol, and stack symbol
A NPDA can also have ϵ-transitions, which do not consume any input
symbol but may change the state and the stack
A NPDA can simulate any DPDA, but not vice versa. Therefore,
NPDA is more powerful than DPDA

Imdad ullah Khan (LUMS) Push Down Automata 21 / 29


Examples of DPDA

The language L1 = {0n 1n |n ≥ 0} is recognized by the DPDA

0, ϵ → 0 1, 0 → ϵ

ϵ, ϵ → $ 1, 0 → ϵ ϵ, $ → $
q0 q1 q2 q3

Imdad ullah Khan (LUMS) Push Down Automata 22 / 29


Examples of DPDA

The language L2 = {v #v R |v ∈ {a, b, #}∗ } is recognized by the DPDA

b, ϵ → b b, b → ϵ
a, ϵ → a a, a → ϵ

#, ϵ → ϵ ϵ, $ → $
q0 q1 q2

Imdad ullah Khan (LUMS) Push Down Automata 23 / 29


Examples of NPDA

The language L3 = {vv R |v ∈ {a, b}∗ } is recognized by the NPDA

We non-deterministically guess when v ends and v R starts

b, ϵ → b b, b → ϵ
a, ϵ → a a, a → ϵ

ϵ, ϵ → ϵ ϵ, $ → $
q0 q1 q2

Imdad ullah Khan (LUMS) Push Down Automata 24 / 29


Examples of NPDA

The language L4 = {0i 1j 2k |i, j, k ≥ 0 and i = k} is recognized by the


NPDA

0, ϵ → 0 1, ϵ → ϵ 2, 0 → ϵ

ϵ, ϵ → ϵ 2, 0 → ϵ ϵ, $ → ϵ
q0 q1 q2 q3

ϵ, $ → ϵ

ϵ, $ → ϵ

Imdad ullah Khan (LUMS) Push Down Automata 25 / 29


Examples of NPDA

The language L5 = {ai b j c k |i, j, k ≥ 0 and i = j or i = k} is recognized by


the NPDA

a, ϵ → a b, a → ϵ

ϵ, ϵ → $ ϵ, ϵ → ϵ
start q0 q1 q2 c, $ → $

ϵ, $ → $
ϵ, $ → $
ϵ, ϵ → ϵ

ϵ, $ → $
b, ϵ → ϵ q4 q3

ϵ, $ → $
c, a → ϵ

c, a → ϵ q5

Imdad ullah Khan (LUMS) Push Down Automata 26 / 29


Limitation of PDA

A PDA is a powerful model of computation, but it is not as powerful


as a Turing machine
A PDA can only recognize context-free languages, which are a proper
subset of recursively enumerable languages
A PDA has a limited memory in the form of a stack, which can only
be accessed from the top
A PDA cannot perform arbitrary operations on the stack, such as
random access, copying, or reversing
A PDA cannot handle languages that require more complex memory
structures, such as queues, counters, or tapes

Imdad ullah Khan (LUMS) Push Down Automata 27 / 29


Pumping Lemma for Context-Free Languages

The pumping lemma for context-free languages is a property that all


context-free languages share, and it can be used to prove that some
languages are not context-free
The pumping lemma states that if a language L is context-free, then
there exists some integer m (called the pumping length) such that
every string w in L that has a length of m or more symbols can be
written as w = uvxyz, where u, v , x, y , and z are substrings of w ,
such that:
|vxy | ≤ m
|vy | > 0
uv k xy k z ∈ L for all k ≥ 0

The intuition behind the pumping lemma is that a long enough string
in a context-free language must have a repeated pattern in its
derivation tree, and this pattern can be pumped up or down without
leaving the language

Imdad ullah Khan (LUMS) Push Down Automata 28 / 29


Examples of Languages that Cannot be Decided by PDA

The following languages that are not context-free, and hence cannot be
decided by a PDA

L6 = {an b n c n |n ≥ 0}

L7 = {an b m c n d m |n, m ≥ 0}
2
L8 = {an |n ≥ 0}

Imdad ullah Khan (LUMS) Push Down Automata 29 / 29

You might also like