You are on page 1of 20

Theory of Computation (With Automata Theory)

PUSHDOWN AUTOMATA
Pushdown Automata

Introduction

A regular expression can

generate the strings of the
regular language it represents.

A context-free grammar can

generate the strings of the
context-free
language
it
represents.

A finite automaton recognizes

regular languages.

The machine that recognizes

context-free
languages
is
called
a
pushdown
automaton (PDA).

Pushdown Automata

* Property of STI
Page 1 of 20

A PDA is similar to an NFA

stack.

Representation of an NFA:

NFA

Input String

Pushdown Automata

* Property of STI
Page 2 of 20

Theory of Computation (With Automata Theory)

Representation of a PDA:
PDA

Input String
a
b

Stack
a
b

The stack follows a last-in,

first-out (LIFO) structure.

Pushdown Automata

* Property of STI
Page 3 of 20

Operations that can be done

on the stack are push (add a
symbol to the top of the stack)
and pop (remove a symbol
from the top of the stack).

State transitions in a PDA

depend on the current state,
the incoming input symbol,
and the symbol at the top of
the stack.

memory beyond what is
available in an NFA (as
represented by the states).

PDAs are more powerful than

NFAs because they can
recognize some non-regular
languages.

Pushdown Automata

* Property of STI
Page 4 of 20

Theory of Computation (With Automata Theory)

Case Study:
Consider the non-regular
language L1 = {0n1n n 0}.
There is no NFA that can
recognize this language but a
PDA can be constructed to
recognize it.
PDA Operation:

1. Read each symbol of the

input string.
2. While the input is a 0, push
it onto the stack.
3. While the input symbol is a
1, pop a 0 off the stack.
4. If there is no more input
symbol and the stack is
empty, the input string is
accepted.
Pushdown Automata

* Property of STI
Page 5 of 20

Automata

A pushdown automaton is a 6tuple (Q, , , , q0, F), where

Q, , , and F are all finite
sets, and
1. Q is the set of states,
2.

3.

4.

5. q0 Q and is the start

state, and
6. F Q and is the set of final
states.
Pushdown Automata

* Property of STI
Page 6 of 20

The stack alphabet is the set

of symbols that can be pushed
onto the stack. It may or may
not be the same as the input
string alphabet .

Transitions in a PDA
In an NFA, transitions are
represented by:
(qi, 0) = qj
This equation indicates that if
the current state is state qi and
the input is 0, the NFA goes to
state qj. State transitions are
therefore determined by the
current state and the input
symbol.

Pushdown Automata

* Property of STI
Page 7 of 20

Theory of Computation (With Automata Theory)

In a PDA, transitions
represented by:

are

(qi, 0, a) = (qj, b)
This equation indicates that if
the current state is state qi and
the input symbol is 0, and the
symbol at the top of the stack
is a, the PDA goes to state qj
and pushes the symbol b onto
the stack.
State transitions are thus
determined
by the current
state, the input symbol, and
the symbol at the top of the
stack.

Pushdown Automata

* Property of STI
Page 8 of 20

PDA State Diagrams

PDA state diagrams are similar
to NFA state diagrams except
for the labels of the transition
edges.
Example:

a, b c

qi

qj

The label a, b c means that

if the input symbol is a and the
symbol read from the top of
the stack is b, then the PDA
goes to state qj and it pushes
the symbol c unto the stack.
Pushdown Automata

* Property of STI
Page 9 of 20

Theory of Computation (With Automata Theory)

symbol at the top of the stack
implies a pop operation. The
label a, b c implies that the
symbol b was popped off the
stack.
Furthermore, any of the
symbols a, b, c in the given
label can also be the empty
string .
1. If a = , the PDA makes
the transition without any
input symbol.
2. If b = , the PDA makes
the
transition
without
the stack.
3. If c = , the PDA does not
push any symbol onto the
stack.
Pushdown Automata

* Property of STI
Page 10 of 20

In order for the PDA to

determine if the stack is
empty, a special symbol will be
designated as the stack empty
symbol.

This symbol will be pushed

onto the stack every time a
computation is started.

The symbol that will be used

here will be the dollar sign (\$).

So, any time the PDA sees

that the symbol at the top of
the stack is \$, then the stack is
considered empty.

Pushdown Automata

* Property of STI
Page 11 of 20

Theory of Computation (With Automata Theory)

Sample Transitions
0, a b

top of the
stack

qi

qj

a
x
y
\$

b
x
y
\$

stack before
transition

stack after
transition

top of the
stack

0, a a

top of the
stack

Pushdown Automata

qi

qj

a
x
y
\$

a
x
y
\$

stack before
transition

stack after
transition

top of the
stack

* Property of STI
Page 12 of 20

Theory of Computation (With Automata Theory)

0, e b

top of the
stack

qi

qj

a
x
y
\$

b
a
x
y
\$

stack before
transition

stack after
transition

top of the
stack

0, a e

top of the
stack

Pushdown Automata

qi

qj

a
x
y
\$

x
y
\$

stack before
transition

stack after
transition

top of the
stack

* Property of STI
Page 13 of 20

0, e e

top of the
stack

qi

qj

a
x
y
\$

a
x
y
\$

stack before
transition

stack after
transition

top of the
stack

It was mentioned earlier that a

PDA can make a state
transition without any input
symbol.
This implies that PDAs are
nondeterministic.

Pushdown Automata

* Property of STI
Page 14 of 20

The PDA P1 that can

recognize the non-regular
language L1 = {0n1n n 0} is:

q0

q3

e, e \$

q1

0, e 0

Pushdown Automata

e, \$ e

1, 0 e

q2

1, 0 e

* Property of STI
Page 15 of 20

The given PDA can be formally

defined as P1 = (Q, , , , q0,
F) where:

2.

= {0, 1}

3.

= {0, \$}

4. q0 is the start state.

5. F = {q0, q3}

Pushdown Automata

* Property of STI
Page 16 of 20

6. The transition function

given by:

Input Stack

is

Current State
q0

q1

q2

q3

0
0

\$
(q1, 0)

0
1

(q2, )

(q2, )

\$
0
\$

(q3, )

(q1, \$)

Pushdown Automata

* Property of STI
Page 17 of 20

Example 2:

The PDA P2 that can

recognize the non-regular
language L2 = {wwR w
{0,
1}*} is:

q0

q3

e, e \$

q1

0, e 0
1, e 1

Pushdown Automata

e, \$ e

e, e e

q2

0, 0 e
1, 1 e

* Property of STI
Page 18 of 20

Example 3:

The PDA P3 that can

recognize the non-regular
language L3 = {aibjck i, j, k 0
and i = j or i = k} is:

b, a e

q0

q2

e, \$ e

q3

e,

e, e \$

c, e e

q1

a, e a

Pushdown Automata

e, e e

q4

b, e e

e, e e

q5

e, \$ e

q6

c, a e

* Property of STI
Page 19 of 20

Exercises:

Construct a PDA that can

recognize the language L4 =
{w w is composed of an equal
number of 0s and 1s}.

Construct a PDA that can

recognize the language L5 =
{02n1n n 1}.

Pushdown Automata

* Property of STI
Page 20 of 20