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

Pushdown Automata - 2 May

The document discusses pushdown automata and their properties. Pushdown automata are more powerful than finite state machines as they have a stack for memory. Deterministic pushdown automata have a single transition for each input and state, while non-deterministic pushdown automata can have multiple transitions. Examples of languages recognized by deterministic and non-deterministic pushdown automata are provided.

Uploaded by

Shivam Kumar
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)
103 views

Pushdown Automata - 2 May

The document discusses pushdown automata and their properties. Pushdown automata are more powerful than finite state machines as they have a stack for memory. Deterministic pushdown automata have a single transition for each input and state, while non-deterministic pushdown automata can have multiple transitions. Examples of languages recognized by deterministic and non-deterministic pushdown automata are provided.

Uploaded by

Shivam Kumar
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/ 10

Pushdown Automata

A Pushdown Automata (PDA) is a way to implement context-free Grammar in a similar way.


We design Finite Automata for Regular Grammar.

It is more powerful than FSM.

FSM has very limited memory but PDA has more memory.

PDA= Finite State Machine + Stack

Formal definition of PDA,

PDA can be betokened formally by a 7-tuple (Q, ∑, S, δ, q0, I, F) where,

1. Q is the number of states. It is finite.


2. ∑ is an input alphabet. It is a finite set.
3. S stands for stack symbols.(which can be pushed and popped from the stack).
4. δ is the transition function which is Q × (∑ ∪ {ε}) × S × Q × S*. It is a finite subset.
5. q0 is the start or initial or beginning state (q0 ∈ Q).
6. I is the initial stack top symbol (I ∈ S).
7. F is the set of accepting states (F ∈ Q).

In a specified state, PDA will read the symbol which is at the top of the stack and the input
signal and move to a new state after changing the symbol of the stack.

DPDA

DPDA: For every input with the current state, there is only one move.

M = (Q,∑,Γ,q0, Z,F ,δ)

δ: Q*∑*Γ→Q*Γ

Non-Deterministic PDA

For every input with the current state, We can have multiple moves.
Difference between NPDA and DPDA:
S. NPDA(Non-deterministic
No DPDA(Deterministic Pushdown Automata) Pushdown Automata)

It is more powerful than


It is less powerful than NPDA.
1. DPDA.

It is not possible to convert


It is possible to convert every DPDA to a
every NPDA to a
corresponding NPDA.
2. corresponding DPDA.

The language accepted by


The language accepted by DPDA is a subset of the
NPDA is not a subset of the
language accepted by NDPA.
3. language accepted by DPDA.

The language accepted by DPDA is called The language accepted by


DCFL(Deterministic Context-free Language) which NPDA is called NCFL(Non-
is a subset of NCFL(Non-deterministic Context-free deterministic Context-free
4. Language) accepted by NPDA. Language).
Deterministic Push-Down Automata:

A PDA is said to be deterministic if all the derivations in the design have to give only a single
move.

Example 1:

Take the language L = {a^nb^2n where n > 0}

The strings in the language are L = {abb, aabbbb, . . . }

The language has a’s followed by b’s.

If we have a single a, we have two b’s. It means multiples of 2.

The logic is simple.

Whenever we see an input symbol ‘a’, we push it onto the stack.

We need to pop the stack symbol a for every second occurrence of b.

The below diagram shows the DPDA for the language L.

DPDA for L
On the state q0, if the input symbol is a and the stack top is z, or a. we push onto the stack.

On the state q0, if we see the input symbol b, we are moving to state q1 and doing no operation.

On state q1, if we see the input symbol b, we pop the element from the stack because we have
seen the second b.

We move to state q2. and loop on to state q1 for every second occurrence of b.

On the state q2, if the input symbol is epsilon, move to the final state.
Deterministic Push Down Automata for a^n b^n

First we have to count number of a's and that number should be equal to number of b's.
That we will achieve by pushing a's in STACK and then we will pop a's whenever "b" comes.
So in the end of the strings if nothing is left in the STACK then we can say that language is
accepted in the PDA.

We have designed the PDA for the problem:

DPDA for number of a(w) = number of b(w)

Here approach is little bit different than previous example.

Let either 'a' or 'b' push in STACK. That means if 'a' comes first let it push.
After 'a' if again 'a' comes then let push it.

If 'b' comes first, push it in STACK ('a' did not come yet)
If again 'b' comes then push it in STACK.

Now if 'a' is present in top of STACK and 'b' comes then, pop 'a'
Similarily if 'b' is present in top of STACK and 'a' comes then, pop 'b'

So in the end of the strings if nothing is left in the STACK then we can say that CFL is
accepted in the PDA.
We have designed the PDA for the problem:

STACK Transiton Function

δ(q0, a, Z) = (q0, aZ)


δ(q0, a, a) = (q0, aa)
δ(q0, b, Z) = (q0, bZ)
δ(q0, b, b) = (q0, bb)
δ(q0, b, a) = (q0, ε)
δ(q0, a, b) = (q0, ε)

δ(q0, ε, Z) = (qf, Z)

Note: qf is Final State

Explanation
Lets see, how this DPDA is working:
We will take one input string: "aabbbbaa"

1. Scan string from left to right


2. First input is 'a' and follow the rule:
3. on input 'a' and STACK alphabet Z, push the input 'a' into STACK as : (a,Z/aZ) and
state will be q0
4. Second input is 'a' and so follow the rule:
5. on input 'a' and STACK alphabet 'a', push the input 'a' into STACK as : (a,a/aa) and
state will remain q0
6. Second input is 'b' and so follow the rule:
7. Third input is 'b' and so follow the rule:
8. on input 'b' and STACK alphabet 'a', pop STACK with one 'a' as : (b,a/&epsiloon;) and
state will remain q0
9. Fourth input is 'b' and so follow the rule:
10. on input 'b' and STACK alphabet 'a', pop STACK with one 'a' as : (b,a/&epsiloon;) and
state will remain q0
11. Fifth input is 'b' and so follow the rule:
12. on input 'b' and STACK alphabet Z, push the input 'b' into STACK as : (b,Z/bZ) and
state will remain q0
13. Sixth input is 'b' and so follow the rule:
14. on input 'b' and STACK alphabet 'a', push the input 'b' into STACK as : (b,b/bb) and
state will remain q0
15. Seventh input is 'a' and so follow the rule:
16. on input 'a' and STACK alphabet 'b', pop STACK with one 'b' as : (a,b/&epsiloon;) and
state will remain q0
17. Eighth input is 'a' and so follow the rule:
18. on input 'a' and STACK alphabet 'b', pop STACK with one 'b' as : (a,b/&epsiloon;) and
state will remain q0
19. We reached end of the string, so follow the rule:
20. on input ε and STACK alphabet Z, go to final state(qf) as : (ε, Z/Z)

Example :

Take the language L1 = {wcw^R where w = (0+1)*}

The input alphabet Σ = {0,1,c}.

w^R shows the reverse of the w.

The strings in the language are L1 = {011c110, 001c100, . . . }

The reverse of 011 is 110. After the symbol c, we need to have the reverse of w.

The logic is simple. whatever we find before the symbol c we need to push onto the stack

After the symbol c, the first input should match the stack top. Because we need reverse of w.

After the symbol c, if the input symbol and stack top are the same, we do the pop operation.

The below diagram shows the DPDA for the language L1.
DPDA for L1
On the state q0, whatever we see, we need to push on to the stack.

On the state q0. If the input is c, move to state q1. Because from now we need to check for
reverse

on the state q1 if the input symbol and the stack symbol are the same pop the element.

On the state q1, if the input is epsilon and the stack top is z, we move to the final state.

NPDA

Problem: Design a non deterministic PDA for accepting the language L = {wwR w ∈ (a, b)+},
i.e.,

L = {aa, bb, abba, aabbaa, abaaba, ......}

Explanation: In this type of input string, one input has more than one transition states, hence it
is called non-deterministic PDA, and the input string contain any order of ‘a’ and ‘b’. Each
input alphabet has more than one possibility to move next state. And finally when the stack is
empty then the string is accepted by the NPDA. In this NPDA we used some symbols which
are given below:

Γ = { a, b, z }

Where, Γ = set of all the stack alphabet

z = stack start symbol

a = input alphabet

b = input alphabet
The approach used in the construction of PDA –

As we want to design an NPDA, thus every times ‘a’ or ‘b’ comes then either push into the
stack or move into the next state. It is dependent on a string. When we see the input alphabet
which is equal to the top of the stack then that time pop operation applies on the stack and
move to the next step.

So, in the end, if the stack becomes empty then we can say that the string is accepted by the
PDA.

STACK Transition Function

Delta is transition

|-- Push ,Pop,Skip

Where, q0 = Initial state

qf = Final state

∈ = indicates pop operation

NPDA for accepting the language L = {wwR | w ∈ (a,b)*}


L = {aa, bb, abba, aabbaa, abaaba, ......}
So, this is our required non-deterministic PDA for accepting the language L = {wwR w ∈ (a,
b)*}

Example:
We will take one input string: “abbbba”.

Scan string from left to right


The first input is ‘a’ and follows the rule:
on input ‘a’ and STACK alphabet Z, push the two ‘a’s into STACK as: (a, Z/aZ) and state will
be q0
on input ‘b’ and STACK alphabet ‘a’, push the ‘b’ into STACK as: (b, a/ba) and state will be
q0
on input ‘b’ and STACK alphabet ‘b’, push the ‘b’ into STACK as: (b, b/bb) and state will be
q0
on input ‘b’ and STACK alphabet ‘b’ (state is q1), pop one ‘b’ from STACK as: (b, b/∈) and
state will be q1
on input ‘b’ and STACK alphabet ‘b’ (state is q1), pop one ‘b’ from STACK as: (b, b/∈) and
state will be q1
on input ‘a’ and STACK alphabet ‘a’ and state q1, pop one ‘a’ from STACK as: (a, a/∈) and
state will remain q1
on input ∈ and STACK alphabet Z, go to the final state(qf) as : (∈, Z/Z)
So, at the end the stack becomes empty then we can say that the string is accepted by the PDA.

PDA for regular languages


First draw a DFA
In this
There will be 3 cases q0-rem 0,q1-rem 1,q2-rem 2

You might also like