0% found this document useful (0 votes)
48 views19 pages

TOC Lecture 13

The document discusses pushdown automata (PDA), which are more powerful than finite state machines because they have a stack to store memory. A PDA consists of a finite state control, input tape, and stack. It formally defined by 7 tuples including states, input symbols, stack symbols, transition function, initial state, start stack symbol, and accepting states. The transition function specifies how the PDA changes state and modifies the stack based on the input symbol and top of stack symbol. Non-deterministic PDA can have multiple transitions for a given input/stack pair, allowing it to "guess" which path to take.

Uploaded by

Varchasva Singh
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)
48 views19 pages

TOC Lecture 13

The document discusses pushdown automata (PDA), which are more powerful than finite state machines because they have a stack to store memory. A PDA consists of a finite state control, input tape, and stack. It formally defined by 7 tuples including states, input symbols, stack symbols, transition function, initial state, start stack symbol, and accepting states. The transition function specifies how the PDA changes state and modifies the stack based on the input symbol and top of stack symbol. Non-deterministic PDA can have multiple transitions for a given input/stack pair, allowing it to "guess" which path to take.

Uploaded by

Varchasva Singh
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/ 19

TOC Lecture-13

Pushdown Automata
Introduction
• A Pushdown Automata (PDA) is a way to implement a Context Free
Grammar in a similar way we design Finite Automata for Regular
Grammar.

• PDA is more powerful than Finite State Machine (FSM).

• FSM has very limited memory but PDA has more memory.

• PDA = FSM + A Stack

• Stack – is a structure that can be:


– Read,
– Pushed (into), and
– Popped (from),
only from its top (just like “stack” data structure).
Components of PDA

• A Pushdown Automata has 3 components:


1. An Input Tape
2. A Finite Control Unit
3. A Stack with infinite size
PDA: Formal Definition
• A Pushdown Automata is formally defined by 7 tuples:
Q = finite set of states

= finite set of input symbols

Г = finite stack alphabet, components we are allowed to push


on the stack

 = transition function

q0 = initial state

z0 = start stack symbol

F = set of final or “accepting” states


PDA: Transition Function
• δ = transition function, which takes the triple: δ(q, a, X) where
– q = state in Q
– a = input symbol in 
– X = stack symbol in Γ

• The output of δ is the finite set of pairs ( p, γ ) where p is a new


state and γ is a new string of stack symbols that replaces X at the
top of the stack.
– If γ = ε then we pop the stack

– if γ = X the stack is unchanged

– if γ = YZ then X is replaced by Z and Y is pushed on the stack. Note


the new stack top is to the left end.
PDA: Graphical Notation
Finite State Machine
a
q0 q1

Pushdown Automata

a,b/c
q0 q1

Symbol on top
This symbol is
Input of the Stack.
pushed onto
symbol. This symbol is
the stack.
popped.
PDA: Graphical Notation
0
0, 1 / 01
q0 q1  1 1
Push 0
z0 z0

0, 1 / 
q0 q1  1
Pop
z0 z0

0, 1 / 1
q0 q1  1
Neither
1
z0 z0
Push
nor Pop
PDA: Graphical Notation
0, 1 / 0
q0 q1  1 0
Pop 1
z0 z0
Push 0

0, 1 / 00 0
q0 q1  1 0
Pop 1
z0 z0
Push 00

0,  / 0 On seeing 0 in input, push 0 on


q0 q1  stack (irrespective of what top is)
PDA: Example
• Design a pushdown automata for language {an bn | n > 0}
• Let’s take an input string: "aabb$"

aabb$ aabb$ aabb$ aabb$ aabb$ aabb$

a
a a a
z0 z0 z0 z0 z0

Empty Push a Push a Pop a Pop a Pop z0


(q0) (q0) (q0) (q1) (q1) Empty  Accept
(q2)
PDA: Example
• Design a pushdown automata for language {an bn | n > 0}

• Let’s take an input string: "aabb$"

Stack (leftmost State


Row State Input δ(q, a, X) symbol represents after
top of stack) move

1 q0 aabb$ z0 q0
2 q0 aabb$ δ(q0, a, z0) = (q0, a z0) a z0 q0
3 q0 aabb$ δ(q0, a, a) = (q0, a a) a a z0 q0
4 q0 aabb$ δ(q0, b, a) = (q1, ) a z0 q1
5 q1 aabb$ δ(q1, b, a) = (q1, ) z0 q1
6 q1 aabb$ δ(q1, $, z0) = (q2, )  q2
PDA: Transition Diagram
• Design a pushdown automata for language {an bn | n > 0}

• Let’s take an input string: "aabb$"

Instantaneous Description
a, z0 / az0
a, a / aaz0 b, a /  (q0, aabb$, z0) ⊢ (q0, abb$, az0)
⊢ (q0, bb$, aaz0)
⊢ (q0, b$, az0)
$, z0 / 
q0 q1 q2 ⊢ (q0, $, z0)
⊢ (q0, , )
PDA: 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.

• An instantaneous description is a triple (q, w, α) where:


 q describes the current state.
 w describes the remaining input.
 α describes the stack contents, top at the left.

• Turnstile Notation:
 ⊢ sign describes the turnstile notation and represents one move.
 ⊢* sign describes a sequence of moves.

• Example: ( p , b , T ) ⊢ ( q , w , α )
Question
• Design a PDA that accepts L = {wcwR | w  {0 + 1}*}

• Solution:

a, z0 / az0 a, a / 
b, z0 / bz0 b, b / 
c, a / a
c, b / b $, z0 / 
q0 q1 q2

a, a / aa
a, b / ab
b, a / ba
b, b / bb
PDA: Acceptance
1. Acceptance by Final State: The PDA is said to accept its input by
the final state if it enters any final state in zero or more moves
after reading the entire input.
– Let P = (Q, ∑, Γ, δ, q0, z0, F) be a PDA. The language acceptable by
the final state can be defined as:

L(PDA) = {w | (q0, w, z0) ⊢* (p, ε, γ), p ∈ F, γ ∈ Γ*}

2. Acceptance by Empty Stack: On reading the input string from the


initial configuration for some PDA, the stack of PDA gets empty.
– Let P = (Q, ∑, Γ, δ, q0, z0, F) be a PDA. The language acceptable by
empty stack can be defined as:

N(PDA) = {w | (q0, w, z0) ⊢* (p, ε, ε), p ∈ Q}


Non-Deterministic
Pushdown Automata
Non-Deterministic Pushdown Automata
• A deterministic PDA (DPDA) must have only one transition for any
given pair of input symbol/ stack symbol.

• A non-deterministic PDA (NPDA) may have no transition or several


transitions defined for a particular input symbol/stack symbol pair.

• In an NPDA, there may be several paths to follow to process a given


input string.
– Some of the paths may result in accepting the string.

– Other paths may end in a non-accepting state.

• An NPDA can “guess” which path to follow through the machine in


order to accept a string.
Non-Determinism
• Non- determinism means that we can have more than one choice.

q2 q2

q1 q1

q3 q3

q2 q2

q1 q1

q3 q3
Example
• Design an NPDA for the language L = {wwR | w  {0 + 1}+}

• Solution:

a, z0 / az0 a, a / 
b, z0 / bz0 b, b / 
a, a / 
b, b /  $, z0 / 
q0 q1 q2

a, a / aa
a, b / ab
b, a / ba
b, b / bb
DPDA Vs. NPDA
• The languages accepted by DPDA are called Deterministic
Context Free Languages (DCFL).

• The languages accepted by NPDA are called Non-


Deterministic Context Free Languages (NCFL).

• NPDA is more powerful than DPDA.

• It is not possible to convert every NPDA to DPDA.

You might also like