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

Automata

The document discusses Push Down Automata (PDA), a class of machines that can accept context-free languages (CFLs) using a stack for memory. It explains the structure of PDAs, including input tapes, states (START, ACCEPT, REJECT, READ), and operations (PUSH, POP). Examples illustrate how PDAs process strings and demonstrate their capabilities compared to finite automata.

Uploaded by

Asma Ayub
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 views27 pages

Automata

The document discusses Push Down Automata (PDA), a class of machines that can accept context-free languages (CFLs) using a stack for memory. It explains the structure of PDAs, including input tapes, states (START, ACCEPT, REJECT, READ), and operations (PUSH, POP). Examples illustrate how PDAs process strings and demonstrate their capabilities compared to finite automata.

Uploaded by

Asma Ayub
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/ 27

Language Theory and Finite Automata

Lecture No 15

Dr. Nazir Ahmad Zafar


Push Down Automata (PDA)
A new format for FAs
• A class of machines (FAs) has been discussed accepting the
regular language i.e. corresponding to a regular language there
is a machine in this class, accepting that language and
corresponding to a machine of this class there is a regular
language accepted by this machine.
• It is discussed there is CFG corresponding to regular language
and CFGs also define some non-regular languages as well
• There is a question whether there is a class of machines
accepting the CFLs? The answer is yes.
• The new machines which are to be defined are more powerful
and can be constructed with the help of FAs with new format.
Dr. Nazir Ahmad Zafar
Push Down Automata (PDA)
Input TAPE
• The part of an FA, where the input string is placed before it is run, is
called the input TAPE.
• The input TAPE is supposed to accommodate all possible strings.
The input TAPE is partitioned with cells, so that each letter of the
input string can be placed in each cell. The input string abbaa is
shown in the following input TAPE.
Cell i Cell ii Cell iii
a b b a a ∆ ∆ .

• The character ∆ indicates a blank in the TAPE. The input string is


read from the TAPE starting from the cell (i). It is assumed that
when first ∆ is read, the rest of the TAPE is supposed to be blank.

Dr. Nazir Ahmad Zafar


Push Down Automata (PDA)
The START state START
This state is like initial state of an FA & is
represented by
An ACCEPT state
This state is like a final state of an FA and
is expressed by ACCEPT
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.

Dr. Nazir Ahmad Zafar


Push Down Automata (PDA)
A READ state
a
• This state is to read an input letter
READ b
and lead to some other state.

The READ state is expressed by
Example 01
• Before some other states are
defined consider the following b a
a
example of an FA along with its x- y+
b
new format

Dr. Nazir Ahmad Zafar


Push Down Automata (PDA)
• DFA b a
a

x- y+
• New Format (PDA) b

START
b
READ a READ ∆
b
∆ a

REJECT ACCEPT

Note: The ∆-edges start only from READ boxes and lead to halt states.

Dr. Nazir Ahmad Zafar


Push Down Automata (PDA)
Example 2 a a,b
b
The above FA accepts the language 1 b +
-
expressed by (a+b)*bb(a+b)* a

START
a a,b

a READ b READ b READ

∆ ∆ ∆
REJECT REJECT ACCEPT

Dr. Nazir Ahmad Zafar


Push Down Automata (PDA)
PUSHDOWN STACK or PUSHDOWN STORE
• PUSHDOWN STACK is a place where the input letters
can be placed until these letters are referred again. It can
store as many letters as one can in a long column.
• Initially the STACK is supposed to be empty i.e. each of
its storage location contains a blank.

Dr. Nazir Ahmad Zafar


Push Down Automata (PDA)
PUSH
• A PUSH operator adds a new letter at the top of STACK,
for e.g. if the letters a, b, c and d are pushed to the STACK
that was initially blank, the STACK can be shown as
The PUSH state is expressed by
PUSH a

• When a letter is pushed, it replaces the existing letter and


pushes it one position below

Dr. Nazir Ahmad Zafar


Push Down Automata (PDA)
POP and STACK
• POP is an operation that takes out a letter from the top of
the STACK. The rest of the letters are moved one location
up. POP state is expressed as

b
POP a

Dr. Nazir Ahmad Zafar


Push Down Automata (PDA)
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

Dr. Nazir Ahmad Zafar


Push Down Automata (PDA)
Example 3
• Consider the following PDA
START

PUSH a a READ1 ∆

b
b

POP1 a READ2 ∆ POP2

a,b
b, ∆ ∆

REJECT ACCEPT
REJECT

Dr. Nazir Ahmad Zafar


Push Down Automata (PDA)
• 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 ∆ ∆  

Dr. Nazir Ahmad Zafar


Push Down Automata (PDA)
• 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

Dr. Nazir Ahmad Zafar


Push Down Automata (PDA)
• 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

Dr. Nazir Ahmad Zafar


Push Down Automata (PDA)
• 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 a a b b b ∆ ∆ 
a
TAPE a a a b b b ∆ ∆  a a
∆ ∆ ∆
  
a a a b b b ∆ ∆ 
  

The above PDA accepts the language {anbn: n = 0, 1, 2, … }

Dr. Nazir Ahmad Zafar


Push Down Automata (PDA)
Note: The process of running the string aaabbb can also be
expressed in the following table.
STATE STACK TAPE STATE STACK TAPE
START ∆… aaabbb∆ … READ2 aa∆ … aaabbb∆ …
READ1 ∆… aaabbb∆ …
POP1 a∆ … aaabbb∆ …
PUSH a a∆ … aaabbb∆ …
READ2 a∆ … aaabbb∆ …
READ1 a∆ … aaabbb∆ …
PUSH a aa∆ … aaabbb∆ … POP1 ∆… aaabbb∆ …
READ1 aa∆ … aaabbb∆ … READ2 ∆… aaabbb∆ …
PUSH a aaa∆ … aaabbb∆ … POP2 ∆… aaabbb∆ …
READ1 aaa∆ … aaabbb∆ …
ACCEPT ∆… aaabbb∆ …
POP1 aa∆ … aaabbb∆ …

Dr. Nazir Ahmad Zafar


Push Down Automata (PDA)
Note: It may be noted that the TAPE alphabet Σ and STACK
alphabet Γ , may be different in general and hence the PDA
equivalent to that accepting {an bn : n=0,1,2,3…}
START


PUSH X a READ1

b
b

POP1 X READ2 ∆ X POP2


a ∆
REJECT ACCEPT

Dr. Nazir Ahmad Zafar


Push Down Automata (PDA)
Example 04
• Consider the following FA corresponding to the EVEN-
EVEN language
a
±
a

b b b b

a
• The corresponding PDA will be

Dr. Nazir Ahmad Zafar


Push Down Automata (PDA)
ACCEPT REJECT
a
∆ ∆

START b
b
a

a
b b


a ∆
REJECT
REJECT

Dr. Nazir Ahmad Zafar


Push Down Automata (PDA)
Nondeterministic PDA
• Like TGs and NFAs, if in PDA there are more than one
outgoing edges at READ or POP states with one label, then it
creates nondeterminism and PDA is nondeterministic.
• In nondeterministic PDA no edge is labeled by string of
terminals or nonterminals, like 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

Dr. Nazir Ahmad Zafar


Push Down Automata (PDA)
Example 5
START a
POP1
a a
b
a
PUSH a READ1 b
b
POP2 READ2
PUSH b b ∆

POP3

ACCEPT

Dr. Nazir Ahmad Zafar


Push Down Automata (PDA)
• Here the nondeterminism can be observed at state READ1.
It is observed that above PDA accepts the language

• EVENPALINDROME = {w = reverse(w): w  {a, b}*}


= {Λ, aa, bb, aaaa, abba, baab, bbbb, …}

• Now the definition of PDA including the possibility of


nondeterminism may be given as follows

Dr. Nazir Ahmad Zafar


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).
Dr. Nazir Ahmad Zafar
Push Down Automata (PDA)
Example 6: Consider the CFG S  S+S|S*S|4
Following is the PDA accepting the corresponding CFL
4 + *
READ1 READ3
READ2
ACCEPT
START
S
+ * ∆
∆ READ4
PUSH1 S POP
S S
PUSH2 S PUSH5 S

PUSH3 + PUSH6 *

PUSH4 S PUSH7 S

Dr. Nazir Ahmad Zafar


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 ∆ ∆

Dr. Nazir Ahmad Zafar


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.

Dr. Nazir Ahmad Zafar

You might also like