Chapter-4-pushdown-modified (2)
Chapter-4-pushdown-modified (2)
Sub chapters:
As we have seen, finite automaton cannot recognize all context-free languages. It is because
they have finite memories, where as the recognition of a context free language may require
storing an unbounded amount of information. For example, L={a nbn:n>=0}, since n is
unbounded, this counting cannot be done by finite memory. We want a machine that can
count without a limit. Another example where {ww R} , we need the ability to store and match
a sequence of symbols in reverse order. This suggests that we might try a stack as storage
mechanism, allowing unbounded storage that is restricted to operating like a stack. This gives
us a class of mechanism called pushdown automata or (PDA).
The stack is infinite in size, so can be used as a “memory” to eliminate the weakness of
“finite states” of NFA’s, which cannot accept languages like L = {anbn | n > 1}.
Each move of a PDA depends on the current state, input symbol, and top of stack symbol.
Each move consists of change of state and replacing top of stack symbol by a string of stack
symbols. A pushdown automata can accept its input in two ways - either by entering into an
accepting state or when the stack is empty.
1 | Page
A non deterministic pushdown accepter (npda)
M=(Q,I, r, 5, q0,z0,F)
Where
Q is a finite set of internal states of the control unit X is the input alphabet
r is the finite set of symbols called the stack alphabet
function.
qo c Q is the initial state of the control unit z c r* is the stack start symbol F c Q
2 | Page
Instantaneous Description: During execution, a PDA goes through a sequence of
configuration. Each configuration, called instantaneous description (ID) consists of 1.
Current state 2. Input yet to be scanned, 3. Stack content and is represented by a triplet (q,x,y)
where q is the current state, x is the input yet to be read(leftmost symbol of x is the current
input) and y is the stack content (leftmost symbol of y is the current top-of-stock symbol, i.e.
current stack contents as a string from top to bottom of stack ).
Move
Each move involves a change from one ID to another. The symbol |-- is used to represent a
move.
1. By an accepting state
2. by empty stack
(when the input is completely read, the stack is empty. We do not care about the state at
the end of execution).
3 | Page
Languages accepted by a PDA M by empty stack N(M) is defined as:
Q={q0,q1,q2}
□ □{a,b}
□ □{z,A}
The arguments of the □ Dare the current state of the control unit, a current input
symbol, and the current symbol on top of the stack.
accepting state.
|-- (q0,abbb,AAz)
|— (q0,bbb,AAAz)
|- (q1,bb,AAz)
|-- (q1,b,Az)
I-- (ql,D,z)
4 | Page
Explanation: In state q0, PDA reads a’s and pushes A for each a. on reading b, it pops
one A and goes to state q1. In q1, it reads b’s and pops off one A for each b. At the end,
M goes to the accepting state q2 if all A’s are popped off (i.e number of b’s=number of
a’s). PDA halts in q2.
□ □q0,a,z)={(q0,Az)}
□ Dq0,a,A)={(q0,AA)}
□ □qO,b,A)={(ql,D)}
□ □ql,b,A)={(ql,Q)}
It has a row for each pair of state and top of stack symbol and a column for each input. For
example, PDA for the above example is given as a transition table below.
q1
A (qi,nn --
Z (q2,DD
q2 No next move
5 | Page
Transition diagram: b,A/s
a,z/Az
To solve the problem, we have to keep track of number of a’s and see that
number of b’s are in excess. In the start state q0, PDA pushes the stack symbol
A for each a. On encountering b, PDA changes to q2. In q2, PDA pops off A
for each B. when all A’s are popped off, if there is an input b, PDA goes to the
accepting state q2. It skips further b’s. Formally
□ Dq0,a,Z)={(q0,AZ)}
□ Dq0,a,A)={(q0,AA)}
□ □qO,b,A)={(ql,Q)}
□ □ql,b,A)={(ql,D)}
□ □q1,b,Z)={(q2,Z)}
state.
Computation of aabbb is shown below
6 | Page
(q0,aabbb,z) |- (q0,abbb,Az)
|- (q0,bbb,AAz)
h (q1, bb,Az)
h (q1,b,z)
The central idea is to remember the pattern of w in stack and match the right
portion with the pattern already stored. For this purpose, we use two stack
symbols B and G to represent 0 and 1 respectively. In state q1, PDA pushes B
for 0 and G for 1. On scanning c, PDA go to state q2. It can be observed that
after scanning the left portion w, stack content from top to bottom is the
reverse of w. Also, top of stack symbol corresponds to the input to be
matched. In state q2, PDA matches and pops-off B for the input 0 and G for
input 1. At the end, if the input is correct, reverse of left portion (w R) matches
with the input and initial stack symbol R is exposed. Then, PDA empty the
initial stack symbol R to epsilon. If there is a mismatch the PDA halts. A
formal description is given below.
=q q
Q { 1, 2}
Z={0,1,c>
□ □□R,B,GD
7 | Page
M=(Q,X,D □ □ □ □ □ OqO, z,0 □ □ acceptance by empty stack
□ □q1,0,R)={(q1,BR)}
□ □q1,1,R)={(q1,GR)}
□ □ q1,c,R)={(q2,R)}
□ □q1,0,B)={(q1,BB)}
□ □q1,1,B)={(q1,GB)}
□ □q1,c,B)={(q2,B)}
□ □q1,0,G)={(q1,BG)}
□ □q1,1,G)={(q1,GG)}
□ □q1,c,G)={(q2,G)}
□ □ q2,0,B)={(q2, □)}
□ □q2,l,G)={(q2,D)}
Let us see the transition table for the above. Computation of strings 011c110.
TOS symbol 0 1 c
state
R (q1,BR) (q1,GR) (q2,R)
8 | Page
B (q2, □)
G
q2 (q2, □) --
M = ({qo, q\, q2, q3, q\}, {a, b, c, d}, {a, c, $}, d, qo, $, {q4})
Transitions are:
♦ By a single symbol
9 \ Page
♦ By a string of symbols
♦ By the empty string epsilon which means the top stack symbol is
“popped up (eliminated).”
With respect to push down automata, we had defined two models of acceptance. Depending
on specific situation, one model is more convenient than the other. It can, however, be shown
that both models are equivalent in power. For every language accepted by PDA by empty
stack, there is a PDA which accepts it by final state and vice-versa. Let us prove this: For
every PDA M1, there is a PDA M2 such that N(M1)=L(M2)
for any a.
In the above example the language accepted by P is the set of all strings that can put M
into a final state at the end of the string. The final stack content □ is irrelevant to this
definition of acceptance.
Acceptance by Empty Stack:
for any q.
2 If D(q ,D,b) is not empty, then D(q,c,b) must be empty for every cD □ □ □
The first condition requires that for any given input symbol and any stack top, at most
one move can be made.
11 | Page
The language L={anbn : n>=0}
□(q0,a,0) ={(q1,10)}
□ (q1,a,1) ={(q1,11)}
□ (ql,b,l)={(q2,D)}
□ (q2,b,l)={(q2,D)}
□(q2,D,0) ={(qO,D)}
12 | Page