Professional Documents
Culture Documents
Non-Deterministic Pushdown Automata
Non-Deterministic Pushdown Automata
Models of Computation
(pushdown)
stack
input head
(left to right, read-only)
stack head
(push/pop)
finite control
Models of Computation
In each step, the NPDA pops the top symbol off the stack; based on (1) this
symbol, (2) the input symbol currently reading, and (3) its current state, it can
1. push a sequence of symbols (possibly ) onto the stack
2. move its read head one cell to the right, and
3. enter a new state
according to the transition rule
of the machine.
We allow -transition: an NPDA can pop and push without reading the next input
symbol or moving its read head.
Note: an NPDA can only access the top of stack symbol in each step.
Models of Computation
Example: input is [ [ ] [ ] ]
Think of an NPDA as (representing) an
Definition of an NPDA
1 ,WJ
1 $U&/6
1 a6E
1 V
bc
X#YNZ7[\^].!_0
and
! .
`A#Q
Note: An NPDA is strictly more powerful than a deterministic PDA. We shall not
consider the latter specifically here.
Models of Computation
Configuration
A configuration of
is an element of
!"
state, (2) the portion of the input yet unread (i.e. under and to the right of the input
head) and (3) the current stack contents.
The start configuration is
#%$'&)(+*,(-/.
. I.e.
its input head scanning the leftmost input symbol and the stack containing only
The next-configuration relation
describes how
If
#%$2(435.678#:9;(=<>(+?/.
#:9;(=<@>(G?BCH.I0
(The input symbol
<
#%$J(+@>(43>CH.
If
#%$2(435.678#:9;(
'(G?.
#L9M(+@>(G?BCH.N0
and CD6E
#%$2(+@O(43PCH.
gAhGi
&
0 l
krqts\u
0 l
and define
from
0 l
kpo
mRn
mRn
just if
k
0
vxwcf
l
l
0
q
w
0
, as follows:
wz0
, written
l
0 l
iff
follows
$,6EV and
#%$J(
'(43M. . Configurations of the form #%$2(
'(43M.
, we have
The language of
by
, written
S#%z.
Models of Computation
$,6
#Q$J(
'(
.-f
Models of Computation
\JO
High-level description:
1. Push the input symbols onto the stack, one at a time.
2. Non-deterministically guess that the middle of the string has been reached at
some point during 1, and then change into popping off the stack for each
symbol read, checking to see if they (i.e. symbols just popped and just read)
are the same.
3. If they are always the same symbols, and the stack empties at the same time
as the input is finished, accept.
Models of Computation
\JO
Implementation-level description:
where
#%$U&)(')(-.
[#%$U&)('S.O]
,W
#%$U&)(
'(-.
[#%$u(-.O]
#%$u(=}8(=}J.
[#%$u(
-.]
#%$u(')('.
[#%$u(
-.]
#%$ u (
'(-/.
[#%$(
-.]
where
Models of Computation
}8('
10
X
X
\JO
push
=+N
pop
#%$%(43M.67#%$2(=<O(-.
to
$ .
Models of Computation
11
#%$ & (
})))}8(
/.
#%$ & (
)))}8(
}/.
#%$ & (
))}8(
}/.
#%$ & (
)}8(
)}/.
#%$ u (
)}8(
)}/.
#%$u(
}8(
}/.
#%$u(
}8(
}/.
#%$u(
U(
/.
#%$(
U(
-.
Models of Computation
X
X
=
push
=+X
U
pop
12
Implementation-level description:
Transition diagram:
[#%$2( [
.O]
#%$2(
#%$2(
[( [.
[#%$2(
#%$2(
]( [.
[#%$2().O]
#%$2(t8(T.
[#%$ (
.]
(T.
[ [ .O]
[ [
Models of Computation
13
B Given an NPDA
generating S#_. .
Models of Computation
14
informally:
(a)
is a variable
by the string *
(b)
and replace
(say) on the rhs of the rule (so that the leftmost symbol of
is a terminal < : Read the next input symbol and compare it with < . If they
do not match, then exit (and reject this branch of the nondeterminism).
(c)
Claim:
d
F
accepts S#Y. .
Models of Computation
15
Implementation-level description:
Transition diagram:
2
is given by
#%$U&(tx(.
o
o
[2#%$u(-/.=]
#%$ u (tx(e.
[2#%$ u (=<8FUF.-(
#%$ u (
UH<F.-(
#%$ u (<;(U<O.
#%$u(
.=]
#%$ u (().
#%$u'(tx(.
Models of Computation
[2#%$ u (
.=]
o
[2#%$ u (
.=]
>
;=
U
-
[2#%$ (
.=]
16
#%$U&t(
<x<x(
/.
#%$u(
<x<x(
/.
#%$ u (
<x<x(
<8F/.
#%$ u (
<x(
F/.
#%$u(
<x(
U"<8F/.
#%$u(
<x(
"<8F/.
#%$ u (
<x(
<8F/.
#%$u(
F/.
#%$ u (
/.
#%$ u (
U(
/.
#%$ u (
U(
/.
#%$ (
U(
.
Leftmost derivation:
X0
J4
J4
J4
2
(1)
(1)
(2)
(3)
(2)
(3)
(3)
;=
(3)
<8FN0
<xUH<"UN0
<x<8FUI0
<x<xX0
<x<x
Models of Computation
17
o
where
that accepts by
#T(-S(G(-/.
contains a rule
?
S#%z.
Models of Computation
^u''/
#%$2(=,u''/.678#%$2(=(G?.
S#Y . .
#[$T](-S(+(=(=$2(-,(
t.
where
6KIZ[\^]
. Then we
18
is of the
form
#%$U&)(=u''/.67#L9M(=(G?.
where
6KIZ7[H]
, include in
the transition
$ u ('''(=$
Models of Computation
Intuitively
19
simulates
will be
in at certain future points in the computation, saving those guesses on the stack,
and then verifying later that the guesses were correct.
Lemma.
9B?~$
q
#L9M(+de(+?/. 0
It then follows that
Models of Computation
#%$J(
'(
.
S#%z.
mRn
S#%.
q
#J(+d5(9?_$+. 0 R
#J(
U(
-.
20
o
# u(-S(u(-u-. and
# (-( (- . be context
o
free grammars with Tu\
. Consider the following context free grammars
o
UU
where
,u
S#Y,u.;ZS#Y .
S#YUU
.
S#Y
.
S#YQ++.
Models of Computation
S#Y u .'S#Y .
S#Y,u.G
21