Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 32

Hawassa University Daye

Campus
Department of Computer
Automata and complexity
Science
theory

Course code: CoSc3071


By: Mekonen M.
1
Chapter Two
Unit 5
Pushdown Automata
Introduction

Chomsky Hierarchy in Theory of Computation

01
Mekonen M. # CoSc3071  Unit 3 – Regular Expression 3
Why Pushdown Automata?
Exercise
• Draw Finite automata for language
b
Not
Possible??

• FA have limited capability.


• This is due to the "finite memory” and "no external memory" involved
with FA.

Mekonen M. # CoSc3071  Unit 5 – Pushdown Automata 4


Pushdown Automata
• A pushdown Automata is essentially a finite Automata with a stack data structure.

Finite
Stack Accept | Reject
Input Control

Input tape

Stack

• A PDA can write an unbounded no. of symbols on the stack and read these
symbols later.
• Writing a symbol on to the stack is called “PUSH” operation.
• Removing a symbol off the stack is called “POP” operation.

Mekonen M. # CoSc3071  Unit 5 – Pushdown Automata 5


Pushdown Automata components
• A pushdown Automata is essentially a finite Automata with a stack data structure.

Finite
Stack Accept | Reject
Input Control
Input tape

Stack

• 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 pop the items from one end only. It has
an infinite size. In PDA, the stack is used to store the items temporarily.

Mekonen M. # CoSc3071  Unit 5 – Pushdown Automata 6


Definition of PDA
• A pushdown Automata(PDA) is a 7-tuple , where
is finite set of states
and are finite sets of i/p symbol
is stack alphabet
the initial state, is an element of Q
the initial stack symbol, is an element of
is a set of accepting states, is a subset of Q
the set of finite subsets of
The function is called transition function of .

Mekonen M. # CoSc3071  Unit 5 – Pushdown Automata 7


• δ takes as arguments a triple δ(q, a, X) where
I. q is a State in Q
II. a is either an input symbol in Σ or a = ϵ
III. X is a Stack Symbol, that is a member of Γ
• The output of δ is finite set of pairs (p, γ) where
I. P is a new state
II. γ is a string of stack symbols that replace X at the top of the stack
• Example: if γ = ϵ then the stack is popped
• if γ = X then the stack is Unchanged
• if γ = YZ then X is replaced by Z and Y is pushed onto the stack

Mekonen M. # CoSc3071  Unit 5 – Pushdown Automata 8


Acceptance by PDA
• There are two different ways to define PDA acceptability.
• If is a PDA and , is accepted by if

for some and some . A language is said to be accepted by if L is


precisely the set of strings accepted by , in this case, we write .
1. If = - L acceptance by final state
2. If = - L is acceptance by final state

Mekonen M. # CoSc3071  Unit 5 – Pushdown Automata 9


Deterministic PDA
• Let be a pushdown Automata. is deterministic if there is no
configuration for which has a choice of more than one move. In other
words is deterministic if it satisfies the following conditions:
1. For any and , the set has at most one element.
A language L is a deterministic context free language (DCFL) if there is
deterministic PDA accepting L.

Mekonen M. # CoSc3071  Unit 5 – Pushdown Automata 10


Applications of PDA
• A pushdown automata is a way to implement a context free grammar.
• PDA is used in parser design for syntactic analysis.

Mekonen M. # CoSc3071  Unit 5 – Pushdown Automata 11


𝒂
Design DPDA for L={a b |a,b ∈ Ʃ, n≥0} n n 𝒂
𝒂
anbn If n=3 then a 3 b3 = a a a b b b

𝒃
𝒃
𝒃
𝒛𝟎
Mekonen M. # CoSc3071  Unit 5 – Pushdown Automata 12
How to Represent PDA?
Move No State Input Stack Symbol Move(s)

a, z0|az0 Input symbol, stack symbol | PUSH/POP

𝑞0 𝑞1
b, a |
FIRST 2 SYMBOLS
^
OF THE STACK

a, a | aa

Mekonen M. # CoSc3071  Unit 5 – Pushdown Automata 13


Design DPDA for L={anbn|a,b ∈ Ʃ, n≥0}
Move No State Input Stack Symbol Move(s)

a, z0|az0 b, a |

𝑞1
,z0 | z0
𝑞0
b, a |
𝑞2
a, a | aa ,z0 | z0
Mekonen M. # CoSc3071  Unit 5 – Pushdown Automata 14
Design DPDA for L={anbn|a,b ∈ Ʃ, n≥0}
Move No State Input Stack Symbol Move(s)

a, z0|az0 b, a |

𝑞1
,z0 | z0
𝑞0
b, a |
𝑞2
a, a | aa ,z0 | z0
Mekonen M. # CoSc3071  Unit 5 – Pushdown Automata 15
Design PDA for palindrome with middle symbol c 𝒂
𝒃
𝒂
a b a ca b a

𝒂
𝒃
𝒂
𝒛𝟎
Mekonen M. # CoSc3071  Unit 5 – Pushdown Automata 16
Design PDA for palindrome with middle symbol c
• Design a PDA for following CFG.
SaSa/bSb/c
• Design PDA for L={xcxr/x∈{a,b}*}. The string in L are odd length palindromes
over {a,b}
• Strings accepted in the language are:
1.aba c aba
2.aaa c aaa
3.bab c bab
4.ab c ba

Mekonen M. # CoSc3071  Unit 5 – Pushdown Automata 17


Design PDA for palindrome with middle symbol c
Move No State Input Stack Symbol Move(s)

b, z0|bz0
a, z0|az0 a, a | aa

𝑞0
b, b | bb b, a | ba
a, b | ab

Mekonen M. # CoSc3071  Unit 5 – Pushdown Automata 18


Design PDA for palindrome with middle symbol c
Move No State Input Stack Symbol Move(s)

b, z0|bz0
a, z0|az0 a, a | aa c,a | a

𝑞1
c,b | b
𝑞0 c,z0 | z0

b, b | bb b, a | ba
a, b | ab

Mekonen M. # CoSc3071  Unit 5 – Pushdown Automata 19


Design PDA for palindrome with middle symbol c
Move No State Input Stack Symbol Move(s)

b, z0|bz0 b, b |
a, z0|az0 a, a | aa
c,a | a

𝑞0 c,b | b

c,z0 | z0
𝑞1 ,z0 | z0
𝑞2
b, b | bb b, a | ba
a, b | ab a, a |

Mekonen M. # CoSc3071  Unit 5 – Pushdown Automata 20


Instantaneous Description (ID)
• ID is an informal notation of how a PDA computes an input string and
make a decision that string is accepted or rejected.

• An instantaneous description is a triple (q, w, α) where:


• q describes the current state.
• w describes the remaining input.
• α describes the stack contents, top at the left.

Mekonen M. # CoSc3071  Unit 5 – Pushdown Automata 21


Turnstile Notation (⊢)
• ⊢ sign describes the turnstile notation and represents one move.
• ⊢* sign describes a sequence of moves.

• For example: (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 α.

Mekonen M. # CoSc3071  Unit 5 – Pushdown Automata 22


Instantaneous Description (ID) for abcba
b, z0|bz0 b, b |
(, , ) ⊢ (, , )
a, z0|az0 a, a | aa
c,a | a ⊢ (, , )

𝑞0 c,b | b

c,z0 | z0
𝑞1 ,z0 | z0
𝑞2 ⊢ (, , )
⊢ (, , )
b, b | bb b, a | ba ⊢ (,, )
a, b | ab a, a |
⊢ (,, )
Move No Resulting State Unread Input Stack

𝒒
𝑞𝟐2

Mekonen M. # CoSc3071  Unit 5 – Pushdown Automata 23


Design DPDA for same no. of a’s & b’s
Move No State Input Stack Symbol Move(s)

a, z0|az0
a, b| b, z0|bz0
b, a|
𝑞0 𝑞1
,z0 | z0

a, a | aa
b, b | bb

Mekonen M. # CoSc3071  Unit 5 – Pushdown Automata 24


Design PDA for {anbn+m cm | n,m>=1}
an bn+m cm = an bn bm cm

If n=2 and m=3 then

= a 2 b2 b3 c 3
= aa bb bbb ccc

Mekonen M. # CoSc3071  Unit 5 – Pushdown Automata 25


Design PDA for {anbn+m cm | n,m>=1}
Move No State Input Stack Symbol Move(s)

a,a,a|a|aa b, a| b, b| bb
aa

b, z0| bz0
𝑞0
a, z00| az0.0
𝑞1
b, a|
𝑞2 𝑞3

Mekonen M. # CoSc3071  Unit 5 – Pushdown Automata 26


Design PDA for {anbn+m cm | n,m>=1}
Move No State Input Stack Symbol Move(s)

a, a| aa b, a| b, b| bb c, b|

𝑞4
b, z0| bz0
𝑞3
c, b|
𝑞0
a, z0| az0
𝑞1
b, a|
𝑞2
, z0| z0

𝑞5
Mekonen M. # CoSc3071  Unit 5 – Pushdown Automata 27
Exercise: Design PDA
1. Design PDA for anbncmdm , n,m>=1
2. Design PDA for anbmcmdn , n,m>=1
3. Design PDA for an+mbncm , n,m>=1

Mekonen M. # CoSc3071  Unit 5 – Pushdown Automata 28


CFG to PDA
Steps to convert CFG to PDA
• From given CFG G=(V,Σ,S,P), we can construct a PDA.
• The PDA’s δ is given by :
1. For each non terminal A, include a transition
Include a transition δ(q, 𝜖, A){(q, α)|A α is a production in G}
2. For each terminal a, include a transition
Include a transition δ(q, a, a){(q, 𝜖)}

Mekonen M. # CoSc3071  Unit 5 – Pushdown Automata 30


Example: CFG to PDA
Find PDA for following grammar:
S0S1 | 0 | 1
The equivalent PDA, M is given by:
δ(q, 𝜖, A){(q, α)|A α is a production in G Non Terminal
δ(q, 𝜖, S)= {(q, 0S1), (q, 00), (q,11)}

δ(q, a, a){(q, 𝜖)}


δ(q, 0, 0)={(q, 𝜖)} Terminal
δ(q, 1, 1)={(q, 𝜖)}

Mekonen M. # CoSc3071  Unit 5 – Pushdown Automata 31


Exercise: CFG to PDA
1. Given a CFG , G =( {S,A,B},{0,1},P,S) with P as follows:
S  0B| 1A
A  0S|1AA|0
B  1S| 0BB | 1
2. Design a PDA M corresponding to CFG:
I  a | b | Ia | Ib | I0 | I1
E  I | E * E | E + E | (E)

Mekonen M. # CoSc3071  Unit 5 – Pushdown Automata 32

You might also like