Title: Module 32
1Module 32
- Pushdown Automata (PDAs)
- definition
- Example
- We define configurations and computations of
PDAs - We define L(M) for PDAs
2Pushdown Automata
- Definition and Motivating Example
3Pushdown Automata (PDA)
- In this presentation we introduce the PDA model
of computation (programming language). - The key addition to a PDA (from an NFA-/\) is the
addition of external memory in the form of an
infinite capacity stack - The word pushdown comes from the stacks of
trays in cafeterias where you have to pushdown on
the stack to add a tray to it.
4NFA for ambn m,n gt 0
- Consider the language anbn n gt 0.
- This NFA can recognize strings which have the
correct form, - as followed by bs.
- However, the NFA cannot remember the relative
number of as and bs seen at any point in time.
- What strings end up in each state of the above
NFA? - I
- B
- C
5PDA for anbn n gt0
Imagine we now have memory in the form of a stack
which we can use to help remember how many as we
have seen by pushing onto and popping from the
stack When we see an a in state I, we do the
following two actions 1) We push an a on the
stack. 2) We stay in state I. When we see a b
in state B, we do the following two actions 1)
We pop an a from the stack. 2) We stay in state
B. From state B, we allow a /\-transition to
state C only if 1) The stack is empty. Finally,
when we begin, the stack should be empty.
6Formal PDA definition
- PDA M (Q, S, G, q0, Z, A, d)
- Modified elements
- G is the stack alphabet
- Z is a special character that is initially on the
stack - Often used to represent an empty stack
- d is modified as follows
- Pop to read the top character on the stack
- Stack update action
- What to push back on the stack
- If we push /\, then the net result of the action
is a pop
7Example PDA
- Q I, B, C
- S a,b
- G Z, a
- q0 I
- Z is the initial stack character
- A C
- d
- S a TopSt NS stack update
- I a a I push aa
- I a Z I push aZ
- I /\ a B push a
- I /\ Z B push Z
- B b a B push /\
- B /\ Z C push Z
8Computing with PDAs
- Configurations change compared with NFA-/\s
- Configuration components
- current state
- remaining input to be processed
- stack contents
- Computations are essentially the same as with
NFA-/\s given the modified configurations - Determining which transitions of a PDA can be
applied to a given configuration is more
complicated though
9Computation Graph of PDA
Computation graph for this PDA on the input
string aabb
Q I, B, C S a,b G Z, a q0 I Z is
the initial stack character A C d S
a TopSt NS stack update I a a I push
aa I a Z I push aZ I /\ a B push a I /\ Z B push
Z B b a B push /\ B /\ Z C push Z
(I,aabb,Z)
10Definition of -
Input string aabb
(I, aabb, Z) - (I,abb,aZ) (I, aabb, Z) - (B,
aabb, Z) (I, aabb, Z) -2 (C, aabb, Z) (I, aabb,
Z) -3 (B, bb, aaZ) (I, aabb, Z) - (B, abb,
aZ) (I, aabb, Z) - (B, /\, Z) (I, aabb, Z) -
(C, /\, Z)
11Acceptance and Rejection
Input string aabb
M accepts string x if one of the configurations
reached is an accepting configuration (q0, x,
Z) - (f, /\, a),f in A, a in G Stack
contents can be anything M rejects string x if
all configurations reached are either not halting
configurations or are rejecting configurations
12Defining L(M) and LPDA
- L(M) (or Y(M))
- The set of strings ?
- N(M)
- The set of strings ?
- LPDA
- Language L is in language class LPDA iff ?
M accepts string x if one of the configurations
reached is an accepting configuration (q0, x,
Z) - (f, /\, a),f in A, a in G Stack
contents can be anything M rejects string x if
all configurations reached are either not halting
configurations or are rejecting configurations
13Deterministic PDAs
- A PDA is deterministic if its transition function
satisfies both of the following properties - For all q in Q, a in S union /\, and X in G,
- the set d(q,a,X) has at most one element
- For all q in Q and X in G,
- if d(q, /\, X) lt gt , then d(q,a,X) for
all a in S - A computation graph is now just a path again
- Our default assumption is that PDAs are
nondeterministic
14Two forms of nondeterminism
Trans Current Input Top of Next Stack
State Char. Stack State
Update -------------------------------------------
------------ 1 q0 a
Z q0 aZ 2 q0
a Z q0 aa 3 q0
/\ Z q0 aZ 4
q0 a Z q0
aa
15LPDA and DCFL
- A language L is in language class LPDA if and
only if there exists a PDA M such that L(M) L - A language L is in language class DCFL
(Deterministic Context-Free Languages) if and
only if there exists a deterministic PDA M such
that L(M) L - To be proven
- LPDA CFL
- CFL is a proper superset of DCFL
16PDA Comments
- Note, we can use the stack for much more than
just a counter - See examples in chapter 7 for some details