Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Pushdown Automata
1
Finite Automata
• A finite automaton has a huge limitation.
• It can count only by changing states.
• So an FA can distinguish between at most
|Q| states.
• This limitation bounds the class of languages
that an NFA can recognize to a rather small
category - that of regular languages.
2
Turing Machine
• Infinite memory allow us to recognize a larger
class of languages.
• If there are no restrictions on the use of this
memory, i.e. the automaton can read and
write in any location in the memory, then
the result is the strongest possible model - a
Turing Machine.
• A Turing machine (TM) can perform any
computation that the most powerful computer
can (now and in the future).
3
The Stack Model
• We add to an NFA an unlimited memory but
we limit the way it is used.
• Our limitation - the memory will be a stack.
• We can read/write only at the top of the stack.
• We still have a finite number of states that can
be used as before.
• we get a machine which is stronger than NFA
but less powerful than TM.
4
Pushdown Automata
• Informally a pushdown automata (PDA) is an
NFA + Stack
state
control
a a b ca a
x
y
z
7
Transition function of a PDA
• In NFA a transition function is determined
according to:
1. A current state
2. An input letter
• In PDA we move according to
1. A current state
2. An input letter
3. A letter on top of the stack
• The transition function output is a state and a
letter to be written into the stack. 8
Formal Definition of PDA
• A pushdown automaton is a 6-tuple:
(Q, , , , q0, F)
,xy
• The diagram for the PDA is: q q’
10
Possible transition functions
• (q,,x) = (q',y)
– move without reading a symbol from the input
• (q,,) = (q',y)
– move without reading a symbol from the stack
• (q, ,x) = (q',)
– move without pushing a symbol to the stack
• (q, , ) = (q,y)
– push y ,xy
• (q, , x) = (q,) q q’
– pop x
11
Example:
• Change the stack:
(q,,x) = (q',y)
,xy
q q’
x y
z z
12
Example:
• Popping the stack:
(q,,x) = (q', )
,x
q q’
x
z z
13
Example:
• Pushing the stack:
(q,,) = (q', y)
,y
q q’
y
x x
z z
14
Example:
• No change:
(q,,x) = (q', x)
(q,,) = (q', )
,xx
q q’
,
x x
z z
15
Example of a PDA
• A state diagram for a PDA that recognizes
{ambn | m=n0}
q4 q3
,$ b,A 17
Example of a PDA
• The transition function can be described using a
transition table:
input:
stack:
,$ a,A
q1 q2
b,A
q4 q3
,$ b,A 18
Another Example
• A state diagram for a PDA that recognizes
{ambn | n>m 0}
20
Computation of a PDA
• A PDA accepts input w if w can be written as
w=w1w2…wm, wi and there exist a sequence
of states r0,r1,…rm, riQ, and a sequence of
strings s0,s1,…,sm , si such that:
1. r0=q0 and s0= .
2. for i=0,...,m-1 (ri+1,b)(ri,wi+1,a) where
si=a t and si+1=b t , where a,b and t
3. rmF
wi+1,ab
a b ri ri+1
t t
si si+1 21
Another Example of PDA
• This PDA recognizes {aibjck | i=j or i=k}
b,A c,
,$
q1 q3 q4
,$ ,
q2 q5 q6 q7
, , ,$
a,A
b, c,A
22
Non Determinism in PDA
23
Non Determinism in PDA
• A PDA is called deterministic iff it holds the
following three conditions:
– for each qQ, a and x, |(q,a,x)| 1
– for each qQ and x, if (q,,x) then for each
, (q, , x)=
– for each qQ and , if (q,,) then for
each x, (q, ,x)=
,$ 0,0
q0 q1 1,1
c,
0,0
q3 q2 1,1
,$
25
Example of Nondeterministic PDA
• This PDA recognizes {wwR | w{0,1}* }
• A nondeterminism is a must here.
,$ 0,0
q0 q1 1,1
,
0,0
q3 q2 1,1
,$
26
Example of a PDA
• Construct a PDA that recognizes:
L = {aibjci+j | i,j0}
,$
q0 q1 a,Z
,
q4 q3 q2 b,Z
,$ ,
c,Z
27
Example of a PDA
• Construct a PDA that recognizes:
L = {aibj | i,j0}
a, b,
b,
q0 q2
a,A
q7 q6 q5
,$ ,
b,A a,A
29
Shorthand Notation for PDA
• Sometimes it is convenient to allow the PDA
to write on the stack an entire string u* in
one machine step.
• We use the notation:
(r,u)(q,a,x) where u*
to denote that when a,xu
q r
– the current state is qQ
– the next input symbol is a
– the next stack symbol is x
the PDA may move to state r and push the
string u* into the stack.
Shorthand Notation for PDA
u1
u2
a,xu1u2…uk
q r x uk
z z
q r
Shorthand Notation for PDA
• We can implement the action (r,u) (q,a,x) in
the standard PDA by introducing new states
q1,…,qk-1 and setting the transition functions:
– (q,a,x) = {(q1,uk)}{ what we have so far}
– (q1,,)={(q2,uk-1)}
– (q2,,)={(q3,uk-2)}
a,xxyz
q r
– (qk-1,,)={(r,u1)}
q a,xz ,x r
,y
q1 q2
Example of a Shorthand PDA
• Construct a PDA that recognizes:
L = {aibj | i>0 and j=i+3}
,AAA$
q0 q1
a,A
q7 q6 q5
,$ ,
b,A a,A
33
The Power of PDA
• What is the power of a PDA? Can it recognize
all context-free languages? Is it stronger?
• Proof:
– We show that if L is CFL then a PDA recognizes it.
– We show that is a PDA recognizes L then L is CFL.