Download as pdf or txt
Download as pdf or txt
You are on page 1of 50

Push Down Automata

UNIT 4

TAFL

Course Details
(B Tech 4th Sem)

Mr. Nagesh Sharma KCS - 402 TAFL Unit Number: 4


1
6/20/2023
Content

• Introduction
• Push Down Automata
• Example of PDA
• Formal Definition of PDA
• Operation of PDA
• Instantons Description of PDA
• PDA Examples
• Construction of PDA from CFG
• Non Deterministic PDA

Mr. Nagesh Sharma KCS - 402 TAFL


6/20/2023 2
Unit Number: 4
Course Objective

• Introduce concepts in automata theory and theory of computation

• Identify different formal language classes and their relationships

• Design grammars and recognizers for different formal languages

• Prove or disprove theorems in automata theory using its properties

• Determine the decidability and intractability of computational


problems

Mr. Nagesh Sharma KCS - 402 TAFL


6/20/2023 3
Unit Number: 4
Unit Objective

• To understand the designing of Push Down Automata.


• To understand the Non Deterministic Push Down Automata.
• To understand the relationship between PDA and Regular Grammar.

Mr. Nagesh Sharma KCS - 402 TAFL Unit Number: 4


6/20/2023 4
Prerequisite and Recap

Prerequisite:

• Brief review of basic operations on stack & Augmenting stack

Recap:

• Grammar are also called generators.


• There are various types of grammar like type 0, type 1, type 2 etc.
• Grammar can be ambiguous also.
• It can be represented by parse trees also.
• There are different Normal forms of grammar like CNF and GNF.

Mr. Nagesh Sharma KCS - 402 TAFL Unit Number: 4


6/20/2023 5
Unit 4 Syllabus

Push Down Automata and Properties of Context Free Languages:


Nondeterministic Pushdown Automata (NPDA)- Definition, Moves, A
Language Accepted by NPDA, Deterministic Pushdown
Automata(DPDA) and Deterministic Context free Languages(DCFL),
Pushdown Automata for Context Free Languages, Context Free
grammars for Pushdown Automata, Two stack Pushdown Automata,
Pumping Lemma for CFL, Closure properties of CFL, Decision Problems
of CFL, Programming problems based on the properties of CFLs.

Mr. Nagesh Sharma KCS - 402 TAFL Unit Number: 4


6/20/2023 6
Introduction (CO1, CO3, and CO4)

Recap: Till now we have studied about FA and its types, Regular
Expressions and Grammar.

Prerequisite: Brief review of basic operations on stack & Augmenting


stack

Objective: To understand the definition of Push Down Automata.

Mr. Nagesh Sharma KCS - 402 TAFL Unit Number: 4


6/20/2023 7
Introduction (CO1, CO3, and CO4)

Objective: To understand the definition of Push Down Automata.

• Informally pushdown automata can be viewed as finite automata


with stack.
• An added stack provides memory and increases the capability of
the machines.
• A Pushdown automata can do the following things:
– Read input symbols
– Perform Stack Operations:
• Push
• Pop
• Nop
– Make State Change

Mr. Nagesh Sharma KCS - 402 TAFL Unit Number: 4


6/20/2023 8
Push Down Automata(CO1, CO3, and CO4)

• PDA is more powerful than FA

• A Context Free Language (CFL) can be recognized by a PDA. Only a


subset of a CFL that are regular can be recognized by finite
automata.

• For every context free language there exists a PDA

• The language of a PDA is a context free language.

Mr. Nagesh Sharma KCS - 402 TAFL Unit Number: 4


6/20/2023 9
Example of PDA(CO1, CO3, and CO4)

Mr. Nagesh Sharma KCS - 402 TAFL Unit Number: 4


6/20/2023 10
Example of PDA (CO1, CO3, and CO4)

Mr. Nagesh Sharma KCS - 402 TAFL Unit Number: 4


6/20/2023 11
Example of PDA (Continued)

• The machine will have two states q0 and q1.


• State q0 is for reading number of a’s.
• State q1 is for reading number of b’s.

• A transition in a PDA depends on:


– Current State
– Current input
– Top symbol of the stack

Mr. Nagesh Sharma KCS - 402 TAFL Unit Number: 4


6/20/2023 12
PDA (CO1, CO3, and CO4)

A PDA uses three stack operations:

• POP Operation: it remove top symbol of the stack.


• PUSH Operation: it inserts a symbol onto the stack.
• NOP Operation, it does nothing to the stack.

Mr. Nagesh Sharma KCS - 402 TAFL Unit Number: 4


6/20/2023 13
The Formal Definition of PDA(CO1,
PDA CO3, and
CO4)

Recap: Till now we have studied about basic concept of Push


Down Automata.

Prerequisite: Brief review of basic operations on stack &


Augmenting stack

Objective: To understand the Formal Definition of PDA

Mr. Nagesh Sharma KCS - 402 TAFL Unit Number: 4


6/20/2023 14
The Formal Definition of PDA(CO1,
PDA CO3, and
CO4)
Objective: To understand the Formal Definition of PDA

• A Pushdown automata M is defined as 7 tuple:

Mr. Nagesh Sharma KCS - 402 TAFL Unit Number: 4


6/20/2023 15
Operations of PDA Representation(CO1,
CO3, and CO4)
Read Input with no operation on Stack

Left hand side of the transition implies:


• q1 is the current state,
• a is the current input,
• b is the stack symbol (topmost)

Right hand side of the transition implies:


• Machine enters in state q2 and symbol b is replaced by b. (No
modification)
Mr. Nagesh Sharma KCS - 402 TAFL Unit Number: 4
6/20/2023 16
Operations of PDA Representation(Continued)

POP Operation:

The above transition will erase the stack symbol


(topmost). Replacing b with ɛ manse removing b from top of the
stack.

Mr. Nagesh Sharma KCS - 402 TAFL Unit Number: 4


6/20/2023 17
Operations of PDA Representation(Continued)

PUSH Operation:

• The above transition will perform PUSH operation. It will push


a onto the stack. Replacing b with ab means PUSH a onto the
stack.

Mr. Nagesh Sharma KCS - 402 TAFL Unit Number: 4


6/20/2023 18
Operations of PDA Graphical
Representation(CO1, CO3, and CO4)

Mr. Nagesh Sharma KCS - 402 TAFL Unit Number: 4


6/20/2023 19
Instantaneous Description of a PDA (CO1,
CO3, and CO4)
• For a FA, the only thing of interest about the FA is its state.

• For a PDA, we want to know its state and the entire content of its
stack.
– Often the stack is one of the most useful pieces of
information, since it is not bounded in size.

• We can represent the instantaneous description (ID) of a PDA by


the following triple (q,w,γ):
– q is the state
– w is the remaining input
– γ is the stack contents

• By convention the top of the stack is shown at the left end of γ


and the bottom at the right end.

Mr. Nagesh Sharma KCS - 402 TAFL Unit Number: 4


6/20/2023 20
Instantaneous Description of a PDA

• Write down the IDs or moves for input string w = “aabb” of PDA
as M = ({q0, q1, q2}, {a, b}, {a, b, Z0}, δ, q0, Z0, {q2}), where δ is
defined by following rules:

• δ(q0, a, Z0) = {(q0, aZ0)} Rule (1)


δ(q0, a, a) = {(q0, aa)} Rule (2)
δ(q0, b, a) = {(q1, λ)} Rule (3)
δ(q1, b, a) = {(q1, λ)} Rule (4)
δ(q1, λ, Z0) = {(q2, λ)} Rule (5)
δ(q0, λ, Z0) = {(q2, λ)} Rule (6)

• Also check string w is accepted by PDA or not?

Mr. Nagesh Sharma KCS - 402 TAFL Unit Number: 4


6/20/2023 21
Instantaneous Description of a PDA

• Solution: Instantaneous Description for string w = “aabb”

• (q0, aabb, Z0) |- (q0, abb, aZ0) as per Rule (1)


|- (q0, bb, aaZ0) as per Rule (2)
|- (q1, b, aZ0) as per Rule (3)
|- (q1, λ, Z0) as per Rule (3)
|- (q2, λ, λ) as per Rule (5)

• Finally PDA reached a configuration of (q2, λ, λ) i.e. the input tape


is empty or input string w is completed, PDA stack is empty and
PDA has reached a final state. So the string ‘w’ is accepted.

Mr. Nagesh Sharma KCS - 402 TAFL Unit Number: 4


6/20/2023 22
The Language of a PDA(CO1,
PDA CO3, and CO4)

Recap: Till now we have studied about basic concept and definition of
Push Down Automata.

Prerequisite: Brief review of basic operations on stack & Augmenting


stack

Objective: To understand the language accepted by PDA.

Mr. Nagesh Sharma KCS - 402 TAFL Unit Number: 4


6/20/2023 23
The Language of a PDA(CO1,
PDA CO3, and CO4)

Objective: To understand the language accepted by PDA.

A language of a PDA can be accepted by two ways:

• Through final State


• Through empty stack

It is also possible to convert between the two states:


• From Final State to empty stack
• From empty stack to final state

Mr. Nagesh Sharma KCS - 402 TAFL Unit Number: 4


6/20/2023 24
Acceptance by Empty Stack

• Let the PDA , M = (Q, Σ, Γ, δ, q0, z0, Φ) then the language


accepted by an empty stack is given by:

Where q1 is any state belonging to Q and the stack becomes


empty on application of input string w.

Mr. Nagesh Sharma KCS - 402 TAFL Unit Number: 4


6/20/2023 25
Acceptance by Final State

• Let the PDA , M = (Q, Σ, Γ, δ, q0, z0, Φ) then the language


accepted by M through a final state is given by:

• Where state q1 ϵ F, α, the final contents of the stack are


irrelevant as a string is accepted through a final state.

Mr. Nagesh Sharma KCS - 402 TAFL Unit Number: 4


6/20/2023 26
PDA Examples with Solutions(CO1, CO3, and
CO4)

Mr. Nagesh Sharma KCS - 402 TAFL Unit Number: 4


6/20/2023 27
PDA Examples with Solutions

Additional m-n a’s should be popped from the stack.


δ(q1, ɛ, a) = (q1, ɛ)

Finally the symbol z0 should be popped out to make the state


empty.
δ(q1, ɛ, z0) = (q1, ɛ)

Mr. Nagesh Sharma KCS - 402 TAFL Unit Number: 4


6/20/2023 28
PDA Examples with Solutions

Q: Design a PDA for accepting the set of all strings over an


alphabet {a,b} with an equal number of a’s and b’s.

Solution:
Stack will be used to store excess of a’s over b’s or excess of b’s
over a’s out of input seen so far.

Mr. Nagesh Sharma KCS - 402 TAFL Unit Number: 4


6/20/2023 29
PDA Examples with Solutions

1. Stack contains z0 (topmost symbols) and the input is a:


δ(q0, a, z0) = (qo, az0)
2. Stack contains z0 and the input is b:
δ(q0, b, z0) = (qo, bz0)
3. Stack contains a and the input is a.
δ(q0, a, a) = (qo, aa)
4. Stack contains a and the input is b
δ(q0, a, b) = (qo, ɛ )
5. Stack contains b and the input is a
δ(q0, b, a) = (qo, ɛ )
6. Stack contains b and the input is b
δ(q0, b, b) = (qo, bb )

Mr. Nagesh Sharma KCS - 402 TAFL Unit Number: 4


6/20/2023 30
PDA Examples with Solutions

Transition Diagram

Mr. Nagesh Sharma KCS - 402 TAFL Unit Number: 4


6/20/2023 31
PDA Examples with Solutions

Q: Design a PDA to check whether a given string over {a, b}


ends in abb.

Solution:
Step 1: Design a DFA of given language:

Mr. Nagesh Sharma KCS - 402 TAFL Unit Number: 4


6/20/2023 32
PDA Examples with Solutions

• Step 2: Convert from DFA to PDA :

Mr. Nagesh Sharma KCS - 402 TAFL Unit Number: 4


6/20/2023 33
Construction of PDA from

Objective: To understand the relationship between PDA and CFG.

From a given CFG G = (V, T, P, S) a PDA can be constructed, M that


simulates the leftmost derivation of G.

The PDA accepting L(G) by empty stack is given by:


M = ({q, T, V U T, δ, q, S, Φ)
Where δ is defined as:
For each variable A ϵ V include a transition,
• δ(q,ɛ,A) = {(q,α)| A→ α is a production in G}
For each terminal a ϵ T, include a transition:
• δ(q,a,a) = {(q, ɛ)}

Mr. Nagesh Sharma KCS - 402 TAFL Unit Number: 4


6/20/2023 34
Construction of PDA from CFG

Recap: Till now we have studied about basic concept and definition of
Push Down Automata with examples.

Prerequisite: Brief review of basic operations on stack & Augmenting


stack and CFG.

Objective: To understand the relationship between PDA and CFG.

Mr. Nagesh Sharma KCS - 402 TAFL Unit Number: 4


6/20/2023 35
Construction of PDA from CFG: Example

Q: Find a PDA for the given grammar:


S → 0S1|00|11

Solution:
The equivalent PDA, M is given by:
M = ({q},{0,1}, {0,1,S}, δ, q, S, Φ), where δ is given by:

δ(q, ɛ, S) = {(q,0S1), (q,00), (q,11)}


δ(q, 0, 0) = {(q, ɛ)}
δ(q, 1, 1) = {(q, ɛ)}

For CFG to PDA follow the following link:


https://www.youtube.com/watch?v=J_6JJH34XyQ

Mr. Nagesh Sharma KCS - 402 TAFL Unit Number: 4


6/20/2023 36
Non-deterministic Pushdown Automata

Recap: Till now we have studied about basic concept and definition of
Push Down Automata with examples and relationship between CFG and
PDA.

Prerequisite: Brief review of basic operations on stack & Augmenting


stack and CFG.

Objective: To understand the designing of Non Deterministic PDA.

Mr. Nagesh Sharma KCS - 402 TAFL Unit Number: 4


6/20/2023 37
Non-deterministic Pushdown Automata
(CO1, CO3, and CO4)
Objective: To understand the designing of Non Deterministic PDA.

• The non-deterministic pushdown automata is very much


similar to NFA.

• The CFG which accepts deterministic PDA accepts non-


deterministic PDAs as well. Similarly, there are some CFGs
which can be accepted only by NPDA and not by DPDA. Thus
NPDA is more powerful than DPDA.

Mr. Nagesh Sharma KCS - 402 TAFL Unit Number: 4


6/20/2023 38
Non-deterministic Pushdown Automata
Non

• Design PDA for Palindrome strips.

Mr. Nagesh Sharma KCS - 402 TAFL Unit Number: 4


6/20/2023 39
Non-deterministic Pushdown Automata
Non

Simulation of abaaba
• δ(q1, abaaba, Z) Apply rule 1
• ⊢ δ(q1, baaba, aZ) Apply rule 5
• ⊢ δ(q1, aaba, baZ) Apply rule 4
• ⊢ δ(q1, aba, abaZ) Apply rule 7
• ⊢ δ(q2, ba, baZ) Apply rule 8
• ⊢ δ(q2, a, aZ) Apply rule 7
• ⊢ δ(q2, ε, Z) Apply rule 11
• ⊢ δ(q2, ε) Accept

Mr. Nagesh Sharma KCS - 402 TAFL Unit Number: 4


6/20/2023 40
Daily Quiz

1. Design PDA for Language WcW R , W  (a, b) *


2. Enlist the difference between PDA and FA
3. Construct a PDA for the grammar
S→aAbB
A→aA
B→bB|b
4. Construct an unrestricted PDA equivalent of the grammar given
below
S→aAA
A→aS|bS|a
5. Construct the PDA for the language L= {ambn|n<m}

6/20/2023 Mr. Nagesh Sharma KCS - 402 TAFL Unit Number: 4 41


Daily Quiz (Continued)

6. Explain Two Stack PDA


7. Enlist the difference between PDA and FA.
8. Construct the PDA for the language L= {ambn|n<m}.
9. Design a PDA for accepting the set of all strings over {a,b} with
equal number od a’s and b’s.
10. Let L={anbncmdm|n,m>=1} find PDA that accept L.
11. Design a PDA to check whether a given string over {a,b} ends
with aba.
12. Construct a PDA to accept language {(ab)n|n>=1} by empty
stack.

6/20/2023 Mr. Nagesh Sharma KCS - 402 TAFL Unit Number: 4 42


MCQ s

1. Top down PDA first move the ……. into the stack

a. start symbol
b. input symbol
c. first symbol
d. last production

2. The type of moves which are related to bottom up PDA are:

a. Shift
b. Reduce
c. Both A ad B
d. Neither A and B

6/20/2023 Mr. Nagesh Sharma KCS - 402 TAFL Unit Number: 4 43


MCQ s(Continued)

3. In a transaction if it takes a symbol b as an input and top of the stack is x


and wish to perform NOP operation then the string must replace the top of
the stack with which symbol?

a. x
b. a
c. ax
d. xa

4. PDA can accept:

a. context sensitive grammars


b. context free grammars
c. unrestricted grammars
d. chomsky’s grammars

6/20/2023 Mr. Nagesh Sharma KCS - 402 TAFL Unit Number: 4 44


MCQ s(Continued)

5. During the reduce action of a bottom up DPDA ….. of a production in the


stack will be replaced by …….. of a production.
a. RHS, LHS
b. LHS, RHS
c. LHS, LHS
d. RHS, RHS

6. During shift operation bottom up PDA ……… the input terminal……….


a. PUSH, into STACK
b. POP, from STACK
c. ignore, does not change STACK
d. throw, away

6/20/2023 Mr. Nagesh Sharma KCS - 402 TAFL Unit Number: 4 45


MCQ s(Continued)

7. In case of PDA containing transactions δ(q,ɛ,X)=p and δ(q,a,X)=r then it is


known as:
a. DPDA
b. NPDA
c. Violates the rule of PDA
d. Empties the stack

8. In case of accepted string the bottom up derivation ended with:


a. Non Terminal
b. start symbol
c. terminal
d. first production

6/20/2023 Mr. Nagesh Sharma KCS - 402 TAFL Unit Number: 4 46


Expected Questions for University Exam

1. Define the concept and working of a PDA.


2. Design a PDA to accept each of the following languages. You
may accept either by final state or by empty stack, whichever
more convenient. {0n1n|n>=1}
3. Construct a PDA to accept the language having equal number
of 0’s and 1’s.
4. Design 2 stack PDA for language L={ ambncn|n>=1}
5. Define Deterministic Push Down Automata and explain
instantaneous description of PDA.

6/20/2023 Mr. Nagesh Sharma KCS - 402 TAFL Unit Number: 4 47


Summary

• Push Down Automata are an extended version of finite automata


and uses stack as auxiliary memory.
• A push down automata is defined using seven tuples.
• PDA defines moves are based on three things:
– Current State
– Current input symbol
– Top of stack
• The power of NPDA is more than DPDA.
• Given PDA corresponding CFG can be determined.

6/20/2023 Mr. Nagesh Sharma KCS - 402 TAFL Unit Number: 4 48


References

1. Aho, Hopcroft and Ullman, The Design and Analysis of Computer


Algorithms, Addison Wesley.
2. Aho, Sethi, Ullman, Compilers Principles, Techniques and Tools,
Pearson Education, 2003.
3. Hopcroft and Ullman, Introduction to Automata Theory, Languages
and Computation, Addison Wesley.
4. Kohavi, ZVI, Switching And Finite Automata Theory, Tata McGraw-
Hill, 2006.
5. Lewis and Papadimitriou, Elements of the Theory of Computation,
Prentice-Hall.
6. Martin, Introduction to Languages and the Theory of Computation,
McGraw-Hill, 2nd edition,1996.
7. Mishra, KLP, Chandrasekaran, N. Theory of Computer Science,
(Automata, Languages and Computation) PHI, 2002.

6/20/2023 Mr. Nagesh Sharma KCS - 402 TAFL Unit Number: 4 49


6/20/2023 Mr. Nagesh Sharma KCS - 402 TAFL Unit Number: 4 50

You might also like