0% found this document useful (0 votes)
7 views

Pushdown Automata

The document provides an overview of Pushdown Automata (PDA), detailing its components and functions, including the definition of Instantaneous Description and Turnstile notation. It explains the construction of PDAs for various context-free languages, acceptance criteria, and the differences between deterministic and non-deterministic PDAs. Additionally, it includes examples and homework questions related to constructing PDAs for specific languages.

Uploaded by

saloni05012004
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Pushdown Automata

The document provides an overview of Pushdown Automata (PDA), detailing its components and functions, including the definition of Instantaneous Description and Turnstile notation. It explains the construction of PDAs for various context-free languages, acceptance criteria, and the differences between deterministic and non-deterministic PDAs. Additionally, it includes examples and homework questions related to constructing PDAs for specific languages.

Uploaded by

saloni05012004
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Dr. Md. A. K.

Akhtar, UMU

Pushdown Automata
Pushdown Automata is a finite automata with extra memory called stack which
helps Pushdown automata to recognize Context Free Languages.

A Pushdown Automata (PDA) can be defined as :


• Q is the set of states
• ∑is the set of input symbols
• Γ is the set of pushdown symbols (which can be pushed and popped
from stack)
• q0 is the initial state
• Z is the initial pushdown symbol (which is initially present in stack)
• F is the set of final states
• δ is a transition function which maps Q x {Σ ∪ ∈} x Γ into Q x Γ*. In a
given state, PDA will read input symbol and stack symbol (top of the
stack) and move to a new state and change the symbol of stack.

Instantaneous Description (ID)


Instantaneous Description (ID) is an informal notation of how a PDA “computes”
a input string and make a decision that string is accepted or rejected.
A ID is a triple (q, w, α), where:
1. q is the current state.
2. w is the remaining input.
3.α is the stack contents, top at the left.

Turnstile notation
⊢ sign is called a “turnstile notation” and represents
one move.
⊢* sign represents a sequence of moves.
Eg- (p, b, T) ⊢ (q, w, α)
This implies that while taking a transition from state p to state q, the input
symbol ‘b’ is consumed, and the top of the stack ‘T’ is replaced by a new string ‘α’

Example : Define the pushdown automata for language {anbn | n > 0}


Solution : M = where Q = { q0, q1 } and Σ = { a, b } and Γ = { A, Z } and &delta is
given by :

&delta( q0, a, Z ) = { ( q0, AZ ) }


&delta( q0, a, A) = { ( q0, AA ) }
&delta( q0, b, A) = { ( q1, ∈) }
&delta( q1, b, A) = { ( q1, ∈) }
&delta( q1, ∈, Z) = { ( q1, ∈) }

Let us see how this automata works for aaabbb.

1
Dr. Md. A. K. Akhtar, UMU

Explanation : Initially, the state of automata is q0 and symbol on stack is Z and


the input is aaabbb as shown in row 1. On reading ‘a’ (shown in bold in row 2),
the state will remain q0 and it will push symbol A on stack. On next ‘a’ (shown in
row 3), it will push another symbol A on stack. After reading 3 a’s, the stack will
be AAAZ with A on the top. After reading ‘b’ (as shown in row 5), it will pop A and
move to state q1 and stack will be AAZ. When all b’s are read, the state will be q1
and stack will be Z. In row 8, on input symbol ‘∈’ and Z on stack, it will pop Z and
stack will be empty. This type of acceptance is known as acceptance by empty
stack.

Note :
• The above pushdown automaton is deterministic in nature because
there is only one move from a state on an input symbol and stack
symbol.
• The non-deterministic pushdown automata can have more than one
move from a state on an input symbol and stack symbol.
• It is not always possible to convert non-deterministic pushdown
automata to deterministic pushdown automata.
• Expressive Power of non-deterministic PDA is more as compared to
expressive deterministic PDA as some languages which are accepted by
NPDA but not by deterministic PDA which will be discussed in next
article.
• The push down automata can either be implemented using accepetance
by empty stack or accepetance by final state and one can be converted
to another.

Question : Which of the following pairs have DIFFERENT expressive power?


A. Deterministic finite automata(DFA) and Non-deterministic finite
automata(NFA)
B. Deterministic push down automata(DPDA)and Non-deterministic push down
automata(NPDA)

2
Dr. Md. A. K. Akhtar, UMU

C. Deterministic single-tape Turing machine and Non-deterministic single-tape


Turing machine
D. Single-tape Turing machine and multi-tape Turing machine
Solution : Every NFA can be converted into DFA. So, there expressive power is
same. As discussed above, every NPDA can’t be converted to DPDA. So, the power
of NPDA and DPDA is not same. Hence option (B) is correct.
PDA Acceptance
• 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.
• Acceptance by Empty Stack: On reading the input string from the initial
configuration for some PDA, the stack of PDA gets empty.

Q) Construct a PDA for language L = {0n1m2m3n | n>=1, m>=1}


Approach used in this PDA –
First 0’s are pushed into stack. Then 1’s are pushed into stack.
Then for every 2 as input a 1 is popped out of stack. If some 2’s are still left
and top of stack is a 0 then string is not accepted by the PDA. Thereafter if
2’s are finished and top of stack is a 0 then for every 3 as input equal
number of 0’s are popped out of stack. If string is finished and stack is empty
then string is accepted by the PDA otherwise not accepted.
• Step-1: On receiving 0 push it onto stack. On receiving 1, push it
onto stack and goto next state
• Step-2: On receiving 1 push it onto stack. On receiving 2, pop 1
from stack and goto next state
• Step-3: On receiving 2 pop 1 from stack. If all the 1’s have been
popped out of stack and now receive 3 then pop a 0 from stack and
goto next state
• Step-4: On receiving 3 pop 0 from stack. If input is finished and
stack is empty then goto last state and string is accepted

3
Dr. Md. A. K. Akhtar, UMU

Examples:
Input : 0 0 1 1 1 2 2 2 3 3
Result : ACCEPTED

Input : 0 0 0 1 1 2 2 2 3 3
Result : NOT ACCEPTED
Q) Construct a PDA for language L = {0n1m | n >= 1, m >= 1, m > n+2}
Approach used in this PDA –
First 0’s are pushed into stack.When 0’s are finished, two 1’s are ignored.
Thereafter for every 1 as input a 0 is popped out of stack. When stack is
empty and still some 1’s are left then all of them are ignored.
• Step-1: On receiving 0 push it onto stack. On receiving 1, ignore it
and goto next state
• Step-2: On receiving 1, ignore it and goto next state
• Step-3: On receiving 1, pop a 0 from top of stack and go to next
state
• Step-4: On receiving 1, pop a 0 from top of stack. If stack is empty,
on receiving 1 ingore it and goto next state
• Step-5: On receiving 1 ignore it. If input is finished then goto last
state

Examples:
Input : 0 0 0 1 1 1 1 1 1
Result : ACCEPTED

Input : 0 0 0 0 1 1 1 1
Result : NOT ACCEPTED

4
Dr. Md. A. K. Akhtar, UMU

Home Work:
Construct Pushdown automata for L = {0n1m2m3n | m,n ≥ 0}
Construct Pushdown automata for L = {0m1(n+m)2n | m,n ≥ 0}
Construct Pushdown automata for L = {0(n+m)1m2n | m, n ≥ 0}
Construct Pushdown automata for L = {0n1m2(n+m) | m,n ≥ 0}

Que: Construct a PDA for language L = {wcw’ | w={0, 1}*} where w’ is the
reverse of w.
Approach used in this PDA –
Keep on pushing 0’s and 1’s no matter whatever is on the top of stack until
reach the middle element. When middle element ‘c’ is scanned then process
it without making any changes in stack. Now if scanned symbol is ‘1’ and top
of stack also contain ‘1’ then pop the element from top of stack or if scanned
symbol is ‘0’ and top of stack also contain ‘0’ then pop the element from top
of stack. If string becomes empty or scanned symbol is ‘$’ and stack
becomes empty, then reach to final state else move to dead state.
• Step 1: On receiving 0 or 1, keep on pushing it on top of stack
without going to next state.
• Step 2: On receiving an element ‘c’, move to next state without
making any change in stack.
• Step 3: On receiving an element, check if symbol scanned is ‘1’
and top of stack also contain ‘1’ or if symbol scanned is ‘0’ and top
of stack also contain ‘0’ then pop the element from top of stack else
move to dead state. Keep on repeating step 3 until string becomes
empty.
• Step 4: Check if symbol scanned is ‘$’ and stack does not contain
any element then move to final state else move to dead state.

5
Dr. Md. A. K. Akhtar, UMU

Examples:

Input : 1 0 1 0 1 0 1 0 1
Output :ACCEPTED
Input : 1 0 1 0 1 1 1 1 0
Output :NOT ACCEPTED
Que: Construct a PDA for language L = {ww’ | w={0, 1}*} where w’ is the
reverse of w.
Approach used in this PDA –
For construction of even length palindrome, user has to use Non
Deterministic Pushdown Automata (NPDA). A NPDA is basically an NFA with
a stack added to it.
The NPDA for this language is identical to the previous one except for
epsilon transition. However, there is a significant difference, that this PDA
must guess when to stop pushing symbols, jump to the final state and start
matching off of the stack. Therefore this machine is decidedly non-
deterministic.
Keep on pushing 0’s and 1’s no matter whatever is on the top of stack and at
the same time keep a check on the input string, whether reach to the second
half of input string or not. If reach to last element of first half of the input
string then after processing the last element of first half of input string make
an epsilon move and move to next state. Now if scanned symbol is ‘1’ and
top of stack also contain ‘1’ then pop the element from top of stack or if
scanned symbol is ‘0’ and top of stack also contain ‘0’ then pop the element
from top of stack. If string becomes empty or scanned symbol is ‘$’ and stack
becomes empty, then reach to final state else move to dead state.
• Step 1: On receiving 0 or 1, keep on pushing it on top of stack and
at a same time keep on checking whether reach to second half of
input string or not.
• Step 2: If reach to last element of first half of input string, then push
that element on top of stack and then make an epsilon move to next
state.
• Step 3: On receiving an element, check if symbol scanned is ‘1’
and top of stack also contain ‘1’ or if symbol scanned is ‘0’ and top
of stack also contain ‘0’ then pop the element from top of stack else
move to dead state. Keep on repeating step 3 until string becomes
empty.
• Step 4: Check if symbol scanned is ‘$’ and stack does not contain
any element then move to final state else move to dead state.

6
Dr. Md. A. K. Akhtar, UMU

Examples:
Input : 1 0 0 1 1 1 1 0 0 1
Output :ACCEPTED

Input : 1 0 0 1 1 1
Output :NOT ACCEPTED
Now, take the example of all length palindrome, i.e. a PDA which can accept
both odd length palindrome and even length palindrome:
Que: Construct a PDA for language L = {ww’ | wcw’, w={0, 1}*} where w’ is
the reverse of w.
Approach used in this PDA –
For construction of all length palindrome, user has to use NPDA.
The approach is similar to above example, except now along with epsilon
move now user has to show one more transition move of symbol ‘c’ i.e. if
string is of odd length and if reach to middle element ‘c’ then just process it
and move to next state without making any change in stack.
• Step 1: On receiving 0 or 1, keep on pushing it on top of stack and
at a same time keep on checking, if input string is of even length
then whether reach to second half of input string or not, however if
the input string is of odd length then keep on checking whether
reach to middle element or not.
• Step 2: If input string is of even length and reach to last element of
first half of input string, then push that element on top of stack and
then make an epsilon move to next state or if the input string is of
odd length then on receiving an element ‘c’, move to next state
without making any change in stack.
• Step 3: On receiving an element, check if symbol scanned is ‘1’
and top of stack also contain ‘1’ or if symbol scanned is ‘0’ and top
of stack also contain ‘0’ then pop the element from top of stack else

7
Dr. Md. A. K. Akhtar, UMU

move to dead state. Keep on repeating step 3 until string becomes


empty.
• Step 4: Check if symbol scanned is ‘$’ and stack does not contain
any element then move to final state else move to dead state.

Examples:
Input : 1 1 0 0 1 1 1 1 0 0 1 1
Output :ACCEPTED

Input : 1 0 1 0 1 0 1
Output :ACCEPTED

You might also like