0% found this document useful (0 votes)
8 views26 pages

Automata

Automata

Uploaded by

yoniman1352
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)
8 views26 pages

Automata

Automata

Uploaded by

yoniman1352
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/ 26

Chapter Four

PUSH DOWN AUTOMATA(PDA)


Push Down Automata(PDA)

 Pushdown automata is a way to implement a CFG in the same


way we design DFA for a regular grammar.
 A DFA can remember a finite amount of information,
 But a PDA can remember an infinite amount of information.
 Pushdown Automata (PDA) is a finite automata (FA) with extra
memory called stack .
 The addition of stack is used to provide a last-in-first-out (LIFO)
memory management capability to Pushdown automata (PDA).
 Pushdown automata can store an unbounded amount of
information on the stack.
 It can access a limited amount of information on the stack.
 A PDA can push an element onto the top of the stack and pop off
an element from the top of the stack
Cont…

 To read an element into the stack, the top elements must be popped off
and are lost.
 A PDA is more powerful than FA.
 Any language which can be acceptable by FA can also be acceptable by
PDA.
 PDA also accepts a class of language which even cannot be accepted by
FA.
 Thus PDA is much more superior to FA.
 Basically a PDA is :
 " Finite state machine " + " a stack ".
 PDA has three components:
 An input tape: The input tape is divided in many cells or symbols.
 The input head is read-only and may only move from left to right, one
symbol at a time
Cont…
 Finite control: The finite control has some pointer
which points the current symbol which is to be read.
 Stack: The stack is a structure in which we can push
and remove the items from one end only.
 It has an infinite size.
 In PDA, the stack is used to store the items
temporarily.
Cont…

 The diagram that shows a transition in a PDA from a state q1, to


state q2, labeled as a, b →c.

 At state q1, if an i/p string is 'a' is encounter and top symbol of the
stack is 'b‘ then we pop 'b' , push 'c' on top of the stack and move to
state q2.
Formal Definition of PDA

 A PDA can be formally described as 7-tuples (Q, ∑, Γ, δ,


q0, Z, F).
 Q is finite number of states.
 ∑ is input alphabet.
 Γ(gama) is a stack symbol which can be pushed and
popped from the stack
 q0 is the initial state (q0 ϵ Q)
 Z is a start symbol which is in Γ.
 F is set of accepting states (F ϵ Q)
 δ (delta)is mapping function which is used for moving
from current state to next state.
Terminologies Related to PDA

1. Instantaneous Description(ID)
 ID is an informal notation of how a PDA computes
an input string and make a decision that string is
accepted or rejected.
 The instantaneous description (ID) of a PDA is
represented by a triplet (q, w, s )
q is a current state
 w is unconsumed input

 s is the stack contents


Cont…

2. Turnstile Notation:
 ⊢sign describes the turnstile notation and represents
one move.
 It is used for connecting pairs of ID’s that represent
one or many moves of a PDA.
 ⊢* sign describes a sequence of moves.
 Example: (p, b,T ) ⊢(q, w, a)
 While taking a transition from p to q, the input
symbol ' b ' is consumed and top of the stack 'T' is
represented with a new string 'a '.
PDA Acceptance

 There are two different ways to define PDA acceptability.


1. Final State Acceptability
 A PDA accepts a string, after reading the entire string,
the PDA is in final state.
 From the starting state, we can make moves that end up
in a final state with any stack values.
 The stack values are irrelevant as long as we end up in a
final state.
 For a PDA ((Q, ∑, S, δ, q0, I, F) the language accepted by
the set of final sates
 F is L(PDA) ={w | (q0, w, I) ⊢* (q, ɛ, x), q ϵ F} for any
input stack string x
Cont…

2. Empty Stack Acceptability


 Here a PDA accepts a string , after reading the entire
string, the PDA has emptied its stack.
 For a PDA (Q, ∑, S, δ, q0, I, F) the language
accepted by Empty Stack
 L(PDA) ={w | (q0, w, I) * (q, ɛ, ɛ), q ϵ Q} for any
input string x.
Empty stack
Cont…

 Example1: Construct PDA that accepts L = {a^nb^m


| n ≥ m, m ≥1}in final state.
 Solution: simple logic at least one b is there and 2 a's
should be there.
 L={aab, aaabb, aaaabbb. ….}
Cont…

 Now we will simulate this PDA for the input string


"aaabb".
 δ(q0, aaabb, Z0) push a
 δ(q0, aabb, aZ0) push a
 δ(q0, abb, aaZ0) push a
 δ(q0, bb, aaaZ0) push a
 δ(q0, bb, aaaZ0) pop a
 δ(q1, b, aaZ0) pop a
 (q1, ε, aZ0)
 δ(q2, a) Accept
Cont…

 Example 2 : Design a PDA for accepting a language {a^nb^2n |


n>=1} in empty stack acceptability
 Solution: strings belong to this language are {abb, aabbbb,
aaabbbbbb,….}
 In this language, n number of a's should be followed by 2n number
of b's.
 Hence, we will apply a very simple logic, and that is if we read single
'a', we will push two a's onto the stack.
 As soon as we read 'b' then for every single 'b' only one 'a' should
get popped from the stack
 For a single a push 2 a’s on the top of the stack.
 If you read input b pop 1 a from the top of the stack
 After popping each a for corresponding each b,
the stack is empty
Cont…

 So, the PDA diagram will be constructed as follows:

 Now we can write the Instantaneous Description(ID)


as follows:
 δ(q0, a, Z0) = (q0, aaZ0)
 δ(q0, a, a) = (q0, aaa)
 δ(q0, b, a) = (q1, ε)
 δ(q1, ε, Z0) = (q2, Z0)
Cont…

 Now we will simulate this PDA for the input string


"aabbbb".
 δ(q0, aabbbb, Z0)
 δ(q0, abbbb, aaZ0) push 2 a on stack
 δ(q0, bbbb, aaaaZ0) push 2 a on stack
 δ(q1, bbb, aaaZ0) pop 1 a from the stack
 δ(q1, bb, aaZ0) pop 1 a from the stack
 δ(q1, b, aZ0) pop 1 a from the stack
 δ(q1, ε , Z0)
 δ(q2, ε)
Deterministic Push Down Automata (DPDA)

 The DPDA is a variation of pushdown automata that


accepts the deterministic context-free languages.
 A language L(A) is accepted by a DPDA if and only if
there is a single computation from the initial
configuration until an accepting one for all strings
belonging to L(A).
 It is not as powerful as non-deterministic finite
automata.
 That's why it is less in use and used only where
determinism is much easier to implement.
 A PDA is said to be deterministic if its transition function
δ(q, a, X) has at most one member for a Σ U {ε}
Cont…

 So, for a deterministic PDA, there is at most one


transition possible in any combination of state, input
symbol and stack top.
Non-Deterministic Push Down Automata (NPDA)

 A non-deterministic PDA is used to generate a


language that a deterministic automata cannot
generate.
 It is more powerful than a deterministic PDA.
 So, a push down automata is allowed to be non-
deterministic.
Cont…

 A non-deterministic pushdown automaton is a 7-tuple.


 NPDA = (Q, Σ, Γ, δ, q0, Z, F) where
 Q- It is the finite set of states,
 Σ - finite set of input alphabet,
 Γ - finite set of stack alphabet,
 δ - transition function,
 q0 - initial state,
 Z - stack start symbol
 F-Final state
 Example: Construct NPDA for the language L={a b | n>=1} .
n 3n

 Solution: string of the language are w={abbb, aaabbbbbb, …..}


Pushdown Automata and Context-Free Languages

Context Free Language


 A language is context free if there exists a context free
grammar that can generate it.
 Example1: The language L=a^nb^n, n≥0, is generated by a
grammar whose rule are:
S → aSb
S→ε
 Example2: The language L=wwR, n≥0, is generated by a
grammar whose rule are:
S → aSa
S → bSb
S→ε
 A language is context free if and only if it is accepted by
pushdown automata.
Properties of Context Free Languages

 Context-free languages are closed under:


1. Union
2. Concatenation
3. Kleene Star operation
1. Union
 Let L 1 and L2 be two context free languages.
 Then L 1 U L2 is also context free language.
 Example
 Let L1 = { a^nb^n , n > 0}. Corresponding grammar G1 will have P:
S1 → aAb|ab
 Let L2 = { c^md^m , m ≥ 0}. Corresponding grammar G2 will have
P: S2 → cBb| ε
 Union of L1 and L2, L = L1 L2 = { a^nb^n } U { c^md^m }.
 The corresponding grammar G will have the additional production S
→ S1 | S2.
Cont…

2. Concatenation
 If L1 and L2 are context free languages, then L1L2 is also context free
language.
 Example
 Concatenation of the languages L1 and L2, L = L1.L2 = { a^nb^nc^md^m }
 The corresponding grammar G will have the additional production S →
S1S2
3. Kleene Star
 If L is a context free language, then L* is also context free language.
 Example
 Let L1 = { a^nb^n , n ≥ 0}. Corresponding grammar G will have P: S →
aAb| ε
 Kleene Star L1 = { a^nb^n }*
 The corresponding grammar G1 will have additional productions S1 → SS1

 Context-free languages are not closed under:
 Intersection − If L1 and L2 are context free
languages, then L1 ∩ L2 is not necessarily context
free language.
 Intersection with Regular Language − If L1 is a
regular language and L 2 is a context free language,
then L1∩ L2 is not a context free language.
 Complement − If L1 is a context free language,
then L1' may not be context free.
Application of Push Down Automata (PDA)

 For designing the parsing phase of a compiler(Syntax


Analysis).
 For implementation of stack applications.
 For evaluating the arithmetic expressions.
 For solving the Tower of Hanoi Problem.
Exercise(10%)

 Construct PDA for a language L = { a^nb^n : n ≥ 0}


and simulate using PDA for the string aaabbb
acceptance or not.
 Construct PDA for language L = {a^2nb^m : n ≥ 0,
m ≥ 0} and simulate using PDA for the string aab
acceptance or not.
 Construct PDA for language L = {a^nb^mc^n : n ≥ 1,
m ≥ 1} and simulate using PDA for the string
aabbbcc acceptance or not.
 Design PDA for Palindrome strings and simulate for
the string abaaba
END OF THE CHAPTER

You might also like