0% found this document useful (0 votes)
35 views22 pages

Chapter 5 PUSHDOWN AUTOMATA by Hatem TnrhLz5

Uploaded by

Rakshith P CSE
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views22 pages

Chapter 5 PUSHDOWN AUTOMATA by Hatem TnrhLz5

Uploaded by

Rakshith P CSE
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

Chapter 5

PUSHDOWN AUTOMATA

BY: Dr. Hatem Moharram


PUSHDOWN AUTOMATA
In this section we introduce a new type of computational model called
pushdown automata.
These automata are like nondeterministic finite automata but have an extra
component called a stack. The stack provides additional memory beyond
the finite amount available in the control.
The stack allows pushdown automata to recognize some nonregular languages.
Pushdown automata are equivalent in power to context-free grammars. This
equivalence is useful because it gives us two options for proving that a
language is context free.
We can give either a context-free grammar generating it or a
pushdown automaton recognizing it. Certain languages are more easily
described in terms of generators, whereas others are more easily described by
recognizers. Dr. Hatem Moharram
The following figure is a schematic representation of a finite
automaton.
The control represents the states and transition function, the tape
contains the input string, and the arrow represents the input head,
pointing at the next input symbol to be read.

With the addition of a stack component we


obtain a schematic representation of a
pushdown automaton, as shown in the
following figure.
Dr. Hatem Moharram
A pushdown automaton (PDA) can write symbols on the stack and
read them back later.

Writing a symbol “pushes down” all the other symbols on the stack.

At any time the symbol on the top of the stack can be read and
removed. The remaining symbols then move back up.

Writing a symbol on the stack is often referred to as pushing the


symbol, and removing a symbol is referred to as popping it.
A stack is valuable because it can hold an unlimited amount of information.

Recall that a finite automaton is unable to recognize the language {0n1n|n0}


because it cannot store very large numbers in its finite memory. A PDA is able to
recognize this language because it can use its stack to store the number of 0s it
has seen. Dr. Hatem Moharram
to recognize the language {0n1n|n0}; Read symbols from the input. As each
0 is read, push it onto the stack.

As soon as 1s are seen, pop a 0 off the stack for each 1 read.

If reading the input is finished exactly when the stack becomes empty of 0s,
accept the input.

If the stack becomes empty while 1s remain or if the 1s are finished while the
stack still contains 0s or if any 0s appear in the input following 1s, reject the
input.

Dr. Hatem Moharram


pushdown automata may be nondeterministic. Deterministic and
nondeterministic pushdown automata are not equivalent in power.

Nondeterministic pushdown automata recognize certain languages that no


deterministic pushdown automata can recognize.

Recall that deterministic and nondeterministic finite automata do recognize the


same class of languages, so the pushdown automata situation is different.

We focus on nondeterministic pushdown automata because these automata are


equivalent in power to context-free grammars.

Dr. Hatem Moharram


FORMAL DEFINITION OF A PUSHDOWN AUTOMATON

we specify both an input alphabet  and a stack alphabet Γ .

Recall that  =   {} and Γ  = Γ  {}.

The domain of the transition function is Q ×  × Γ . Thus the current


state, next input symbol read, and top symbol of the stack determine
the next move of a pushdown automaton.

Either symbol may be , causing the machine to move without reading


a symbol from the input or without reading a symbol from the stack.

Dr. Hatem Moharram


For the range of the transition function we need to consider what to
allow the automaton to do when it is in a particular situation.

It may enter some new state and possibly write a symbol on the top of
the stack. The function  can indicate this action by returning a
member of Q together with a member of Γ, that is, a member of Q × Γ.

Because we allow nondeterminism in this model, a situation may have


several legal next moves.

The transition function incorporates nondeterminism in the usual way,


by returning a set of members of Q × Γ, that is, a member of P(Q × Γ).
Putting it all together, our transition
function takes the form  : Q ×  × Γ P (Q × Γ).
Dr. Hatem Moharram
DEFINITION 2.13
A pushdown automaton is a 6-tuple (Q,  , Γ, , q0, F), where Q,  , Γ, and
F are all finite sets, and
1. Q is the set of states,
2.  is the input alphabet,
3. Γ is the stack alphabet,
4.  : Q ×  × Γ P (Q × Γ) is the transition function,
5. q0  Q is the start state, and
6. F  Q is the set of accept states.

Dr. Hatem Moharram


A pushdown automaton M = (Q,  , Γ, , q0, F) computes as follows.
It accepts input w if w can be written as w = w1 w2 · · · wm, where each wi  
and sequences of states r0, r1, . . . , rm  Q and strings s0, s1, . . . , sm  Γ* exist
that satisfy the following three conditions.
The strings si represent the sequence of stack contents that M has on
the accepting branch of the computation.
1. r0 = q0 and s0 = . This condition signifies that M starts out properly,
in the start state and with an empty stack.
2. For i = 0, . . . ,m-1, we have (ri+1, b)  (ri, wi+1, a), where si = at and si+1
= bt for some a, b  Γ and t  Γ*. This condition states that M moves
properly according to the state, stack, and next input symbol.
3. rm  F. This condition states that an accept state occurs at the input
end.
Dr. Hatem Moharram
This means at state q1, if we encounter an input string ‘a’ and top
symbol of the stack is ‘b’, then we pop ‘b’, push ‘c’ on top of the stack
and move to state q2.

Dr. Hatem Moharram


We can also use a state diagram to describe a PDA, We write “a,b  c”
to signify that when the machine is reading an a from the input, it may replace
the symbol b on the top of the stack with a c.

a a

q b p c

Any of a, b, and c may be .

Dr. Hatem Moharram


If a is  (,b  c), the machine may make
this transition without reading any symbol  
from the input.
q b p c

If b is  (a,   c), the machine may make a a


this transition without reading and popping
any symbol from the stack (means that a q p c
push operation performs at stack).

a a
If c is  (a, b ), the machine does not
write any symbol on the stack when going
q b p
along this transition (means that a pop
operation performs at stack). Dr. Hatem Moharram
EXAMPLES OF PUSHDOWN AUTOMATA
EXAMPLE 2.14
The following is the formal description of the PDA that recognizes
the language {0n1n| n 0}. Let M1 be (Q,  , Γ, , q1, F) , where
Q = {q1, q2, q3, q4},
 ={0,1}
Γ ={0, $}
F = {q1, q4}, and
 is given by the following table, wherein blank entries signify .

Dr. Hatem Moharram


The formal definition of a PDA contains no explicit mechanism to allow
the PDA to test for an empty stack. This PDA is able to get the same
effect by initially placing a special symbol $ on the stack. Then if it
ever sees the $ again, it knows that the stack effectively is empty.

Dr. Hatem Moharram


EXAMPLE 2.16
This example illustrates a pushdown automaton that recognizes the
language {aibjck| i, j, k 0 and i = j or i = k}.

Informally, the PDA for this language works by first reading and
pushing the a’s. When the a’s are done, the machine has all of them on
the stack so that it can match, them with either the b’s or the c’s.

Think of the machine as having two branches of its nondeterminism,


one for each possible guess. If either of themmatches, that branch
accepts and the entire machine accepts.

Dr. Hatem Moharram


Dr. Hatem Moharram
EXAMPLE 2.18
give a PDA M3 recognizing the language {wwR|w  {0,1}}.
Recall that wR means w written backwards. The informal description
and state diagram of the PDA follow.

Begin by pushing the symbols that are read onto the stack. At each
point, nondeterministically guess that the middle of the string has
been reached and then change into popping off the stack for each
symbol read, checking to see that they are the same. If they were
always the same symbol and the stack empties at the same time as the
input is finished, accept; otherwise reject.

Dr. Hatem Moharram


Dr. Hatem Moharram
Example:
Give pushdown automata that recognize the following language; A = { w ∈ {0, 1} ∗
| w contains at least three 1s }
Ans.:

Note that A is a regular language, so the language has a DFA. We can


easily convert the DFA into a PDA by using the same states and
transitions and never push nor pop anything from the stack.

Dr. Hatem Moharram


Example:
Give pushdown automata that recognize the following language; C = {w ∈ {0,
1}∗ | w = wR }
Ans.:

The length of a string w ∈ C can be either even or odd. If it’s even, then there is no
middle symbol in w, so the first half of w is pushed on the stack, we move from q2
to q3 without reading, pushing, or popping anything, and then match the second
half of w to the first half in reverse order by popping the stack. If the length of w is
odd, then there is a middle symbol in w, and the description of the PDA in part (b)
applies.
Dr. Hatem Moharram
Example:
Give pushdown automata that recognize the following language; E = { ai bj ck |
i, j, k ≥ 0 and i+j = k }
Ans.:

For every a and b read in the first part of the string, the PDA pushes an
x onto the stack. Then it must read a c for each x popped off the stack.

Dr. Hatem Moharram

You might also like