pushdown automata - cse 211 (theory of computation)teacher.buet.ac.bd/atif/courses/pda_6.pdf ·...

21
CSE 211 Pushdown Automata CSE 211 (Theory of Computation) Atif Hasan Rahman Lecturer Department of Computer Science and Engineering Bangladesh University of Engineering & Technology Adapted from slides by Dr. Muhammad Masroor Ali Atif Hasan Rahman Pushdown Automata CSE 211 PDA The context free languages have a type of automaton that denes them. This automaton is called “pushdown automaton.” It is an extension of the nondeterministic nite automaton with -transitions. The pushdown automaton is essentially an -NFA with the addition of a stack. The stack can be read, pushed, and popped only at the top, just like the “stack” data structure. Atif Hasan Rahman Pushdown Automata CSE 211 PDA Languages which can not be Recognized by an FA Consider ww R : w ∈{a, b} . It is context-free, since it is generated by the grammar with rules S aSa, S bSb, and S . It would seem that any device that recognizes the strings in this language by reading them from left to right must “remember” the rst half of the input string, so that it can check it — in reverse order — against the second half of the input. Atif Hasan Rahman Pushdown Automata CSE 211 PDA Languages which can . . . an FA It is not surprising that this function cannot be performed by a nite automaton. If, however, the machine is, capable of accumulating its input string as it is read, appending symbols one at a time to a stored string, then it could nondeterministically guess when the center of the input has been reached, and thereafter check the symbols off from its memory one at a time. The storage device need not be a general-purpose one. A sort of “stack” or “pushdown store,” allowing read and write access only to the top symbol, would do nicely. Atif Hasan Rahman Pushdown Automata CSE 211 PDA Languages which can . . . an FA Atif Hasan Rahman Pushdown Automata CSE 211 PDA Languages which can . . . an FA (()(())(()(()))) To take another example, the set of strings of balanced parentheses is also nonregular. However, computer programmers are familiar with a simple algorithm for recognizing this language: Start counting at zero, add one for every left parenthesis, and subtract one for every right parenthesis. If the count either goes negative at any time, or ends up different from zero, then the string should be rejected as unbalanced; otherwise it should be accepted. Now, a counter can be considered as a special case of a stack, on which only one kind of symbol can be written. Atif Hasan Rahman Pushdown Automata

Upload: haminh

Post on 18-Aug-2018

249 views

Category:

Documents


2 download

TRANSCRIPT

CSE 211

Pushdown AutomataCSE 211 (Theory of Computation)

Atif Hasan Rahman

LecturerDepartment of Computer Science and EngineeringBangladesh University of Engineering & Technology

Adapted from slides by

Dr. Muhammad Masroor Ali

Atif Hasan Rahman Pushdown Automata

CSE 211 PDA

The context free languages have a type of automaton thatdefines them.

This automaton is called “pushdown automaton.”

It is an extension of the nondeterministic finite automatonwith ε -transitions.

The pushdown automaton is essentially an ε -NFA with theaddition of a stack.

The stack can be read, pushed, and popped only at thetop, just like the “stack” data structure.

Atif Hasan Rahman Pushdown Automata

CSE 211 PDA

Languages which can not be Recognized by an FA

Consider{wwR : w ∈ {a, b}∗}.

It is context-free, since it is generated by the grammar withrules S → aSa, S → bSb, and S → ε .It would seem that any device that recognizes the strings inthis language

by reading them from left to right must “remember” thefirst half of the input string,so that it can check it — in reverse order — againstthe second half of the input.

Atif Hasan Rahman Pushdown Automata

CSE 211 PDA

Languages which can . . . an FA

It is not surprising that this function cannot be performedby a finite automaton.If, however, the machine is,

capable of accumulating its input string as it is read,appending symbols one at a time to a stored string,then it could nondeterministically guess when thecenter of the input has been reached,and thereafter check the symbols off from its memoryone at a time.

The storage device need not be a general-purpose one.

A sort of “stack” or “pushdown store,” allowing read andwrite access only to the top symbol, would do nicely.

Atif Hasan Rahman Pushdown Automata

CSE 211 PDA

Languages which can . . . an FA

Atif Hasan Rahman Pushdown Automata

CSE 211 PDA

Languages which can . . . an FA

(()(())(()(())))To take another example, the set of strings of balancedparentheses is also nonregular.However, computer programmers are familiar with a simplealgorithm for recognizing this language:

Start counting at zero,add one for every left parenthesis,and subtract one for every right parenthesis.If the count either goes negative at any time, or endsup different from zero, then the string should berejected as unbalanced;otherwise it should be accepted.

Now, a counter can be considered as a special case of astack, on which only one kind of symbol can be written.

Atif Hasan Rahman Pushdown Automata

CSE 211 PDA

Informal Introduction

The pushdown automaton is in essence a nondeterministicfinite automaton with ε -transitions permitted.

It has one additional capability: a stack on which it canstore a string of “stack symbols.”

The presence of a stack means that, unlike the finiteautomaton, the pushdown automaton can “remember” aninfinite amount of information.

However, unlike a general purpose computer, which alsohas the ability to remember arbitrarily large amounts ofinformation, the pushdown automaton can only access theinformation on its stack in a last-in-first-out way.

Atif Hasan Rahman Pushdown Automata

CSE 211 PDA

Informal Introduction

As a result, there are languages that could be recognizedby some computer program, but are not recognizable byany pushdown automaton.

In fact, pushdown automata recognize all and only thecontext-free languages.

There are many languages that are context-free, includingsome we have seen that are not regular languages.

There are also some simple-to-describe languages thatare not context-free.

An example of a non-context-free language is{0n1n2n |n ≥ 1}, the set of strings consisting of equalgroups of 0’s, 1’s, and 2’s.

Atif Hasan Rahman Pushdown Automata

CSE 211 PDA

Informal Introduction

As a result, there are languages that could be recognizedby some computer program, but are not recognizable byany pushdown automaton.

In fact, pushdown automata recognize all and only thecontext-free languages.

There are many languages that are context-free, includingsome we have seen that are not regular languages.

There are also some simple-to-describe languages thatare not context-free.

An example of a non-context-free language is{0n1n2n |n ≥ 1}, the set of strings consisting of equalgroups of 0’s, 1’s, and 2’s.

Atif Hasan Rahman Pushdown Automata

CSE 211 PDA

Informal Introduction

We can view the pushdown automaton informally as the devicesuggested in figure.

Atif Hasan Rahman Pushdown Automata

CSE 211 PDA

Informal Introduction

A “finite-state control” reads inputs, one symbol at a time.

Atif Hasan Rahman Pushdown Automata

CSE 211 PDA

Informal Introduction

The pushdown automaton observes the symbol at the topof the stack.

It bases its transition on its current state, the input symbol,and the symbol at the top of stack.

Atif Hasan Rahman Pushdown Automata

CSE 211 PDA

Informal Introduction

Alternatively, it may make a spontaneous transition, usingε as its input instead of an input symbol.

Atif Hasan Rahman Pushdown Automata

Informal Introduction

In one transition, the pushdown automaton:

1. Consumes from the input the symbol that it uses in thetransition.

If ε is used for the input, then no input symbol isconsumed.

Informal Introduction

In one transition, the pushdown automaton:

2. Goes to a new state, which may or may not be the same asthe previous state.

Informal Introduction

abc ⇒

bc

In one transition, the pushdown automaton:

3. Replaces the symbol at the top of the stack by any string.The string could be ε , which corresponds to a pop ofthe stack.

Informal Introduction

abc ⇒

abc

In one transition, the pushdown automaton:

3. Replaces the symbol at the top of the stack by any string.It could be the same symbol that appeared at the top ofthe stack previously; i.e., no change to the stack ismade.

Informal Introduction

abc ⇒

dbc

In one transition, the pushdown automaton:

3. Replaces the symbol at the top of the stack by any string.It could also replace the top stack symbol by one othersymbol.This in effect changes the top of the stack but does notpush or pop it.

Informal Introduction

abc ⇒

edbc

In one transition, the pushdown automaton:

3. Replaces the symbol at the top of the stack by any string.Finally, the top stack symbol could be replaced by twoor more symbols.This has the effect of (possibly) changing the top stacksymbol, and then pushing one or more new symbolsonto the stack.

CSE 211 PDA

Example

Let us consider the language

lwwr ={

wwR |w is in (0 + 1)∗}

This language, often referred to as “w-w-reversed,” is theeven-length palindromes over alphabet {0, 1}.It is a CFL, generated by the grammar Gpal, with theproductions P → 0 and P → 1 omitted.

Atif Hasan Rahman Pushdown Automata

We can design an informal pushdown automaton acceptinglwwr , as follows.

1. Start in a state q0 that represents a “guess” that we have notyet seen the middle.

i.e., we have not seen the end of the string w that is tobe followed by its own reverse.While in state q0, we read symbols and store them onthe stack, by pushing a copy of each input symbol ontothe stack, in turn.

0101↓1011︸ ︷︷ ︸

w

11011010︸ ︷︷ ︸wR

We are in q0 Stack contains

11010

We can design an informal pushdown automaton acceptinglwwr , as follows.

2. At any time, we may guess that we have seen the middle.i.e., the end of w .At this time, w will be on the stack, with the right end ofw at the top and the left end at the bottom.We signify this choice by spontaneously going tostate q1.Since the automaton is nondeterministic, we actuallymake both guesses:

we guess we have seen the end of w ,but we also stay in state q0 and continue to readinputs and store them on the stack.

01011011︸ ︷︷ ︸w

↓ 11011010︸ ︷︷ ︸wR

We switch to q1

Stack contains

11011010

We can design an informal pushdown automaton acceptinglwwr , as follows.

3. Once in state q1, we compare input symbols with the symbolat the top of the stack.

If they match, we consume the input symbol, pop thestack, and proceed.If they do not match, we have guessed wrong; ourguessed w was not followed by wR.This branch dies, although other branches of thenondeterministic automaton may survive and eventuallylead to acceptance.

01011011︸ ︷︷ ︸w

1↓1011010︸ ︷︷ ︸

wR

We are in q1

Stack contains

1011010

We can design an informal pushdown automaton acceptinglwwr , as follows.

4. If we empty the stack, then we have indeed seen some inputw followed by wR.

We accept the input that was read up to this point.

01011011︸ ︷︷ ︸w

1101101↓0︸ ︷︷ ︸

wR

We are in q1 Stack contains 0

CSE 211 PDA

The Formal Definition of Pushdown Automata

Our formal notation for a pushdown automaton (PDA)involves seven components.

We write the specification of a PDA P as follows:

P = (Q, Σ, Γ, δ, q0, Z0, F )

Atif Hasan Rahman Pushdown Automata

The Formal . . . Automata

P = (Q, Σ, Γ, δ, q0, Z0, F )

The components have the following meanings:

Q: A finite set of states, like the states of a finiteautomaton.

Σ: A finite set of input symbols, also analogous to thecorresponding component of a finite automaton.

Γ: A finite stack alphabet.This component, which has nofinite-automaton analog, is the set of symbolsthat we are allowed to push onto the stack.

The Formal . . . Automata

P = (Q, Σ, Γ, δ, q0, Z0, F )

The components have the following meanings:

Q: A finite set of states, like the states of a finiteautomaton.

Σ: A finite set of input symbols, also analogous to thecorresponding component of a finite automaton.

Γ: A finite stack alphabet.This component, which has nofinite-automaton analog, is the set of symbolsthat we are allowed to push onto the stack.

The Formal . . . Automata

P = (Q, Σ, Γ, δ, q0, Z0, F )

The components have the following meanings:

Q: A finite set of states, like the states of a finiteautomaton.

Σ: A finite set of input symbols, also analogous to thecorresponding component of a finite automaton.

Γ: A finite stack alphabet.This component, which has nofinite-automaton analog, is the set of symbolsthat we are allowed to push onto the stack.

The Formal . . . Automata

P = (Q, Σ, Γ, δ, q0, Z0, F )

δ: The transition function.As for a finite automaton, δ governs thebehavior of the automaton.Formally, δ takes as argument a tripleδ(q, a, X ), where:

1. q is a state in Q.2. a is either an input symbol in Σ or a = ε ,

the empty string, which is assumed not tobe an input symbol.

3. X is a stack symbol, that is, a memberof Γ.

The Formal . . . Automata

P = (Q, Σ, Γ, δ, q0, Z0, F )

δ(q, a, X ) = (p, γ)

The output of δ is a finite set of pairs (p, γ), wherep is the new state,and γ is the string of stack symbols that replaces X atthe top of the stack.

For instance,if γ = ε , then the stack is popped,if γ = X , then the stack is unchanged,and if γ = YZ , then X is replaced by Z , and Y ispushed onto the stack.

The Formal . . . Automata

P = (Q, Σ, Γ, δ, q0, Z0, F )

q0: The start state.The PDA is in this state before making anytransitions.

Z0: The start symbol.Initially, the PDA’s stack consists of oneinstance of this symbol, and nothing else.

F : The set of accepting states, or final states.

CSE 211 PDA

Example

Let us design a PDA P to accept the language lwwr .

There are a few details that we need to understand in orderto manage the stack properly.

We shall use a stack symbol Z0 to mark the bottom of thestack.

We need to have this symbol present so that, after we popw off the stack and realize that we have seen wwR on theinput, we still have something on the stack to permit us tomake a transition to the accepting state, q2.

Atif Hasan Rahman Pushdown Automata

CSE 211 PDA

Example-continued

The three states:

q0: We are yet to see the midpoint of the string.

01↓011011︸ ︷︷ ︸

w

11011010︸ ︷︷ ︸wR

We remain in q0

q1: We have just seen the midpoint of thestring/crossed the midpoint of the string.

01011011︸ ︷︷ ︸w

↓11011010︸ ︷︷ ︸wR

We switch from q0 to q1

q2: We are finished with the string and it is acceptable.

01011011︸ ︷︷ ︸w

11011010︸ ︷︷ ︸wR

↓ We switch from q1 to q2

Atif Hasan Rahman Pushdown Automata

Thus, our PDA for lwwr can be described asP = ({q0, q1, q2}, {0, 1}, {0, 1, Z0}, δ, q0, Z0, {q2})

where δ is defined by the following rules:

1.i) δ(q0, 0, Z0) = {(q0, 0Z0)} andii) δ(q0, 1, Z0) = {(q0, 1Z0)}.

One of these rules applies initially, when we are in state q0

and we see the start symbol Z0at the top of the stack.

We read the first input, and push it onto the stack, leavingZ0 below to mark the bottom.

↓01011011︸ ︷︷ ︸

w

11011010︸ ︷︷ ︸wR

We are in q0 Z0 ⇒0Z0

Thus, our PDA for lwwr can be described asP = ({q0, q1, q2}, {0, 1}, {0, 1, Z0}, δ, q0, Z0, {q2})

where δ is defined by the following rules:

2.i) δ(q0, 0, 0) = {(q0, 00)},ii) δ(q0, 0, 1) = {(q0, 01)},iii) δ(q0, 1, 0) = {(q0, 10)}, andiv) δ(q0, 1, 1) = {(q0, 11)}.

These four similar rules allow us to stay in state q0 andread inputs, pushing each onto the top of the stack andleaving the previous top stack symbol alone.

01↓011011︸ ︷︷ ︸

w

11011010︸ ︷︷ ︸wR

We remain in q010Z0 ⇒

010Z0

Thus, our PDA for lwwr can be described asP = ({q0, q1, q2}, {0, 1}, {0, 1, Z0}, δ, q0, Z0, {q2})

where δ is defined by the following rules:

3.i) δ(q0, ε , Z0) = {(q1, Z0)},ii) δ(q0, ε , 0) = {(q1, 0)}, andiii) δ(q0, ε , 1) = {(q1, 1)}.

These three rules allow P to go from state q0 to state q1

spontaneously (on ε input), leaving intact whatever symbolis at the top of the stack.

01011011︸ ︷︷ ︸w

↓ 11011010︸ ︷︷ ︸wR

We switch from q0 to q1

11011010Z0 ⇒

11011010Z0

Thus, our PDA for lwwr can be described asP = ({q0, q1, q2}, {0, 1}, {0, 1, Z0}, δ, q0, Z0, {q2})

where δ is defined by the following rules:

4.i) δ(q1, 0, 0) = {(q1, ε )}, andii) δ(q1, 1, 1) = {(q1, ε )}.

Now, in state q1, we can match input symbols against thetop symbols on the stack, and pop when the symbolsmatch.

01011011︸ ︷︷ ︸w

1101↓1010︸ ︷︷ ︸

wR

We remain in q1

1010Z0 ⇒

010Z0

Thus, our PDA for lwwr can be described asP = ({q0, q1, q2}, {0, 1}, {0, 1, Z0}, δ, q0, Z0, {q2})

where δ is defined by the following rules:

5.i) δ(q1, ε , Z0) = {(q2, Z0)}.

Finally, if we expose the bottom-of-stack marker Z0and weare in state q1, then we have found an input of the formwwR.

We go to state q2 and accept.

01011011︸ ︷︷ ︸w

11011010︸ ︷︷ ︸wR

↓ We switch fromq1 to q2

Z0 ⇒ Z0

No “Mixing and Matching”

There may be several pairs that are options for a PDA insome situation.

For instance, suppose δ (q, a, X ) = {(p, YZ ), (r , ε )}.When making a move of the PDA, we have to chose onepair in its entirety.

We cannot pick a state from one and a stack-replacementstring from another.

Thus, in state q, with X on the top of the stack, readinginput a, we could go to state p and replace X by YZ .

Or we could go to state r and pop X .

However, we cannot go to state p and pop X .

And we cannot go to state r and replace X by YZ .

No “Mixing and Matching”

There may be several pairs that are options for a PDA insome situation.

For instance, suppose δ (q, a, X ) = {(p, YZ ), (r , ε )}.When making a move of the PDA, we have to chose onepair in its entirety.

We cannot pick a state from one and a stack-replacementstring from another.

Thus, in state q, with X on the top of the stack, readinginput a, we could go to state p and replace X by YZ .

Or we could go to state r and pop X .

However, we cannot go to state p and pop X .

And we cannot go to state r and replace X by YZ .

No “Mixing and Matching”

There may be several pairs that are options for a PDA insome situation.

For instance, suppose δ (q, a, X ) = {(p, YZ ), (r , ε )}.When making a move of the PDA, we have to chose onepair in its entirety.

We cannot pick a state from one and a stack-replacementstring from another.

Thus, in state q, with X on the top of the stack, readinginput a, we could go to state p and replace X by YZ .

Or we could go to state r and pop X .

However, we cannot go to state p and pop X .

And we cannot go to state r and replace X by YZ .

No “Mixing and Matching”

There may be several pairs that are options for a PDA insome situation.

For instance, suppose δ (q, a, X ) = {(p, YZ ), (r , ε )}.When making a move of the PDA, we have to chose onepair in its entirety.

We cannot pick a state from one and a stack-replacementstring from another.

Thus, in state q, with X on the top of the stack, readinginput a, we could go to state p and replace X by YZ .

Or we could go to state r and pop X .

However, we cannot go to state p and pop X .

And we cannot go to state r and replace X by YZ .

CSE 211 PDA

A Graphical Notation for PDA’s

The list of δ facts is not too easy to follow.

A diagram, generalizing the transition diagram of a finiteautomaton, will make aspects of the behavior of a givenPDA clearer.

We shall therefore introduce and subsequently use atransition diagram for PDA’s.

Atif Hasan Rahman Pushdown Automata

A Graphical Notation for PDA’sWe shall introduce and subsequently use a transition diagramfor PDA’s in which:

a) The nodes correspond to the states of the PDA.

b) An arrow labeled Start indicates the start state

c) And doubly circled states are accepting, as for finiteautomata.

d) The arcs correspond to transitions of the PDA in thefollowing sense.

An arc labeled a, X/α from state q to state p meansthat δ(q, a, X ) contains the pair (p, α ), perhaps amongother pairs.That is, the arc label tells what input is used, and alsogives the old and now tops of the stack.

The only thing that the diagram does not tell us is whichstack symbol is the start symbol.

Conventionally, it is Z0, unless we indicate otherwise.

A Graphical Notation for PDA’sWe shall introduce and subsequently use a transition diagramfor PDA’s in which:

a) The nodes correspond to the states of the PDA.

b) An arrow labeled Start indicates the start state

c) And doubly circled states are accepting, as for finiteautomata.

d) The arcs correspond to transitions of the PDA in thefollowing sense.

An arc labeled a, X/α from state q to state p meansthat δ(q, a, X ) contains the pair (p, α ), perhaps amongother pairs.That is, the arc label tells what input is used, and alsogives the old and now tops of the stack.

The only thing that the diagram does not tell us is whichstack symbol is the start symbol.

Conventionally, it is Z0, unless we indicate otherwise.

A Graphical Notation for PDA’sWe shall introduce and subsequently use a transition diagramfor PDA’s in which:

a) The nodes correspond to the states of the PDA.

b) An arrow labeled Start indicates the start state

c) And doubly circled states are accepting, as for finiteautomata.

d) The arcs correspond to transitions of the PDA in thefollowing sense.

An arc labeled a, X/α from state q to state p meansthat δ(q, a, X ) contains the pair (p, α ), perhaps amongother pairs.That is, the arc label tells what input is used, and alsogives the old and now tops of the stack.

The only thing that the diagram does not tell us is whichstack symbol is the start symbol.

Conventionally, it is Z0, unless we indicate otherwise.

A Graphical Notation for PDA’sWe shall introduce and subsequently use a transition diagramfor PDA’s in which:

a) The nodes correspond to the states of the PDA.

b) An arrow labeled Start indicates the start state

c) And doubly circled states are accepting, as for finiteautomata.

d) The arcs correspond to transitions of the PDA in thefollowing sense.

An arc labeled a, X/α from state q to state p meansthat δ(q, a, X ) contains the pair (p, α ), perhaps amongother pairs.That is, the arc label tells what input is used, and alsogives the old and now tops of the stack.

The only thing that the diagram does not tell us is whichstack symbol is the start symbol.

Conventionally, it is Z0, unless we indicate otherwise.

CSE 211 PDA

Example

The PDA of previous example is represented by the diagramshown.

Atif Hasan Rahman Pushdown Automata

a) The nodes correspond to the states of the PDA.

b) An arrow labeled Start indicates the start state. and doubly circled states areaccepting, as for finite automata.

c) The arcs correspond to transitions of the PDA. An arc labeled a, X/α from state qto state p means that δ(q, a, X) contains the pair (p, α ), perhaps among otherpairs.

P = ({q0, q1, q2}, {0, 1}, {0, 1, Z0}, δ, q0, Z0, {q2})

δ is defined by the following rules:

a) The nodes correspond to the states of the PDA.

b) An arrow labeled Start indicates the start state. and doubly circled states areaccepting, as for finite automata.

c) The arcs correspond to transitions of the PDA. An arc labeled a, X/α from state qto state p means that δ(q, a, X) contains the pair (p, α ), perhaps among otherpairs.

P = ({q0, q1, q2}, {0, 1}, {0, 1, Z0}, δ, q0, Z0, {q2})

δ is defined by the following rules:

1.i) δ(q0, 0, Z0) = {(q0, 0Z0)}

andii) δ(q0, 1, Z0) = {(q0, 1Z0)}.

a) The nodes correspond to the states of the PDA.

b) An arrow labeled Start indicates the start state. and doubly circled states areaccepting, as for finite automata.

c) The arcs correspond to transitions of the PDA. An arc labeled a, X/α from state qto state p means that δ(q, a, X) contains the pair (p, α ), perhaps among otherpairs.

P = ({q0, q1, q2}, {0, 1}, {0, 1, Z0}, δ, q0, Z0, {q2})

δ is defined by the following rules:

2.i) δ(q0, 0, 0) = {(q0, 00)},ii) δ(q0, 0, 1) = {(q0, 01)},iii) δ(q0, 1, 0) = {(q0, 10)},

andiv) δ(q0, 1, 1) = {(q0, 11)}.

a) The nodes correspond to the states of the PDA.

b) An arrow labeled Start indicates the start state. and doubly circled states areaccepting, as for finite automata.

c) The arcs correspond to transitions of the PDA. An arc labeled a, X/α from state qto state p means that δ(q, a, X) contains the pair (p, α ), perhaps among otherpairs.

P = ({q0, q1, q2}, {0, 1}, {0, 1, Z0}, δ, q0, Z0, {q2})

δ is defined by the following rules:

3.i) δ(q0, ε , Z0) = {(q1, Z0)},ii) δ(q0, ε , 0) = {(q1, 0)},

andiii) δ(q0, ε , 1) = {(q1, 1)}.

a) The nodes correspond to the states of the PDA.

b) An arrow labeled Start indicates the start state. and doubly circled states areaccepting, as for finite automata.

c) The arcs correspond to transitions of the PDA. An arc labeled a, X/α from state qto state p means that δ(q, a, X) contains the pair (p, α ), perhaps among otherpairs.

P = ({q0, q1, q2}, {0, 1}, {0, 1, Z0}, δ, q0, Z0, {q2})

δ is defined by the following rules:

4.i) δ(q1, 0, 0) = {(q1, ε )},

andii) δ(q1, 1, 1) = {(q1, ε )}.

a) The nodes correspond to the states of the PDA.

b) An arrow labeled Start indicates the start state. and doubly circled states areaccepting, as for finite automata.

c) The arcs correspond to transitions of the PDA. An arc labeled a, X/α from state qto state p means that δ(q, a, X) contains the pair (p, α ), perhaps among otherpairs.

P = ({q0, q1, q2}, {0, 1}, {0, 1, Z0}, δ, q0, Z0, {q2})

δ is defined by the following rules:

5.i) δ(q1, ε , Z0) = {(q2, Z0)}.

CSE 211 PDA

Instantaneous Descriptions of a PDA

To this point, we have only an informal notion of how aPDA “computes.”

The PDA goes from configuration to configuration, inresponse to input symbols (or sometimes ε ).

In the finite automaton, the state is the only thing that weneed to know about the automaton.

The PDA’s configuration involves both the state and thecontents of the stack.

Being arbitrarily large, the stack is often the more importantpart of the total configuration of the PDA at any time.

It is also useful to represent as part of the configuration theportion of the input that remains.

Atif Hasan Rahman Pushdown Automata

CSE 211 PDA

Instantaneous Descriptions of a PDA

To this point, we have only an informal notion of how aPDA “computes.”

The PDA goes from configuration to configuration, inresponse to input symbols (or sometimes ε ).

In the finite automaton, the state is the only thing that weneed to know about the automaton.

The PDA’s configuration involves both the state and thecontents of the stack.

Being arbitrarily large, the stack is often the more importantpart of the total configuration of the PDA at any time.

It is also useful to represent as part of the configuration theportion of the input that remains.

Atif Hasan Rahman Pushdown Automata

CSE 211 PDA

Instantaneous Descriptions of a PDA

To this point, we have only an informal notion of how aPDA “computes.”

The PDA goes from configuration to configuration, inresponse to input symbols (or sometimes ε ).

In the finite automaton, the state is the only thing that weneed to know about the automaton.

The PDA’s configuration involves both the state and thecontents of the stack.

Being arbitrarily large, the stack is often the more importantpart of the total configuration of the PDA at any time.

It is also useful to represent as part of the configuration theportion of the input that remains.

Atif Hasan Rahman Pushdown Automata

CSE 211 PDA

Instantaneous Descriptions of a PDA

To this point, we have only an informal notion of how aPDA “computes.”

The PDA goes from configuration to configuration, inresponse to input symbols (or sometimes ε ).

In the finite automaton, the state is the only thing that weneed to know about the automaton.

The PDA’s configuration involves both the state and thecontents of the stack.

Being arbitrarily large, the stack is often the more importantpart of the total configuration of the PDA at any time.

It is also useful to represent as part of the configuration theportion of the input that remains.

Atif Hasan Rahman Pushdown Automata

CSE 211 PDA

Instantaneous Descriptions of a PDA

Thus, we shall represent the configuration of a PDA by atriple (q, w , γ), where

1. q is the state,2. w is the remaining input, and3. γ is the stack contents.

Conventionally, we show the top of the stack at the left endof γ and the bottom at the right end.

Such a triple is called an instantaneous description, or ID,of the pushdown automaton.

Atif Hasan Rahman Pushdown Automata

CSE 211 PDA

Instantaneous Descriptions of a PDA

Thus, we shall represent the configuration of a PDA by atriple (q, w , γ), where

1. q is the state,2. w is the remaining input, and3. γ is the stack contents.

Conventionally, we show the top of the stack at the left endof γ and the bottom at the right end.

Such a triple is called an instantaneous description, or ID,of the pushdown automaton.

Atif Hasan Rahman Pushdown Automata

CSE 211 PDA

Instantaneous Descriptions of a PDA

Thus, we shall represent the configuration of a PDA by atriple (q, w , γ), where

1. q is the state,2. w is the remaining input, and3. γ is the stack contents.

Conventionally, we show the top of the stack at the left endof γ and the bottom at the right end.

Such a triple is called an instantaneous description, or ID,of the pushdown automaton.

Atif Hasan Rahman Pushdown Automata

CSE 211 PDA

Instantaneous Descriptions of a PDA

For finite automata, the δ̂ notation was sufficient torepresent sequences of instantaneous descriptionsthrough which a finite automaton moved.

The ID for a finite automaton is just its state.

However, for PDA’s we need a notation that describeschanges in the state, the input, and stack.

Thus, we adopt the “turnstile” notation for connecting pairsof ID’s that represent one or many moves of a PDA.

Atif Hasan Rahman Pushdown Automata

CSE 211 PDA

Instantaneous Descriptions of a PDA

Let P = (Q, Σ, Γ, δ, q0, Z0, F )be a PDA.

Define �P , or just � when P is understood, as follows.

Suppose δ (q, a, X ) contains (p, α ).

Then for all strings w in Σ∗ and β in Γ∗:(q, aw , Xβ) � (p, w , α β)

This move reflects the idea that, by consuming a (whichmay be ε ) from the input and replacing X on top of thestack by α , we can go from state q to state p.

What remains on the input, w , and what is below the top ofthe stack, β, do not influence the action of the PDA.

They are merely carried along, perhaps to influence eventslater.

Atif Hasan Rahman Pushdown Automata

CSE 211 PDA

Instantaneous Descriptions of a PDA

Let P = (Q, Σ, Γ, δ, q0, Z0, F )be a PDA.

Define �P , or just � when P is understood, as follows.

Suppose δ (q, a, X ) contains (p, α ).

Then for all strings w in Σ∗ and β in Γ∗:(q, aw , Xβ) � (p, w , α β)

This move reflects the idea that, by consuming a (whichmay be ε ) from the input and replacing X on top of thestack by α , we can go from state q to state p.

What remains on the input, w , and what is below the top ofthe stack, β, do not influence the action of the PDA.

They are merely carried along, perhaps to influence eventslater.

Atif Hasan Rahman Pushdown Automata

CSE 211 PDA

Instantaneous Descriptions of a PDA

Let P = (Q, Σ, Γ, δ, q0, Z0, F )be a PDA.

Define �P , or just � when P is understood, as follows.

Suppose δ (q, a, X ) contains (p, α ).

Then for all strings w in Σ∗ and β in Γ∗:(q, aw , Xβ) � (p, w , α β)

This move reflects the idea that, by consuming a (whichmay be ε ) from the input and replacing X on top of thestack by α , we can go from state q to state p.

What remains on the input, w , and what is below the top ofthe stack, β, do not influence the action of the PDA.

They are merely carried along, perhaps to influence eventslater.

Atif Hasan Rahman Pushdown Automata

CSE 211 PDA

Instantaneous Descriptions of a PDA

Let P = (Q, Σ, Γ, δ, q0, Z0, F )be a PDA.

Define �P , or just � when P is understood, as follows.

Suppose δ (q, a, X ) contains (p, α ).

Then for all strings w in Σ∗ and β in Γ∗:(q, aw , Xβ) � (p, w , α β)

This move reflects the idea that, by consuming a (whichmay be ε ) from the input and replacing X on top of thestack by α , we can go from state q to state p.

What remains on the input, w , and what is below the top ofthe stack, β, do not influence the action of the PDA.

They are merely carried along, perhaps to influence eventslater.

Atif Hasan Rahman Pushdown Automata

CSE 211 PDA

Instantaneous Descriptions of a PDA

We also use the symbol �∗P , or �∗ when the PDA P is

understood, to represent zero or more moves of the PDA.

That is:BASIS: I �∗ I for any ID I.

INDUCTION: I �∗ J if there exists some ID K such thatI � K and K �∗ J.

That is, I �∗ J if there is a sequence of ID’s . . . Kn such thatI = K1, J = Kn, and for all i = 1, 2, . . . , n − 1, we haveKi � Ki+1.

Atif Hasan Rahman Pushdown Automata

CSE 211 PDA

Instantaneous Descriptions of a PDA

We also use the symbol �∗P , or �∗ when the PDA P is

understood, to represent zero or more moves of the PDA.

That is:BASIS: I �∗ I for any ID I.

INDUCTION: I �∗ J if there exists some ID K such thatI � K and K �∗ J.

That is, I �∗ J if there is a sequence of ID’s . . . Kn such thatI = K1, J = Kn, and for all i = 1, 2, . . . , n − 1, we haveKi � Ki+1.

Atif Hasan Rahman Pushdown Automata

CSE 211 PDA

Instantaneous Descriptions of a PDA

We also use the symbol �∗P , or �∗ when the PDA P is

understood, to represent zero or more moves of the PDA.

That is:BASIS: I �∗ I for any ID I.

INDUCTION: I �∗ J if there exists some ID K such thatI � K and K �∗ J.

That is, I �∗ J if there is a sequence of ID’s . . . Kn such thatI = K1, J = Kn, and for all i = 1, 2, . . . , n − 1, we haveKi � Ki+1.

Atif Hasan Rahman Pushdown Automata

CSE 211 PDA

Instantaneous Descriptions of a PDA

We also use the symbol �∗P , or �∗ when the PDA P is

understood, to represent zero or more moves of the PDA.

That is:BASIS: I �∗ I for any ID I.

INDUCTION: I �∗ J if there exists some ID K such thatI � K and K �∗ J.

That is, I �∗ J if there is a sequence of ID’s . . . Kn such thatI = K1, J = Kn, and for all i = 1, 2, . . . , n − 1, we haveKi � Ki+1.

Atif Hasan Rahman Pushdown Automata

CSE 211 PDA

Example

Let us consider the action ofthe PDA of previous exampleon the input 1111.

Since q0 is the start state andZ0is the start symbol, theinitial ID is (q0, 1111, Z0).

On this input, the PDA has anopportunity to guess wronglyseveral times.

The entire sequence of ID’sthat the PDA can reach fromthe initial ID (q0, 1111, Z0) isshown.

Arrows represent the �relation.

Atif Hasan Rahman Pushdown Automata

CSE 211 PDA

Example

Let us consider the action ofthe PDA of previous exampleon the input 1111.

Since q0 is the start state andZ0is the start symbol, theinitial ID is (q0, 1111, Z0).

On this input, the PDA has anopportunity to guess wronglyseveral times.

The entire sequence of ID’sthat the PDA can reach fromthe initial ID (q0, 1111, Z0) isshown.

Arrows represent the �relation.

Atif Hasan Rahman Pushdown Automata

P = ({q0, q1, q2}, {0, 1}, {0, 1, Z0}, δ, q0, Z0, {q2}) 1111

δ is defined by the following rules:

1.i) δ(q0, 0, Z0) = {(q0, 0Z0)} andii) δ(q0, 1, Z0) = {(q0, 1Z0)}

From the initial ID, thereare two choices of move.

The first guesses that themiddle has not been seenand leads to ID(q0, 111, 1Z0).

In effect, a 1 has beenremoved from the inputand pushed onto the stack.

P = ({q0, q1, q2}, {0, 1}, {0, 1, Z0}, δ, q0, Z0, {q2}) 1111

δ is defined by the following rules:

3.i) δ(q0, ε , Z0) = {(q1, Z0)},ii) δ(q0, ε , 0) = {(q1, 0)}, andiii) δ(q0, ε , 1) = {(q1, 1)}.

The second choice fromthe initial ID guesses thatthe middle has beenreached.

Without consuming input,the PDA goes to state q1,leading to the ID(q1, 1111, Z0).

P = ({q0, q1, q2}, {0, 1}, {0, 1, Z0}, δ, q0, Z0, {q2}) 1111

δ is defined by the following rules:

5.i) δ(q1, ε , Z0) = {(q2, Z0)}.

Since the PDA may acceptif it is in state q1 and seesZ0on top of its stack, thePDA goes from there to ID(q2, 1111, Z0).

That ID is not exactly anaccepting ID, since theinput has not beencompletely consumed.

P = ({q0, q1, q2}, {0, 1}, {0, 1, Z0}, δ, q0, Z0, {q2}) 1111

δ is defined by the following rules:

5.i) δ(q1, ε , Z0) = {(q2, Z0)}.

Had the input been ε ratherthan 1111, the samesequence of moves wouldhave led to ID (q2, ε , Z0),which would show that ε isaccepted.

P = ({q0, q1, q2}, {0, 1}, {0, 1, Z0}, δ, q0, Z0, {q2}) 1111

δ is defined by the following rules:

3.i) δ(q0, ε , Z0) = {(q1, Z0)},ii) δ(q0, ε , 0) = {(q1, 0)}, andiii) δ(q0, ε , 1) = {(q1, 1)}.

The PDA may also guessthat it has seen the middleafter reading one 1, that is,when it is in the ID(q0, 111, 1Z0).

That guess also leads tofailure, since the entireinput cannot be consumed.

P = ({q0, q1, q2}, {0, 1}, {0, 1, Z0}, δ, q0, Z0, {q2}) 1111

δ is defined by the following rules:

The correct guess, that themiddle is reached afterreading two 1’s, gives us asequence of ID’s.

P = ({q0, q1, q2}, {0, 1}, {0, 1, Z0}, δ, q0, Z0, {q2}) 1111

δ is defined by the following rules:

1.i) δ(q0, 0, Z0) = {(q0, 0Z0)} andii) δ(q0, 1, Z0) = {(q0, 1Z0)}

(q0, 1111, Z0)

� (q0, 111, 1Z0)

� (q0, 11, 11Z0)

� (q1, 11, 11Z0)

� (q1, 1, 1Z0)

� (q1, ε , Z0)

� (q2, ε , Z0)

P = ({q0, q1, q2}, {0, 1}, {0, 1, Z0}, δ, q0, Z0, {q2}) 1111

δ is defined by the following rules:

2.i) δ(q0, 0, 0) = {(q0, 00)},ii) δ(q0, 0, 1) = {(q0, 01)},iii) δ(q0, 1, 0) = {(q0, 10)}, andiv) δ(q0, 1, 1) = {(q0, 11)}.

(q0, 1111, Z0)

� (q0, 111, 1Z0)

� (q0, 11, 11Z0)

� (q1, 11, 11Z0)

� (q1, 1, 1Z0)

� (q1, ε , Z0)

� (q2, ε , Z0)

P = ({q0, q1, q2}, {0, 1}, {0, 1, Z0}, δ, q0, Z0, {q2}) 1111

δ is defined by the following rules:

3.i) δ(q0, ε , Z0) = {(q1, Z0)},ii) δ(q0, ε , 0) = {(q1, 0)}, andiii) δ(q0, ε , 1) = {(q1, 1)}.

(q0, 1111, Z0)

� (q0, 111, 1Z0)

� (q0, 11, 11Z0)

� (q1, 11, 11Z0)

� (q1, 1, 1Z0)

� (q1, ε , Z0)

� (q2, ε , Z0)

P = ({q0, q1, q2}, {0, 1}, {0, 1, Z0}, δ, q0, Z0, {q2}) 1111

δ is defined by the following rules:

4.i) δ(q1, 0, 0) = {(q1, ε )}, andii) δ(q1, 1, 1) = {(q1, ε )}.

(q0, 1111, Z0)

� (q0, 111, 1Z0)

� (q0, 11, 11Z0)

� (q1, 11, 11Z0)

� (q1, 1, 1Z0)

� (q1, ε , Z0)

� (q2, ε , Z0)

P = ({q0, q1, q2}, {0, 1}, {0, 1, Z0}, δ, q0, Z0, {q2}) 1111

δ is defined by the following rules:

5.i) δ(q1, ε , Z0) = {(q2, Z0)}.

(q0, 1111, Z0)

� (q0, 111, 1Z0)

� (q0, 11, 11Z0)

� (q1, 11, 11Z0)

� (q1, 1, 1Z0)

� (q1, ε , Z0)

� (q2, ε , Z0)

Instantaneous Descriptions of a PDAThere are three important principles about ID’s and theirtransitions that we shall need in order to reason about PDA’s:

1. If a sequence of ID’s (computation) is legal for a PDA P,then the computation formed by adding the same additionalinput string to the end of the input (second component) ineach ID is also legal.

2. If a computation is legal for a PDA P, then the computationformed by adding the same additional stack symbols belowthe stack in each ID is also legal.

3. If a computation is legal for a PDA P, and some tail of theinput is not consumed, then we can remove this tail from theinput in each ID, and the resulting computation will still belegal.

Intuitively, data that P never looks at cannot affect itscomputation.

We formalize points (1) and (2) in a single theorem.

Instantaneous Descriptions of a PDAThere are three important principles about ID’s and theirtransitions that we shall need in order to reason about PDA’s:

1. If a sequence of ID’s (computation) is legal for a PDA P,then the computation formed by adding the same additionalinput string to the end of the input (second component) ineach ID is also legal.

2. If a computation is legal for a PDA P, then the computationformed by adding the same additional stack symbols belowthe stack in each ID is also legal.

3. If a computation is legal for a PDA P, and some tail of theinput is not consumed, then we can remove this tail from theinput in each ID, and the resulting computation will still belegal.

Intuitively, data that P never looks at cannot affect itscomputation.

We formalize points (1) and (2) in a single theorem.

Instantaneous Descriptions of a PDAThere are three important principles about ID’s and theirtransitions that we shall need in order to reason about PDA’s:

1. If a sequence of ID’s (computation) is legal for a PDA P,then the computation formed by adding the same additionalinput string to the end of the input (second component) ineach ID is also legal.

2. If a computation is legal for a PDA P, then the computationformed by adding the same additional stack symbols belowthe stack in each ID is also legal.

3. If a computation is legal for a PDA P, and some tail of theinput is not consumed, then we can remove this tail from theinput in each ID, and the resulting computation will still belegal.

Intuitively, data that P never looks at cannot affect itscomputation.

We formalize points (1) and (2) in a single theorem.

Instantaneous Descriptions of a PDAThere are three important principles about ID’s and theirtransitions that we shall need in order to reason about PDA’s:

1. If a sequence of ID’s (computation) is legal for a PDA P,then the computation formed by adding the same additionalinput string to the end of the input (second component) ineach ID is also legal.

2. If a computation is legal for a PDA P, then the computationformed by adding the same additional stack symbols belowthe stack in each ID is also legal.

3. If a computation is legal for a PDA P, and some tail of theinput is not consumed, then we can remove this tail from theinput in each ID, and the resulting computation will still belegal.

Intuitively, data that P never looks at cannot affect itscomputation.

We formalize points (1) and (2) in a single theorem.

CSE 211 PDA

Instantaneous Descriptions of a PDA

1. If a sequence of ID’s (computation) is legal for a PDA P, then the computationformed by adding the same additional input string to the end of the input (secondcomponent) in each ID is also legal.

2. If a computation is legal for a PDA P, then the computation formed by adding thesame additional stack symbols below the stack in each ID is also legal.

Theorem

If P = (Q, Σ, Γ, δ, q0, Z0, F )is a PDA, and (q, x , α ) �∗P (p, y , β),

then for any strings w in Σ∗ and γ in Γ∗, it is also true that(q, xw , α γ) �∗

P (p, yw , βγ)

Note that if γ = ε , then we have a formal statement ofprinciple (1) above, and if w = ε , then we have the second

Atif Hasan Rahman Pushdown Automata

Instantaneous Descriptions of a PDA

Theorem

If P = (Q, Σ, Γ, δ, q0, Z0, F )is a PDA, and (q, x , α ) �∗P (p, y , β),

then for any strings w in Σ∗ and γ in Γ∗, it is also true that

(q, xw , α γ) �∗P (p, yw , βγ)

PROOF: The proof is actually a very simple induction on thenumber of steps in the sequence of ID’s that take(q, xw , α γ) to (p, yw , βγ).

Each of the moves in the sequence (q, x , α ) �∗P (p, y , β) is

justified by the transitions of P without using w and/or γ inany way.

Therefore, each move is still justified when these stringsare sitting on the input and stack.

Instantaneous Descriptions of a PDA

Theorem

If P = (Q, Σ, Γ, δ, q0, Z0, F )is a PDA, and (q, x , α ) �∗P (p, y , β),

then for any strings w in Σ∗ and γ in Γ∗, it is also true that

(q, xw , α γ) �∗P (p, yw , βγ)

PROOF: The proof is actually a very simple induction on thenumber of steps in the sequence of ID’s that take(q, xw , α γ) to (p, yw , βγ).

Each of the moves in the sequence (q, x , α ) �∗P (p, y , β) is

justified by the transitions of P without using w and/or γ inany way.

Therefore, each move is still justified when these stringsare sitting on the input and stack.

Instantaneous Descriptions of a PDA

Theorem

If P = (Q, Σ, Γ, δ, q0, Z0, F )is a PDA, and (q, x , α ) �∗P (p, y , β),

then for any strings w in Σ∗ and γ in Γ∗, it is also true that

(q, xw , α γ) �∗P (p, yw , βγ)

PROOF: The proof is actually a very simple induction on thenumber of steps in the sequence of ID’s that take(q, xw , α γ) to (p, yw , βγ).

Each of the moves in the sequence (q, x , α ) �∗P (p, y , β) is

justified by the transitions of P without using w and/or γ inany way.

Therefore, each move is still justified when these stringsare sitting on the input and stack.

Instantaneous Descriptions of a PDA

Theorem: If P = (Q, Σ, Γ, δ, q0, Z0, F )is a PDA, and(q, x , α ) �∗

P (p, y , β), then for any strings w in Σ∗

and γ in Γ∗, it is also true that

(q, xw , α γ) �∗P (p, yw , βγ)

Incidentally, note that the converse of this theorem is false.That is, the following is false:

If P = (Q, Σ, Γ, δ, q0, Z0, F )is a PDA and for any strings w inΣ∗ and γ in Γ∗, (q, xw , α γ) �∗

P (p, yw , βγ), the it is also truethat (q, xw , α ) �∗

P (p, yw , β) (FALSE).

Instantaneous Descriptions of a PDA

Theorem: If P = (Q, Σ, Γ, δ, q0, Z0, F )is a PDA, and(q, x , α ) �∗

P (p, y , β), then for any strings w in Σ∗

and γ in Γ∗, it is also true that

(q, xw , α γ) �∗P (p, yw , βγ)

Incidentally, note that the converse of this theorem is false.That is, the following is false:

If P = (Q, Σ, Γ, δ, q0, Z0, F )is a PDA and for any strings w inΣ∗ and γ in Γ∗, (q, xw , α γ) �∗

P (p, yw , βγ), the it is also truethat (q, xw , α ) �∗

P (p, yw , β) (FALSE).

Instantaneous Descriptions of a PDA

If P = (Q, Σ, Γ, δ, q0, Z0, F )is a PDA and for any strings w inΣ∗ and γ in Γ∗, (q, xw , α γ) �∗

P (p, yw , βγ), the it is alsotrue that (q, xw , α ) �∗

P (p, yw , β) (FALSE).There are things that a PDA might be able to do

by popping its stack,using some symbols of γ, andthen replacing them on the stack,

that it couldn’t do if it never looked at γ.

⎧⎪⎪⎪⎪⎨⎪⎪⎪⎪⎩

01111{

.γ01Z0 . . . . . .

1Z0 . . . . . .

⎧⎪⎪⎨⎪⎪⎩.β

1100{

.γ01Z0

CSE 211 PDA

Instantaneous Descriptions of a PDA

3. If a computation is legal for a PDA P, and some tail of the input is not consumed,then we can remove this tail from the input in each ID, and the resultingcomputation will still be legal.

However, as principle (3) states, we can remove unusedinput, since it is not possible for a PDA to consume inputsymbols and then restore those symbols to the input.

Atif Hasan Rahman Pushdown Automata

CSE 211 PDA

Instantaneous Descriptions of a PDA

3. If a computation is legal for a PDA P, and some tail of the input is not consumed,then we can remove this tail from the input in each ID, and the resultingcomputation will still be legal.

We state principle (3) formally as:

Theorem

If P = (Q, Σ, Γ, δ, q0, Z0, F )is a PDA, and

(q, xw , α ) �∗P (p, yw , β)

then it is also true that (q, x , α ) �∗P (p, y , β).

Atif Hasan Rahman Pushdown Automata

ID’s for Finite Automata?

One might wonder why we did not introduce for finiteautomata a notation like the ID’s we use for PDA’s.

Although a FA has no stack, we could use a pair (q, w),where q is the state and w the remaining input, as the IDof a finite automaton.

While we could have done so, we would not glean anymore information from reachability among ID’s than weobtain from the δ̂ notation.

That is, for any finite automaton, we could show thatδ̂(q, w) = p if and only if (q, wx) � (p, x) for all strings x .

The fact that x can be anything we wish without influencingthe behavior of the FA is a theorem analogous to theprevious theorems.

ID’s for Finite Automata?

One might wonder why we did not introduce for finiteautomata a notation like the ID’s we use for PDA’s.

Although a FA has no stack, we could use a pair (q, w),where q is the state and w the remaining input, as the IDof a finite automaton.

While we could have done so, we would not glean anymore information from reachability among ID’s than weobtain from the δ̂ notation.

That is, for any finite automaton, we could show thatδ̂(q, w) = p if and only if (q, wx) � (p, x) for all strings x .

The fact that x can be anything we wish without influencingthe behavior of the FA is a theorem analogous to theprevious theorems.

CSE 211 PDA

Language of a PDA

The language accepted by P, denoted L(P), is the set ofall strings accepted by P.Two approaches

1 acceptance by final state2 acceptance by empty stack

Two methods are equivalent.

A language L has a PDA that accepts it by final state if andonly if L has a PDA that accepts it by empty stack.

Atif Hasan Rahman Pushdown Automata

CSE 211 PDA

Language of a PDA

The language accepted by P, denoted L(P), is the set ofall strings accepted by P.Two approaches

1 acceptance by final state2 acceptance by empty stack

Two methods are equivalent.

A language L has a PDA that accepts it by final state if andonly if L has a PDA that accepts it by empty stack.

Atif Hasan Rahman Pushdown Automata

CSE 211 PDA

Acceptance by Final State and Empty Stack

Let P = (Q, Σ, Γ, δ, q0, Z0, F )be a PDA

L(P), the language accepted by P by final state, is

{w |(q0, w , Z0) �∗P (q, ε , α )}

for some state q ∈ F and any stack string α.

N(P), the language accepted by P by empty stack, is

{w |(q0, w , Z0) �∗P (q, ε , ε )}

for any state q. Since the set of accepting states isirrelevant we can omit F .

Atif Hasan Rahman Pushdown Automata

CSE 211 PDA

From Empty Stack to Final State

If L = N(PN) for some PDA PN = (Q, Σ, Γ, δ, q0, Z0, F ),then there is a PDA PF such that L = L(PF ).

We use a new symbol X0 /∈ Γ

X0 is the start symbol and a marker on the bottom of thestack.

We also need a new start state p0 whose sole function is topush Z0 and enter state q0.

We need another state, pf , which is accepting state of PF

Whenever PF sees X0 on the top of the stack, it transfersto pf

Atif Hasan Rahman Pushdown Automata

CSE 211 PDA

From Empty Stack to Final State

Atif Hasan Rahman Pushdown Automata

CSE 211 PDA

From Final State to Empty Stack

If L = L(PF ) for some PDA PF = (Q, Σ, Γ, δ, q0, Z0, F ), thenthere is a PDA PN such that L = N(PN).

From each accepting state of PF , add a transition on ε to anew state p.

When in state p, PN pops its stack and does not consumeany input.

To avoid a situation where PF accidentally epmties its, PN

must use a marker X0 on the bottom of the stack.

We also need a new start state p0 whose sole function is topush start symbol of PF and enter start state of PF .

Atif Hasan Rahman Pushdown Automata

CSE 211 PDA

From Final State to Empty Stack

Atif Hasan Rahman Pushdown Automata

CSE 211 PDA

Example

Design a PDA which accepts a string of balancedparenthesis.

The string must always start with a left parenthesis.

So the PDA accepts all of the following:

(()(())(())) ()()() ε

But it does not accept any of the following:

()) )()(

Atif Hasan Rahman Pushdown Automata

CSE 211 PDA

Example-continued

The principle involved here should be very simple.

Whenever we see a left parenthesis, we push it onto thestack.

Every left parenthesis can be paired with a uniquesubsequent right parenthesis.

Whenever we see a right parenthesis, we try to match itwith one in the stack.

Atif Hasan Rahman Pushdown Automata

CSE 211 PDA

Example-continued

The states involved are,

q0: We are about to start scanning or we are inthe middle of the string.

q1: We have finished scanning the whole string.

While in q1, if the stack is empty, the string is accepted.

Atif Hasan Rahman Pushdown Automata

CSE 211 PDA

Example-continued

So, the PDA is as follows:

P = ({q0, q1}, {(, )}, {(, ), Z0}, δ, q0, Z0, q1)

The δ are as follows:For the initial condition (or when the parentheses sofar has been perfectly matched),δ(q0, (, Z0) = {(q0, (Z0)}.For storing the left parentheses, δ(q0, (, () = {(q0, (()}.For left-right matches, δ(q0, ), () = {(q0, ε )}.For acceptance, δ(q0, ε , Z0) = {(q1, Z0)}.

Atif Hasan Rahman Pushdown Automata

δ(q0, (, Z0) = {(q0, (Z0)},δ(q0, (, () = {(q0, (()},δ(q0, ), () = {(q0, ε )},δ(q0, ε , Z0) = {(q1, Z0)}.

(q0, (()(())(())), Z0) � (q0, ()(())(())), (Z0)

� (q0, )(())(())), ((Z0)

� (q0, (())(())), (Z0)

� (q0, ())(())), ((Z0)

� (q0, ))(())), (((Z0)

� (q0, )(())), ((Z0)

� (q0, (())), (Z0)

� (q0, ())), ((Z0)

� (q0, ))), (((Z0)

� (q0, )), ((Z0)

� (q0, ), (Z0)

� (q0, ε , Z0)

� (q1, ε , Z0)

δ(q0, (, Z0) = {(q0, (Z0)},δ(q0, (, () = {(q0, (()},δ(q0, ), () = {(q0, ε )},δ(q0, ε , Z0) = {(q1, Z0)}.

(q0, ()()(), Z0) � (q0, )()(), (Z0)

� (q0, ()(), Z0)

� (q0, )(), (Z0)

� (q0, (), Z0)

� (q0, ), (Z0)

� (q0, ε , Z0)

� (q1, ε , Z0)

δ(q0, (, Z0) = {(q0, (Z0)},δ(q0, (, () = {(q0, (()},δ(q0, ), () = {(q0, ε )},δ(q0, ε , Z0) = {(q1, Z0)}.

(q0, ε , Z0) � (q1, ε , Z0)

δ(q0, (, Z0) = {(q0, (Z0)},δ(q0, (, () = {(q0, (()},δ(q0, ), () = {(q0, ε )},δ(q0, ε , Z0) = {(q1, Z0)}.

(q0, ()), Z0) � (q0, )), (Z0)

� (q0, ), Z0)

????

δ(q0, (, Z0) = {(q0, (Z0)},δ(q0, (, () = {(q0, (()},δ(q0, ), () = {(q0, ε )},δ(q0, ε , Z0) = {(q1, Z0)}.

(q0, )()()(, Z0) � ????

CSE 211 PDA

Example

This pushdown automaton accepts the language{w ∈ {a, b}∗ : w has the same number of a’s and b’s}.Either a string of a’s or a string of b’s is kept by P on itsstack.

A stack of a’s indicates the excess of a’s over b’s thus farread.

If in fact P has read more a’s than b’s; a stack of b’sindicates the excess of b’s over a’s.

In either case, P keeps a special symbol c (as Z0) on thebottom of the stack as a marker.

Atif Hasan Rahman Pushdown Automata

CSE 211 PDA

Example-continued

Let P = (Q, Σ, Γ, δ, q0, Z0, F ) whereQ = {s, q, f},ε = {a, b},Γ = {a, b, c},Z0 = c,F = f ,δ is listed below,(1) δ(s, ε , c) = (q, c),(2) δ(q, a, c) = (q, ac),(3) δ(q, a, a) = (q, aa),(4) δ(q, a, b) = (q, ε ),(5) δ(q, b, c) = (q, bc),(6) δ(q, b, b) = (q, bb),(7) δ(q, b, a) = (q, ε ),(8) δ(q, ε , c) = (f , c).

Atif Hasan Rahman Pushdown Automata

CSE 211 PDA

Example-continued

(1) δ(s, ε , c) = (q, c),(2) δ(q, a, c) = (q, ac),(3) δ(q, a, a) = (q, aa),(4) δ(q, a, b) = (q, ε ),(5) δ(q, b, c) = (q, bc),(6) δ(q, b, b) = (q, bb),(7) δ(q, b, a) = (q, ε ),(8) δ(q, ε , c) = (f , c).

Transition 1 puts P in state q while keeping c on thebottom of the stack unchanged.

Atif Hasan Rahman Pushdown Automata

CSE 211 PDA

Example-continued

(1) δ(s, ε , c) = (q, c),(2) δ(q, a, c) = (q, ac),(3) δ(q, a, a) = (q, aa),(4) δ(q, a, b) = (q, ε ),(5) δ(q, b, c) = (q, bc),(6) δ(q, b, b) = (q, bb),(7) δ(q, b, a) = (q, ε ),(8) δ(q, ε , c) = (f , c).

In state q, when P reads an a,it either starts up a stack of a’s from the bottom, whilekeeping the bottom marker (transition 2),or pushes an a onto a stack of a’s (transition 3),or pops a b from a stack of b’s (transition 4).

Atif Hasan Rahman Pushdown Automata

CSE 211 PDA

Example-continued

(1) δ(s, ε , c) = (q, c),(2) δ(q, a, c) = (q, ac),(3) δ(q, a, a) = (q, aa),(4) δ(q, a, b) = (q, ε ),(5) δ(q, b, c) = (q, bc),(6) δ(q, b, b) = (q, bb),(7) δ(q, b, a) = (q, ε ),(8) δ(q, ε , c) = (f , c).

When reading a b from the input, the machine actsanalogously,

pushing a b onto a stack of b’s (transition 5),or pushing a b onto a stack consisting of just a bottommarker (transition 6),and popping an a from a stack of a’s (transition 7).

Atif Hasan Rahman Pushdown Automata

CSE 211 PDA

Example-continued

(1) δ(s, ε , c) = (q, c),(2) δ(q, a, c) = (q, ac),(3) δ(q, a, a) = (q, aa),(4) δ(q, a, b) = (q, ε ),(5) δ(q, b, c) = (q, bc),(6) δ(q, b, b) = (q, bb),(7) δ(q, b, a) = (q, ε ),(8) δ(q, ε , c) = (f , c).

Finally, when c is the topmost (and therefore the only)symbol on the stack, the machine may pass to a final state(transition 8).

If at this point all the input has been read, then theconfiguration (f , ε , c) has been reached, and the inputstring is accepted.

Atif Hasan Rahman Pushdown Automata

(1) δ(s, ε , c) = (q, c),(2) δ(q, a, c) = (q, ac),(3) δ(q, a, a) = (q, aa),(4) δ(q, a, b) = (q, ε ),

(5) δ(q, b, c) = (q, bc),(6) δ(q, b, b) = (q, bb),(7) δ(q, b, a) = (q, ε ),(8) δ(q, ε , c) = (f , c).

The following table contains an illustration of the operation of Pfor an input abbbabaa.

CSE 211 PDA

Equivalence of PDA’s and CFG’s

Following three classes of languages are equivalentThe context free languages, i.e. the languages defined byCFG’s.The languages that are accepted by final state by somePDA.The languages that are accepted by empty stack by somePDA.

Atif Hasan Rahman Pushdown Automata

CSE 211 PDA

Deterministic PDA

A PDA P = (Q, Σ, Γ, δ, q0, Z0, F ) is said to be deterministiciff the following conditions are met:

δ (q, a, X ) has at most one member for any q ∈ Q, a ∈ Σ ora = ε and X ∈ Γ.IF δ (q, a, X ) is nonempty for some a ∈ Σ, the δ (q, ε , X )must be empty.

The language accepted by DPDA’s by empty stack islimited. It has the prefix property

The language accepted by DPDA’s by final state properlyinclude the regular languages, but are properly included inthe CFL’s.

The language DPDA’s accept all have unambiguousgrammars.

Atif Hasan Rahman Pushdown Automata

CSE 211 PDA

Deterministic PDA

A PDA P = (Q, Σ, Γ, δ, q0, Z0, F ) is said to be deterministiciff the following conditions are met:

δ (q, a, X ) has at most one member for any q ∈ Q, a ∈ Σ ora = ε and X ∈ Γ.IF δ (q, a, X ) is nonempty for some a ∈ Σ, the δ (q, ε , X )must be empty.

The language accepted by DPDA’s by empty stack islimited. It has the prefix property

The language accepted by DPDA’s by final state properlyinclude the regular languages, but are properly included inthe CFL’s.

The language DPDA’s accept all have unambiguousgrammars.

Atif Hasan Rahman Pushdown Automata

CSE 211 PDA

Thank you

Atif Hasan Rahman Pushdown Automata