Professional Documents
Culture Documents
MOTIVATION
Regular language can be charaterized as the language accepted by finite automata. Similarly,
we can characterize the context-free language as the langauge accepted by a class of
machines called "Pushdown Automata" (PDA). A pushdown automation is an extension of
the NFA.
It is observed that FA have limited capability. (in the sense that the class of languages
accepted or characterized by them is small). This is due to the "finite memory" (number of
states) and "no external memory" involved with them. A PDA is simply an NFA augmented
with an "external stack memory". The addition of a stack provides the PDA with a last-in,
first-out memory management capapability. This "Stack" or "pushdown store" can be used to
record a potentially unbounded information. It is due to this memory management capability
with the help of the stack that a PDA can overcome the memory limitations that prevents a
FA to accept many interesting languages .Although, a PDA can store an unbounded amount
of information on the stack, its access to the information on the stack is limited. It can push
an element onto the top of the stack and pop off an element from the top of the stack. To read
down into the stack the top elements must be popped off and are lost. Due to this limited
access to the information on the stack, a PDA still has some limitations and cannot accept
some other interesting languages.
Finite automata are not able to recognize the context free languages like {WCW R
/ W * } because it has to remember the string W for comparing with the string
WR. But finite automata is not capable to remember anything. Also the language
consists of nested parenthesis (useful in programming languages) is
not
accepted by DFA because the storage of information will be done in its current
state only. It requires unbounded memory to count symbols in strings e.g. anbn A
storage in form of stack would do the trick here, hence, Pushdown Automata
(PDA). i.e Push down Automata is a finite automata with a unlimited memory.
Definition
Following are the equivalent definition
a) PDA is a way to represent the language class called context free
languages
b) PDA is a generalization of FSA and PDA changes from state to state
reading input symbols. Unlike FSA
transitions also update the stack
either by popping symbols or by pushing them.
Components
1)
2)
3)
4)
DESCRIPTION OF PDA
Transition diagram
In a directed graph for an arc going from the vertex which corresponds to
state p to the vertex that corresponds to state q, the edge labeling can be
represented in following forms
Form 1
Form2
Understand the language properties for which the PDA has to be designed
Determine the set and alphabet set required
Identify the initial ,accepting and dead states of PDA
Decide on the stack symbols required
Determine the initial stack symbol
For each state decide on the transition to be made
For each state transition decide on the stack operations to e performed
Obtain the transition diagram and transition table for PDA
Test the PDA on short strings
Design strategy : As it reads the first half of its input, it remain in its initial
state q0 and pushes all the symbols from the input string onto the stack.
When the machine sees a C symbol in the input string it switches its
state from q0 to q1 without updating the stack. If the input symbol
matches with the top of the stack ,top element is popped out. If the input
symbol does not match with top of the stack then no further operation is
possible. If the stack is emptied after reading entire string then that
language is accepted.
Following are the transitions required
1) Read each symbol of the string and push into the stack before C is
encountered
a) (q0,,z0,nop,q0)
b) (q0, 0, z0, push(0), q0)
c) (q0, 1, z0, push(1), q0)
d) (q0, 1, 1, push(1), q0)
e) (q0, 0, 0, push(0), q0)
f) (q0, 1, 0, push(1), q0)
g) (q0, 0 , 1, push(0), q0)
2) Once C is encountered state changes from q0 to q1 without performing
any operation
a) (q0, C , 1, nop, q1)
b) (q0, C , 0, nop, q1)
c) (q0, C , z0, nop, q1)
3) Read the next input symbol in te second half and pop from the stack if
there is a match
a) (q1, 1 , 1, pop, q1)
b) (q1, 0 , 0, pop, q1)
4) If the stack is empty after reading last symbol ,it moves from q1 to q2
Thus the PDA is ( {q0,q1,q2}, {0,1}, {0,1,z0}, , z0, q2) where is
given
by
the
transition
1,1
push(1)
0,1
push(0)
1,0
push (1)
0,0
push(0)
, z0
nop
q0
0, z 0
push(0)
1,1
pop
C ,0
nop
C ,1
nop
C , z0
nop
0,0
pop
q1
, z0
nop
1, z0
push(1)
diagram
Transition table is given by
Unread input
001C100
Transition
-
Stack
Z0
4
New state
q0
q2
01C100
1C100
C100
100
00
0
(q0,0,z0,push(0),q0)
(q0,0,0,push(0),q0)
(q0,1,0,push(1),q0)
(q0,C,1,nop,q1)
(q1,1,1,pop,q1)
(q1,0,0,pop,q1)
(q1,0,0,pop,q1)
(q1,,z0,nop,q2)
0z0
00z0
100z0
100z0
00z0
0z0
Z0
Z0
q0
q0
q0
q1
q1
q1
q1
q2
Example
To show that w = 001C100 is accepted by PDA
: Q x () x Q x *
(q0,001C100,z0 ) = (q0,0z0)
(q0,01C100,0z0 ) = (q0,00z0)
stack
(q0,1C100,00z0 ) = (q0,100z0)
(q0,C100,100z0 ) = (q1,100z0)
(q1,100,100z0 ) = (q1,00z0)
(q1,00,00z0 ) = (q1,0z0)
(q1,0,0z0 ) = (q1,z0)
is empty
(q1,,z0 ) = (q2,z0)
3) Read the next input symbol in the second half and pop from the stack if
there is a match
c) (q1, 1 , 1, pop, q1)
d) (q1, 0 , 0, pop, q1)
4) If the stack is empty after reading last symbol ,it moves from q1 to q2
Thus the PDA is ( {q0,q1,q2},{0,1},{0,1,z0},,z0,q2) where is given
by the transition
1,1
push(1)
0,1
push(0)
1,0
push (1)
0,0
push(0)
, z0
nop
q0
0, z 0
push(0)
1,1
pop
,0
nop
,1
nop
, z0
nop
0,0
pop
q1
, z0
nop
1, z0
push(1)
Transition
(q0,0,z0,push(0),
q0)
(q0,1,0,push(1),q
0)
(q0,,0,nop,q0)
(q1,1,1,pop,q1)
(q1,0,0,pop,q1)
(q1,,z0,nop,q2)
Stack
Z0
0z0
New state
q0
q0
10z0
q0
10z0
0z0
z0
z0
q1
q1
q1
q2
Example
To show that w = 0110 is accepted by PDA
: Q x () x Q x *
(q0,0110,z0 ) = (q0,0z0)
-first symbol is pushed into the stack
(q0,110,0z0 ) = (q0,01z0)
- second symbol is pushed into the stack
(q0,110,01z0 ) = (q1,01z0) - no updation on stack
(q1,10,10z0 ) = (q1,0z0)
- top element is popped
(q1,0,0z0 ) = (q1,z0)
- top element is popped
(q1,,z0 ) = (q2,z0)
- moves to accepting state
q1,,z0 ) = (q2,z0)
- moves to accepting state
3) Obtain a PDA to accept the language L = { a nbn / n 1}
Design strategy : As it reads the input symbol a, it remain in its
initial state q0 and pushes the symbols from the input string onto the
stack. Once an input symbol b is encountered it switches its state from
q0 to q1 and top element is popped out. This process continues for every
b. If the stack is emptied after reading entire string then that language is
accepted.
6
q2
b, a
pop
a, z0
push( a)
b, a
pop
q0
q1
, z0
nop
Transition
(q0,a,z0,push(a),q
0)
(q0,a,a,push(a),q
0)
(q0,b,a,pop,q1)
(q1,b,a,pop,q1)
(q1,,z0,pop,q1)
Stack
Z0
az0
New state
q0
q0
aaz0
q0
az0
z0
z0
q1
q1
q2
Example
To show that w = 0110 is accepted by PDA
: Q x () x Q x *
(q0,aabb,z0 ) = (q0,az0)
-first symbol a is pushed into the stack
(q0,abb,az0 ) = (q0,aaz0)
- second symbol is pushed into the stack
(q0,bb,aaz0 ) = (q1,az0) - top element is popped out
(q1,b,az0 ) = (q1,z0)
- top element is popped
(q1,,z0 ) = (q2,z0)
- - moves to accepting state
4) Design a PDA to accept the language L = { w (a,b) */na = nb }
Transition diagram is
q2
b, b
push(b)
b, a
pop
a, a
push (a )
a, b
pop
, z0
nop
q0
b, z0
push( a)
q2
a, z0
push( a)
(, z0
push (()
(, (
push (a )
), (
pop
q0
, z0
nop
6) Design a PDA to accept L = {w/w (a,b) * such that na(w) > nb(w)
b, a
pop
b, b
push (b)
a, a
push (a)
a, b
pop
q0
b, z 0
push(a )
, a
nop
q2
a, z 0
push(a )
q2
2)
3)
4)
5)
(q0,
(q0,
(q1,
(q1,
(,
),
),
,
(, push( ( ) , q0)
(, pop , q1)
(, pop , q1)
z0, nop , q2)
L ={ a nbn / n 1} is
a, b
push ( x)
q1
a, b
push ( y )
q2
q3
b) Second kind of non determinism occurs when a state emits two edges
labelled with the same stack symbol ,where one input symbol is and
9
other input symbol is different from . Here there are two choices
based on different inputs
a, z 0
push ( xq)2
q1
, z 0
pop
q3
(q0,,z0,nop,q0)
(q0, 0, z0, push(0), q0)
(q0, 1, z0, push(1), q0)
(q0, 1, 1, push(1), q0)
(q0, 0, 0, push(0), q0)
(q0, 1, 0, push(1), q0)
(q0, 0 , 1, push(0), q0)
10
G=(Vn,Vt,P,S)
Where
Vn=set of non-terminal={S}
Vt= set of terminals={0,1}
G=(Vn,Vt,P,S)
11
Where
Vn={S,A,B}
Vt={0,1}
G=(Vn,Vt,P,S)
V= {S}
V={a,b}
Where P is defined as
SaSbS/bSas/
Let us derive a string
W= bbabaabbaa
SbSaS
bbSaSaS
bbaSbaSbSaSaS
bbaSbaaSbSbSaSa
bbabaaSbSbSaSaS
bbabaabaSbSaSaS
bbabaabbSaSaS
12
bbabaabbaSaS
bbabaabbaaS
bbabaabbaa
7. Design a CFG, which can generate string, having any combinations of
as and bs, except null string.
Let CFG be
G=(Vn,Vt,P,S)
Vn={S}
Vt={a,b}
baS(by P1)
baaS(by P1)
baab (by P4)
8. Design CFG for regular expressions
r=(a+b)*aa(a+b)*
Let CFG be
G=(Vn,Vt,P,S)
Vn={S,T}
Vt={a,b}
Where P is defined as
STaaT
(say P1)
TaT
(say P2)
TbT
(say P3)
(Say P4)
13
G=(Vn,Vt,P,S)
V={S}
V={a,b}
Pare defined as
SaS
SbS
Sa
Sb
S
The word ab can be generated by the derivation
SaS
abS
ab
ab
14
Or by the derivation
SaS
ab
10.the difference between even palindrome and odd palindrome is that
when weare finally ready to get rid of S in the even palindromeworking
string, we must replace it with . If we were force to replace it with an a
or b instead , we would create a central letter and the result would be a
grammar for odd palindrome as follows;
SaSa
SbSb
Sa
Sb
If we allow the option of turning the central S into either or a letter, we
would have a grammar for the entire
15