Lecture 14-15 - PDA
Lecture 14-15 - PDA
A REJECT state
This state is like dead-end non final state
REJECT
and is expressed by
Note: It may be noted that the ACCEPT and REJECT states are called
the halt states.
Push Down Automata (PDA) Theory
A READ state
This state is to read an input letter a
READ b
and lead to some other state. The
∆
READ state is expressed by
Example
Before some other states are
defined consider the following b a
a
example of an FA along with its x- y+
b
new format
Push Down Automata (PDA) Theory
Obviously the above FA accepts the language of strings, expressed
by (a+b)*a. Following is the new format of the above FA
START
a ∆
READ READ
b
∆ a
REJECT ACCEPT
Note
The ∆ edge should not be confused with -labeled edge. The
∆-edges start only from READ boxes and lead to halt states.
Push Down Automata (PDA) Theory
Example a a,b
b
The above FA accepts the language 1 b +
-
expressed by (a+b)*bb(a+b)* a
START
a a,b
∆ ∆ ∆
REJECT REJECT ACCEPT
Push Down Automata (PDA) Theory
b
POP a
∆
Push Down Automata (PDA) Theory
Note
It may be noted that popping an empty STACK is like
reading an empty TAPE, i.e. popping a blank character ∆.
It may also be noted that when the new format of an FA
contains PUSH and POP states, it is called PUSHDOWN
Automata or PDAs. It may be observed that if the
PUSHDOWN STACK (the memory structure) is added to
an FA then its language recognizing capabilities are
increased considerably. Following is an example of PDA
Push Down Automata (PDA) Theory
Example
Consider the following PDA
START
PUSH a a READ1 ∆
b
b
∆
b, ∆ a,b
REJECT ACCEPT
REJECT
Push Down Automata (PDA) Theory
The string aaabbb is to be run on this machine. Before the
string is processed, the string is supposed to be placed on
the TAPE and the STACK is supposed to be empty as
shown below
∆
a a a b b b ∆ ∆
Push Down Automata (PDA) Theory
Reading first a from the TAPE we move from READ1State to
PUSH a state, it causes the letter a deleted from the TAPE and added
to the top of the STACK, as shown below
STACK
a a a b b b ∆ ∆
TAPE a
Push Down Automata (PDA) Theory
Reading next two a’s successively, will delete further two
a’s from the TAPE and add these letters to the top of the
STACK, as shown below
STACK
a a a b b b ∆ ∆
TAPE a
a
a
∆
Push Down Automata (PDA) Theory
Then reading the next letter which is b from the TAPE will
lead to the POP1 state. The top letter at the STACK is a,
which is popped out and READ2 state is entered. Situation
of TAPE and STACK is shown below
STACK
a
TAPE a a a b b b ∆ ∆ a
a
∆
Push Down Automata (PDA) Theory
Reading the next two b’s successively will delete two b’s from the
TAPE, will lead to the POP1 state and these b’s will be removed
from the STACK as shown below
∆
a a a b b b ∆ ∆
Now there is only blank character ∆ left, to be read from
the TAPE, which leads to POP2 state. While the only
blank characters is left in the STACK to be popped out
and the ACCEPT state is entered, which shows that the
string aaabbb is accepted by this PDA. It may be observed that the
above PDA accepts the language
{anbn: n = 0,1,2, … }.
Push Down Automata (PDA) Theory
Since the null string is like a blank character, so to
determine how the null string is accepted, it can be placed
in the TAPE as shown below
TAPE ∆ ∆ ∆
∆
PUSH X a READ1
b
b
∆ X POP2
POP1 X READ2
∆
a ∆
REJECT ACCEPT
Push Down Automata (PDA) Theory
Example:
Consider the following FA corresponding to the EVEN-
EVEN language
a
a
b b b b
a
The corresponding PDA will be
Push Down Automata (PDA) Theory
ACCEPT REJECT
∆ a ∆
START
a
b b b b
a
∆
a ∆
REJECT
REJECT
Push Down Automata (PDA) Theory
Nondeterministic PDA
Like TGs and NFAs, if in a PDA there are more than one
outgoing edges at READ or POP states with one label, then it
creates nondeterminism and the PDA is called nondeterministic
PDA.
In nondeterministic PDA no edge is labeled by string of
terminals or nonterminals, like that can be observed in TGs.
Also if there is no edge for any letter to be read from the
TAPE, the machine crashes and the string is rejected.
In nondeterministic PDA a string may trace more than one
paths. If there exists at least one path traced by a string leading
to ACCEPT state, then the string is supposed to be accepted,
otherwise rejected
Push Down Automata (PDA) Theory
START POP1 a
a a
b
PUSH a a READ1
b
POP2 b READ2
PUSH b ∆
b
POP3
ACCEPT
Push Down Automata (PDA) Theory
Here the nondeterminism can be observed at state READ1.
It can be observed that the above PDA accepts the
language
EVENPALINDROME={w reverse(w): wE{a, b}*}
={, aa, bb, aaaa, abba, baab, bbbb, …}
Now the definition of PDA including the possibility of
nondeterminism may be given as follows
Push Down Automata (PDA)
An alphabet Σ of input letters.
An input TAPE with infinite many locations in one direction. Initially the
input string is placed in it starting from first cell, the remaining part of the
TAPE is empty.
An alphabet Γ of STACK characters.
A pushdown STACK which is initially empty, with infinite many locations
in one direction. Initially the STACK contains blanks.
One START state with only one out-edge and no in-edge.
Two halt states i.e. ACCEPT and REJECT states, with in-edges and no
out-edges.
A PUSH state that introduces characters onto the top of the STACK.
A POP state that reads the top character of the STACK, (may contain more
than one out-edges with same label).
A READ state that reads the next unused letter from the TAPE, (may
contain more than one out-edges with same label).
Push Down Automata (PDA)
Example: Consider the CFG S S+S|S*S|4
Following is the PDA accepting the corresponding CFL
4 + *
READ1 READ3
READ2
ACCEPT
START +
S * ∆
PUSH1 S POP ∆ READ4
S S PUSH5 S
PUSH2 S
PUSH3 + PUSH6 *
PUSH4 S PUSH7 S
Push Down Automata (PDA)
The string 4 + 4 * 4 traces the path shown in the following table
STATE STACK TAPE STATE STACK TAPE
READ2 S 4*4
START ∆ 4+4*4
POP ∆ 4*4
PUSH1 S S 4+4*4 PUSH5 S S 4*4
PUSH6 * *S 4*4
POP ∆ 4+4*4 PUSH7 S S*S 4*4
PUSH2 S S 4+4*4 POP *S 4*4
READ1 *S *4
PUSH3 + +S 4+4*4 POP S *4
PUSH4 S S+S 4+4*4 READ3 S 4
POP ∆ 4
POP +S 4+4*4
READ1 ∆ ∆
READ1 +S +4*4 POP ∆ ∆
READ4 ∆ ∆
POP S +4*4
ACCEPT ∆ ∆
Push Down Automata (PDA)
Note
It may be noted that the letters are deleted from the TAPE
instead of underlined.
It may also be noted that the choice of path at POP state
can be determined by the left most deviation of the string
belonging to the CFL.
Chapter # 15
STACK TAPE
B aab
The POP state is entered and to accommodate the production B
b, READ2 state is entered and the letter b is read from the TAPE
STACK TAPE
aab
The ∆ shown in the ∆STACK indicates that there are no
nonterminals in the working string and ∆ is read from the STACK
which leads to READ3 state where the ∆ is read from the TAPE
and the ACCEPT state is entered which shows that the word aab
is accepted by the PDA.
PDA corresponding to CFG
Following is the table showing all the observations discussed above, for
Left most STATE STACK TAPE
the word aab derivation
START ∆ aab
S PUSH S S aab
POP ∆ aab
PUSH B B aab
AB PUSH A AB aab
POP B aab
PUSH C CB aab
CCB PUSH C CCB aab
POP CB aab
aCB READ1 CB aab
POP B aab
aaB READ1 B aab
POP ∆ aab
aab READ2 ∆ aab
POP ∆ aab
READ3 ∆ aab
ACCEPT ∆ aab
PDA corresponding to CFG
Following is an example of building the PDA corresponding
to the given CFG:
Example:
Consider the following CFG
S XY
X aX | bX |a
Y Ya | Yb | a
First of all, converting the CFG to be in CNF, introduce the nonterminals
A and B as
Aa
Bb
PDA corresponding to CFG
The following CFG is in CNF
S XY
X AX | BX |a
Y YA | YB | a
Aa
Bb
The PDA corresponding to the above CFG will be
PDA corresponding to CFG
a a a b
READ1 READ3 READ4
READ2
B
START A ACCEPT
X Y
∆
PUSH S POP ∆ READ5
S
X Y
X
Y
PUSH Y PUSH X PUSH X PUSH A PUSH B
S
X Y
X
Y
PUSH Y PUSH X PUSH X PUSH A PUSH B
becomes
READ7 a READ8 b
b
PDA corresponding to CFG
Becomes PUSH a
a
READ7 a POP b PUSH b READ7 b
$
b PUSH $
To satisfy condition 4,
POP4 a POP5 b
becomes
a b
POP4 HERE POP5
PDA corresponding to CFG
To satisfy condition 5 READ1 a
POP1
b READ2
a
READ3
becomes
POP1 a
PUSH a
a
READ1 RD7 READ2
a b
POP2 PUSH b
a b
PUSH a
ACCEPT $ POP3
b a
READ1 POP1 HERE POP2
a a
a b
READ2
POP5 POP6
∆
a $ $
PUSH a PUSH $ ACCEPT POP3
START, READ, HERE and ACCEPT states are called the joints of
the machine. Between two consecutive joints on a path exactly one
character is popped and any number of characters can be pushed.
The PDA which is in the conversion form can be supposed to be
the set of joints with path segments in between, similar to a TG
PDA corresponding to CFG
START READ1 HERE
READ2
ACCEPT