The document Pushdown Automata (PDA) Computer Science Engineering (CSE) Notes | EduRev is a part of the Computer Science Engineering (CSE) Course Theory of Computation.

All you need of Computer Science Engineering (CSE) at this link: Computer Science Engineering (CSE)

**Part IV. Pushdown Automata (PDA)**

As we learned, context free languages are generated using context free grammars. Context free languages are recognised using pushdown automata.

Following diagram shows a pushdown automation.

The PDA has three components:

An input tape,

A control mechanism, and

A stack.

From the input tape, the finite control reads the input, and also

the finite control reads a symbol from the stack top.

**6 Definition of PDA**

A pushdown automation, P is a system,

P = (Q,âˆ‘, Î“, Î´, q0, F)

where

Q is a set of states,

âˆ‘ is a set of input symbols,

Î“ is a set of stack symbols (pushdown symbols),

q_{0} is the start state,

F is a set of final states,

Î´ is a transition function which maps,

(Q Ã—âˆ‘* Ã—Î“*) â†’ (Q Ã— Î“*)

The meaning of Î´ is explained below:

Consider a transition function, Î´ in a PDA defined by,

Î´ = (p, a, Î²) â†’ (q, Î³)

This means that

read a from the input tape,

pop the string Î² from stack top,

move from state p to state q,

push string Î³ on to the stack top.

Pushing the string abc on to the stack means,

Example:

Consider the following PDA,

Suppose PDA is currently in state q_{1 }and the finite control points to state a and the stack contents are as shown above.

Let a transition is given as,

Î´ = (q_{1}, a, b) â†’ (q_{2}, cd)

This means PDA currently in state q1, on reading the input symbol, a and popping b from the stack top changes to state q_{2} and pushes cd on to the stack top.

The new PDA is shown below:**7 Language Acceptability by PDA****Example 1:**

Consider a PDA,

P = (Q,âˆ‘, Î“, Î´, q0, F)

where

Q = {s, q, f}

âˆ‘= {a, b}

Î“ = {a, b, c}

q0 = {s}

F = {f}

Î´ is given as follows:

1. (s, a, Îµ) â†’ (q, a)

2. (s, b, Îµ) â†’ (q, b)

3. (q, a, a) â†’ (q, aa)

4. (q, b, b) â†’ (q, bb)

5. (q, a, b) â†’ (q, Îµ)

6. (q, b, a) â†’ (q, Îµ)

7. (q, b, Îµ) â†’ (q, b)

8. (q, Îµ, Îµ) â†’ (f, Îµ)

Check whether the string abbbaaba is accepted by the above pushdown automation.

From the above, stack is initially empty, the start state of the PDA is s and PDA points to symbol, a as shown below:

1.

The PDA is in state s, stack top contains symbol Îµ. Consider the transition,

1. (s, a, Îµ) â†’ (q, a)

This means PDA in state s, reads a from the tape, pops nothing from stack top, moves to state q and pushes a onto the stack.

PDA now is,

2.

The PDA is in state q, finite control points to symbol b in the input tape, stack top contains symbol a. Consider the transition,

6. (q, b, a) â†’ (q, Îµ)

This means PDA is in state q, reads b from the input tape, pops a from stack top, moves to state q and pushes nothing onto the stack.

PDA now is,

3.

The PDA is in state q, finite control points to symbol b in the input tape, stack top contains symbol Îµ. Consider the transition,

7. (q, b, Îµ) â†’ (q, b)

This means PDA is in state q, reads b from the input tape, pops Îµ from stack top, moves to state q and pushes b on to the stack.

PDA now is,

4.

The PDA is in state q, finite control points to symbol b in the input tape, stack top contains symbol b. Consider the transition,

4. (q, b, b) â†’ (q, bb)

This means PDA is in state q, reads b from the input tape, pops b from stack top, moves to state q and pushes bb onto the stack.

PDA now is,

5.

The PDA is in state q, finite control points to symbol a in the input tape, stack top contains symbol b. Consider the transition,

5. (q, a, b) â†’ (q, Îµ)

This means PDA is in state q, reads a from the input tape, pops b from stack top, moves to state q and pushes Îµ on to the stack.

PDA now is,

6.

The PDA is in state q, finite control points to symbol a in the input tape, stack top contains symbol b. Consider the transition,

5. (q, a, b) â†’ (q, Îµ)

This means PDA is in state q, reads a from the input tape, pops b from stack top, moves to state q and pushes nothing on to the stack.

PDA now is,

7.

The PDA is in state q, finite control points to symbol b in the input tape, stack top contains symbol Îµ. Consider the transition,

7. (q, b, Îµ) â†’ (q, b)

This means PDA is in state q, reads b from the input tape, pops Îµ from stack top, moves to state q and pushes b onto the stack.

PDA now is,

8.

The PDA is in state q, finite control points to symbol a in the input tape, stack top contains symbol b. Consider the transition,

5. (q, a, b) â†’ (q, Îµ)

This means PDA is in state q, reads a from the input tape, pops b from stack top, moves to state q and pushes Îµ on to the stack.

PDA now is,

9.

The PDA is in state q, finite control points to symbol Îµ in the input tape, stack top contains symbol Îµ. Consider the transition,

8. (q, Îµ, Îµ) â†’ (f, Îµ)

This means PDA is in state q, reads Îµ from the input tape, pops Îµ from stack top, moves to state f and pushes nothing on to the stack.

PDA now is,

Now PDA is in final state, f, and stack is empty. There are no more symbols in the input tape.

So the string abbbaaba is accepted by the above pushdown automation.

**Example 2:**

1.

Consider a PDA,

P = (Q,âˆ‘, Î“, Î´, q_{0}, F)

where

Q = {s, f}

âˆ‘= {a, b, c}

Î“ = {a, b}

q_{0} = {s}

F = {f}

Î´ is given as follpws:

1. (s, a, Îµ) â†’ (s, a)

2. (s, b, Îµ) â†’ (s, b)

3. (s, c, Îµ) â†’ (f, Îµ)

4. (f, a, a) â†’ (f, Îµ)

5. (f, b, b) â†’ (f, Îµ)

Check whether the string abacaba is accpeted by the above pushdown automation.

From the above, stack initially is empty, the start state of the PDA is s as shown below:

1.

The PDA is in state s, finite control points to symbol a in the input tape, stack top contains symbol Îµ. Consider the transition,

1. (s, a, Îµ) â†’ (s, a)

This means PDA is in state s, reads a from the input tape, pops nothing from stack top, moves to state s and pushes a on to the stack.

PDA now is,

2.

The PDA is in state s, finite control points to symbol b in the input tape, stack top contains symbol a. Consider the transition,

2. (s, b, Îµ) â†’ (s, b)

This means PDA is in state s, reads b from the input tape, pops nothing from stack top, moves to state s and pushes b on to the stack.

PDA now is,

3.

The PDA is in state s, finite control points to symbol a in the input tape, stack top contains symbol b. Consider the transition,

1. (s, a, Îµ) â†’ (s, a)

This means PDA is in state s, reads a from the input tape, pops nothing from stack top, moves to state s and pushes a on to the stack.

PDA now is,

4.

The PDA is in state s, finite control points to symbol c in the input tape, stack top contains symbol a. Consider the transition,

3. (s, c, Îµ) â†’ (f, Îµ)

This means PDA is in state s, reads c from the input tape, pops nothing from stack top, moves to state f and pushes nothing onto the stack.

PDA now is,

5.

The PDA is in state f, finite control points to symbol a in the input tape, stack top contains symbol a. Consider the transition,

4. (f, a, a) â†’ (f, Îµ)

This means PDA is in state f, reads a from the input tape, pops a from stack top, moves to state f and pushes nothing on to the stack.

PDA now is,

6.

The PDA is in state f, finite control points to symbol b in the input tape, stack top contains symbol b. Consider the transition,

5. (f, b, b) â†’ (f, Îµ)

This means PDA is in state f, reads b from the input tape, pops b from stack top, moves to state f and pushes nothing on to the stack.

PDA now is,

7.

The PDA is in state f, finite control points to symbol a in the input tape, stack top contains symbol a. Consider the transition,

4. (f, a, a) â†’ (f, Îµ)

This means PDA is in state f, reads a from the input tape, pops a from stack top, moves to state f and pushes nothing on to the stack.

PDA now is,

Now there are no more symbols in the input string, stack is empty. PDA is in final state, f. So the string abacaba is accepted by the above pushdown automation.

Exercises:

1.

Consider a PDA,

P = (Q,âˆ‘, Î“, Î´, q_{0}, F)

where

Q = {q_{0}, q_{1}, q_{2}, q_{3}}

âˆ‘ = {0, 1}

Î“ = {0, 1}

q_{0} = {q_{0}}

F = {q_{3}}

Î´ is given as follpws:

1. (q_{0}, 0, Îµ) â†’ (q_{1}, 0)

2. (q_{1}, 0, 0) â†’ (q_{1}, 00)

3. (q_{1}, 1, 0) â†’ (q_{2}, Îµ)

4. (q_{2}, 1, 0) â†’ (q_{2}, Îµ)

5. (q_{2}, Îµ, Îµ) â†’ (q_{3}, Îµ)

Check whether the string 000111 is accpeted by the above pushdown automation.

2.

Consider a PDA,

P = (Q,âˆ‘, Î“, Î´, q_{0}, F)

where

Q = {q_{0}, q_{1}, q_{2}, q_{3}}

âˆ‘ = {a, b}

Î“ = {a, b}

q_{0} = {q_{0}}

F = {q_{3}}

Î´ is given as follpws:

1. (q_{0}, a, Îµ) â†’ (q_{1}, a)

2. (q_{1}, a, a) â†’ (q_{1}, aa)

3. (q_{1}, b, a) â†’ (q_{2}, a)

4. (q_{2}, a, a) â†’ (q_{2}, Îµ)

5. (q_{2}, Îµ, Îµ) â†’ (q_{3}, Îµ)

Check whether the string aabaa is accpeted by the above pushdown automation.

3.

Consider a PDA,

P = (Q,âˆ‘, Î“, Î´, q0, F)

where

Q = {q_{0}, q_{1}, q_{2}, q_{3}}

âˆ‘ = {a, b}

Î“ = {a, b}

q_{0} = {q_{0}}

F = {q_{3}}

Î´ is given as follpws:

1. (q_{0}, a, Îµ) â†’ (q_{1}, a)

2. (q_{1}, a, a) â†’ (q_{1}, aa)

3. (q_{1}, b, a) â†’ (q_{2}, a)

4. (q_{2}, b, a) â†’ (q_{3}, Îµ)

5. (q_{3}, b, a) â†’ (q_{2}, a)

5. (q_{3}, Îµ, Îµ) â†’ (q_{4}, Îµ)

Check whether the string aabbbb is accpeted by the above pushdown automation.

2.

Consider a PDA,

P = (Q,âˆ‘, Î“, Î´, q0, F)

where

Q = {s, q, f}

âˆ‘ = {a, b}

Î“ = {a, b}

q_{0} = {s}

F = {f}

Î´ is given as follpws:

1. (s, a, Îµ) â†’ (s, a)

2. (s, b, Îµ) â†’ (s, b)

3. (s, Îµ, Îµ) â†’ (q, Îµ)

4. (q, a, a) â†’ (q, Îµ)

4. (q, b, b) â†’ (q, Îµ)

5. (q, Îµ, Îµ) â†’ (f, Îµ)

Check whether the string aabbaa is accepted by the above pushdown automation.

**8 Deterministic Pushdown Automata (DPDA)**

A PDA is said to be deterministic, if

1. Î´(q, a, b) contains at most one element, and

2. if Î´(q, Îµ, b) is not empty, then

Î´(q, c, b) must be empty for every input symbol, c.

For example, consider the following PDA,

**Example 1:**

Consider the PDA,

P = (Q,âˆ‘, Î“, Î´, q_{0}, F)

where

Q = {s, f}

âˆ‘ = {a, b, c}

Î“ = {a, b}

q_{0} = {s}

F = {f}

Î´ is given as follpws:

1. (s, a, Îµ) â†’ (s, a)

2. (s, b, Îµ) â†’ (s, b)

3. (s, c, Îµ) â†’ (f, Îµ)

4. (f, a, a) â†’ (f, Îµ)

5. (f, b, b) â†’ (f, Îµ)

Above is a deterministic pushdown automata (DPDA) because it satisfies both conditions of DPDA.

**Example 2:**

Consider the PDA,

P = (Q,âˆ‘, Î“, Î´, q_{0}, F)

where

Q = {s, f}

âˆ‘ = {a, b, c}

Î“ = {a, b}

q_{0} = {s}

F = {f}

Î´ is given as follpws:

1. (s, a, Îµ) â†’ (s, a)

2. (s, b, Îµ) â†’ (s, b)

3. (s, c, Îµ) â†’ (f, Îµ)

4. (f, a, a) â†’ (f, Îµ)

5. (f, b, b) â†’ (f, Îµ)

Above is a deterministic pushdown automata (DPDA) because it satisfies both conditions of DPDA.

**9 Non-Deterministic Pushdown Automata (NPDA)**

A PDA is said to be non- deterministic, if

1. Î´(q, a, b) may contain multiple elements, or

2. if Î´(q, Îµ, b) is not empty, then

Î´(q, c, b) is not empty for some input symbol, c.

**Example 1:**

Consider the following PDA,

P = (Q,âˆ‘, Î“, Î´, q_{0}, F)

where

Q = {q_{0}, q_{1}, q_{2}, q_{3}}

âˆ‘ = {a, b}

Î“ = {0, 1}

q_{0} = {q_{0}}

F = {q_{3}}

Î´ is given as follpws:

1. (q_{0}, a, 0) â†’ (q_{1}, 10), (q_{3}, Îµ)

2. (q_{0}, Îµ, 0) â†’ (q_{3}, Îµ)

3. (q_{1}, a, 1) â†’ (q_{1}, 11)

4. (q_{1}, b, 1) â†’ (q_{2}, Îµ)

5. (q_{2}, b, 1) â†’ (q_{2}, Îµ)

5. (q_{2}, Îµ, 0) â†’ (q_{3}, Îµ)

Above is a non deterministic pushdown automata (NPDA).

Consider the transition 1, ie.

1. (q_{0}, a, 0) â†’ (q_{1}, 10), (q_{3}, Îµ)

Here (q_{0}, a, 0) can go to q_{1} or q_{3}. That this transition is not deterministic.

**Example 2:**

Consider the following PDA,

P = (Q,âˆ‘, Î“, Î´, q0, F)

where

Q = {q0, qf }

âˆ‘= {a, b}

Î“ = {0, 1}

q_{0} = {q_{0}}

F = {q_{f} }

Î´ is given as follpws:

1. (q_{0}, Îµ, Îµ) â†’ (q_{f} , Îµ)

2. (q_{0}, a, Îµ) â†’ (q_{0}, 0)

3. (q_{0}, b, Îµ) â†’ (q_{0}, 1)

4. (q_{0}, a, 0) â†’ (q_{0}, 00)

5. (q_{0}, b, 0) â†’ (q_{0}, Îµ)

6. (q_{0}, a, 1) â†’ (q_{0}, Îµ)

7. (q_{0}, b, 1) â†’ (q_{0}, 11)

Above is a non deterministic pushdown automata (NPDA).

Consider the transitions, 1, 2 and 3.

1. (q_{0}, Îµ, Îµ) â†’ (q_{f} , Îµ)

2. (q_{0}, a, Îµ) â†’ (q_{0}, 0)

3. (q_{0}, b, Îµ) â†’ (q_{0}, 1)

Here (q_{0}, Îµ, Îµ) is not empty, also,

(q_{0}, a, Îµ) and (q_{0}, b, Îµ) are not empty.

**Example 3:**

Consider the following PDA,

P = (Q,âˆ‘, Î“, Î´, q0, F)

where

Q = {s, p, q}

âˆ‘ = {a, b}

Î“ = {a, b}

q_{0} = {s}

F = {q}

Î´ is given as follpws:

1. (s, a, Îµ) â†’ (p, a)

2. (p, a, a) â†’ (p, aa)

3. (p, a, Îµ) â†’ (p, a)

4. (p, b, a) â†’ (p, Îµ), (q, Îµ)

Above is a non deterministic pushdown automata (NPDA).

This is due to the transition,

4. (p, b, a) â†’ (p, Îµ), (q, Îµ)

**Example 4:**

Consider the following PDA,

P = (Q,P, Î“, Î´, q0, F)

where

Q = {q_{0}, q_{1}, q_{2}, q_{3}, f}

P = {a, b}

Î“ = {a, b}

q_{0} = {q_{0}}

F = {f}

Î´ is given as follpws:

1. (q_{0}, a, Îµ) â†’ (q_{1}, a)

2. (q_{1}, a, a) â†’ (q_{1}, a)

3. (q_{1}, b, a) â†’ (q_{2}, Îµ)

4. (q_{2}, b, a) â†’ (q_{3}, Îµ)

5. (q_{3}, b, a) â†’ (q_{2}, Îµ)

6. (q_{2}, Îµ, a) â†’ (q_{2}, Îµ)

7. (q_{2}, Îµ, Îµ) â†’ (f, Îµ)

8. (q_{1}, Îµ, a) â†’ (q_{1}, Îµ)

9. (q_{1}, Îµ, Îµ) â†’ (f, Îµ)

Above is a non deterministic pushdown automata (NPDA).

This is due to the transitions, 6 and 4, ie,

6. (q_{2}, Îµ, a) â†’ (q_{2}, Îµ)

4. (q_{2}, b, a) â†’ (q_{3}, Îµ)

Also due to the transitions, 8 and 2 and 3, ie,

8. (q_{1}, Îµ, a) â†’ (q_{1}, Îµ)

2. (q_{1}, a, a) â†’ (q_{1}, a)

3. (q1, b, a) â†’ (q2, Îµ)

**10 Design of Pushdown Automata**

For every CFG, there exists a pushdown automation that accepts it.

To design a pushdown automation corresponding to a CFG, following are the steps:

Step 1:

Let the start symbol of the CFG is S. Then a transition of PDA is,

Î´(p, Îµ, Îµ) â†’ (q, S)

Step 2:

For a production of the form, P â†’ AaB, a transition of PDA is,

Î´(q, Îµ, P) â†’ (q, AaB)

For a production of the form, P â†’ a, a transition of PDA is,

Î´(q, Îµ, P) â†’ (q, a)

For a production of the form, P â†’ Îµ, a transition of PDA is,

Î´(q, Îµ, P) â†’ (q, Îµ)

Step 3:

For every terminal symbol, a in CFG, a transition of PDA is,

Î´(q, a, a) â†’ (q, Îµ)

Thus the PDA is,

P = (Q,âˆ‘, Î“, Î´, q_{0}, F)

where

Q = {p, q}

âˆ‘ = set of terminal symbols in the CFG

Î“ =set of terminals and non-terminals in the CFG

q_{0} = p

F = q

Î´ is according to the above rules.

**Example 1:**

Consider the following CFG,

S â†’ aA

A â†’ aABC|bB|a

B â†’ b

C â†’ c

where S is the start symbol.

Design a pushdown automata corresponding to the above grammar.

Step 1:

Here start symbol of CFG is S. A transition is,

Î´(p, Îµ, Îµ) â†’ (q, S)

Step 3:

Consider the production, S â†’ aA.

A transition is

Î´(q, Îµ, S) â†’ (q, aA)

Consider the production, A â†’ aABC|bB|a.

Transitions are

Î´(q, Îµ, A) â†’ (q, aABC),

Î´(q, Îµ, A) â†’ (q, bB),

Î´(q, Îµ, A) â†’ (q, a).

Consider the production, B â†’ b.

Corresponding transition is

Î´(q, Îµ, B) â†’ (q, b)

Consider the production, C â†’ c

Corresponding transition is

Î´(q, Îµ, C) â†’ (q, c)

Step 3:

The terminal symbols in the CFG are, a, b, c.

Then the transitions are,

Î´(q, a, a) â†’ (q, Îµ)

Î´(q, b, b) â†’ (q, Îµ)

Î´(q, c, c) â†’ (q, Îµ)

Thus the PDA is,

P = (Q,âˆ‘, Î“, Î´, q0, F)

where

Q = {p, q}

âˆ‘ = {a, b, c}

Î“ = {S, A, B, C, a, b, c}

q0 = p

F = q

Î´ is given as follows:

Î´(p, Îµ, Îµ) â†’ (q, S)

Î´(q, Îµ, S) â†’ (q, aA)

Î´(q, Îµ, A) â†’ (q, aABC),

Î´(q, Îµ, A) â†’ (q, bB),

Î´(q, Îµ, A) â†’ (q, a).

Î´(q, Îµ, B) â†’ (q, b)

Î´(q, Îµ, C) â†’ (q, c)

Î´(q, a, a) â†’ (q, Îµ)

Î´(q, b, b) â†’ (q, Îµ)

Î´(q, c, c) â†’ (q, Îµ)

**Example 2:**

Consider the CFG,

S â†’ AB|BC

A â†’ aB|bA|a

B â†’ bB|cC|b

C â†’ c

where S is the start symbol.

Step 1:

Here start symbol of CFG is S. A transition is,

Î´(p, Îµ, Îµ) â†’ (q, S)

Step 3:

Consider the production, S â†’ AB|BC

Transitions are

Î´(q, Îµ, S) â†’ (q, AB)

Î´(q, Îµ, S) â†’ (q, BC

Consider the production, A â†’ aB|bA|a

Transitions are

Î´(q, Îµ, A) â†’ (q, aB),

Î´(q, Îµ, A) â†’ (q, bA),

Î´(q, Îµ, A) â†’ (q, a).

Consider the production, B â†’ bB|cC|b

Transitions are

Î´(q, Îµ, B) â†’ (q, bB)

Î´(q, Îµ, B) â†’ (q, cC),

Î´(q, Îµ, B) â†’ (q, b)

Consider the production, C â†’ c

Transitions are

Î´(q, Îµ, C) â†’ (q, c)

Step 3:

The terminal symbols in the CFG are, a, b, c.

Then the transitions are,

Î´(q, a, a) â†’ (q, Îµ)

Î´(q, b, b) â†’ (q, Îµ)

Î´(q, c, c) â†’ (q, Îµ)

Thus the PDA is,

P = (Q,âˆ‘, Î“, Î´, q_{0}, F)

where

Q = {p, q}

âˆ‘ = {a, b, c}

Î“ = {S, A, B, C, a, b, c}

q_{0} = p

F = q

Î´ is given as follows:

Î´(p, Îµ, Îµ) â†’ (q, S)

Î´(q, Îµ, S) â†’ (q, AB)

Î´(q, Îµ, S) â†’ (q, BC)

Î´(q, Îµ, A) â†’ (q, aB)

Î´(q, Îµ, A) â†’ (q, bA)

Î´(q, Îµ, A) â†’ (q, a)

Î´(q, Îµ, B) â†’ (q, bB)

Î´(q, Îµ, B) â†’ (q, cC)

Î´(q, Îµ, B) â†’ (q, b)

Î´(q, Îµ, C) â†’ (q, c)

Î´(q, a, a) â†’ (q, Îµ)

Î´(q, b, b) â†’ (q, Îµ)

Î´(q, c, c) â†’ (q, Îµ)

**Example 3:**

Design a pushdown automata that accepts the language, L = {wcwR|w âˆˆ (a, b)*}

We learned earlier that the CFG corresponding to this language is,

S â†’ aSa

S â†’ bSb

S â†’ c

where S is the start symbol.

Next we need to find the PDA corresponding to the above CFG.

Step 1:

Here start symbol of CFG is S. A transition is,

Î´(p, Îµ, Îµ) â†’ (q, S)

Step 3:

Consider the production, S â†’ aSa

Transitions are

Î´(q, Îµ, S) â†’ (q, aSa)

Consider the production, S â†’ bSb

Transitions are

Î´(q, Îµ, S) â†’ (q, bSb),

Consider the production, S â†’ c

Transitions are

Î´(q, Îµ, S) â†’ (q, c)

Step 3:

The terminal symbols in the CFG are, a, b, c.

Then the transitions are,

Î´(q, a, a) â†’ (q, Îµ)

Î´(q, b, b) â†’ (q, Îµ)

Î´(q, c, c) â†’ (q, Îµ)

Thus the PDA is,

P = (Q,âˆ‘, Î“, Î´, q_{0}, F)

where

Q = {p, q}

âˆ‘ = {a, b, c}

Î“ = {S, a, b, c}

q_{0 }= p

F = q

Î´ is given as follows:

Î´(p, Îµ, Îµ) â†’ (q, S)

Î´(q, Îµ, S) â†’ (q, aSa)

Î´(q, Îµ, S) â†’ (q, bSb)

Î´(q, Îµ, S) â†’ (q, c)

Î´(q, a, a) â†’ (q, Îµ)

Î´(q, b, b) â†’ (q, Îµ)

Î´(q, c, c) â†’ (q, Îµ)

**Example 4:**

Design a pushdown automata that accepts the language, L = {w|w contains equal number of aâ€™s and bâ€™s } from the input alphabet {a,b}.

First, we need to find the CFG corresponding to this language. We learned in a previous section, the CFG corresponding to this is,

S â†’ aSbS|bSaS|Îµ

where S is the start symbol.

Next we need to find the PDA corresponding to the above CFG.

Step 1:

Here start symbol of CFG is S. A transition is,

Î´(p, Îµ, Îµ) â†’ (q, S)

Step 3:

Consider the production, S â†’ aSbS|bSaS|Îµ

Transitions are

Î´(q, Îµ, S) â†’ (q, aSbS)

Î´(q, Îµ, S) â†’ (q, bSaS)

Î´(q, Îµ, S) â†’ (q, Îµ)

Step 3:

The terminal symbols in the CFG are, a, b.

Then the transitions are,

Î´(q, a, a) â†’ (q, Îµ)

Î´(q, b, b) â†’ (q, Îµ)

Thus the PDA is,

P = (Q,âˆ‘, Î“, Î´, q_{0}, F)

where

Q = {p, q}

âˆ‘= {a, b}

Î“ = {S, a, b}

q_{0} = p

F = q

Î´ is given as follows:

Î´(p, Îµ, Îµ) â†’ (q, S)

Î´(q, Îµ, S) â†’ (q, aSbS)

Î´(q, Îµ, S) â†’ (q, bSaS)

Î´(q, Îµ, S) â†’ (q, Îµ)

Î´(q, a, a) â†’ (q, Îµ)

Î´(q, b, b) â†’ (q, Îµ)

**Example 5:**

Design a pushdown automata that accepts the language corresponding to the regular expression, (a|b)*.

First, we need to find the CFG corresponding to this language. We learned in a previous section, the CFG corresponding

to this is,

S â†’ aS|bS|a|b|Îµ

where S is the start symbol.

Next we need to find the PDA corresponding to the above CFG.

Step 1:

Here start symbol of CFG is S. A transition is,

Î´(p, Îµ, Îµ) â†’ (q, S)

Step 3:

Consider the production, S â†’ aS|bS|a|b|Îµ

Transitions are

Î´(q, Îµ, S) â†’ (q, aS)

Î´(q, Îµ, S) â†’ (q, bS)

Î´(q, Îµ, S) â†’ (q, a)

Î´(q, Îµ, S) â†’ (q, b)

Î´(q, Îµ, S) â†’ (q, Îµ)

Step 3:

The terminal symbols in the CFG are, a, b.

Then the transitions are,

Î´(q, a, a) â†’ (q, Îµ)

Î´(q, b, b) â†’ (q, Îµ)

Thus the PDA is,

P = (Q,âˆ‘, Î“, Î´, q_{0}, F)

where

Q = {p, q}

âˆ‘ = {a, b}

Î“ = {S, a, b}

q_{0} = p

F = q

Î´ is given as follows:

Î´(p, Îµ, Îµ) â†’ (q, S)

Î´(q, Îµ, S) â†’ (q, aS)

Î´(q, Îµ, S) â†’ (q, bS)

Î´(q, Îµ, S) â†’ (q, a)

Î´(q, Îµ, S) â†’ (q, b)

Î´(q, Îµ, S) â†’ (q, Îµ)

Î´(q, a, a) â†’ (q, Îµ)

Î´(q, b, b) â†’ (q, Îµ)

Exercises:

1. Design a pushdown automation to accept the language, L = {wwR|w âˆˆ {a, b}*}.

2. Design a pushdown automation to accept the language, L = {a^{n}b^{n}|n > 0}.

3. Design a pushdown automation to accept the language, L = {a^{n}b^{2n}|n > 0}.

4. Design a pushdown automation for the regular expression, r = 0*1*.

5. Design a pushdown automation to accept the language, L = {a^{n}b^{n+1}|n = 1, 2, 3, ....}.

6. Design a pushdown automation to accept the language, L = {a^{n}b^{m}|n > m â‰¥ 0}.

7. Construct PDA equivalent to the grammar S â†’ aAA, A â†’ aS/bS/a.

8. Construct PDA for the language L = {x âˆˆ (a, b)*/na(x) > nb(n)}.

9. Construct a PDA that accepts the language L = {a^{n}ba^{m}/n, m â‰¥ 1} by empty stack.

**11 Applications of Pushdown Automata**

An application of PDA is in parsing.

Parsing is the process of checking whether the syntax of a program is correct or not. For example, a PDA can be

constructed to check the syntax of all C programs.

Also, parsing is the process of checking whether a sentence written in a natural language is correct or not.

Parsing is of two types,

Top down parsing, and

Bottom up parsing.

**Top Down Parsing**

An example for top down parsing is given below:

**Example 1:**

Consider the following CFG,

S â†’ aSb | ab

where S is the start symbol.

Check whether the syntax of string aabb is according to the above CFG.

Top down parsing is shown below:

Thus top down parsing is done beginning from the start symbol, by following a set of productions, reach the given string.

If the string cannot be reached, its syntax is not correct.

Above diagram is called a derivation tree (parse tree).

Here, by performing top down parsing , we got a^{2}b^{2}. So a^{2}b^{2} belongs to the above CFL.

**PDA for Top down Parsing**

A top down parser can be implemented by using a Pushdown automation. Using the pushdown automation, we can parse

a given string.

**Example 1:**

For example, the PDA corresponding to the CFG, S â†’ aSb | ab

is,

P = (Q,âˆ‘, Î“, Î´, q_{0}, F)

where

Q = {p, q}

âˆ‘= {a, b}

Î“ = {S, a, b}

q_{0} = p

F = q

Î´ is given as follows:

Î´(p, Îµ, Îµ) â†’ (q, S)

Î´(q, Îµ, S) â†’ (q, aSb)

Î´(q, Îµ, S) â†’ (q, ab)

Î´(q, a, a) â†’ (q, Îµ)

Î´(q, b, b) â†’ (q, Îµ)

This PDA acts as a top down parser for the CFL corresponding to above CFG.

**Bottom Up Parsing**

This approach can also be used to check whether a string belongs to a context free language. Here, the string w is taken

and an inverted tree is made. This is done by performing a number of reductions starting from the given string using the

productions of the grammar.**Example 1:**

Consider the grammar,

S â†’ aAS|a|SS

A â†’ SbA|ba

where S is the start symbol.

Check whether the string aabaa belongs to the CFL associated with the above grammar.

Bottom up parsing is shown below:

Above is a bottom up parse tree.

Thus by performing a number of reductions, we finally reached the start symbol. So the string aabaa belongs to the

above CFL.

This parsing process can be done using a PDA.

PDA for Bottom down Parsing

A top down parser can be implemented by using a Pushdown automation. Using this pushdown automation, we can parse

a given string.

**Example 1:**

Consider the grammar,

S â†’ aAS|a|SS

A â†’ SbA|ba

where S is the start symbol.

A pushdown automation for performing bottom up parsing is shown below:

P = (Q,âˆ‘, Î“, Î´, q_{0}, F)

where

Q = {p, q}

âˆ‘ = {a, b}

Î“ = {S, A, a, b}

q_{0} = p

F = q

Î´ is given as follows:

Î´(q, Îµ, S) â†’ (p, Îµ)

Î´(q, Îµ, SAa) â†’ (q, S)

Î´(q, Îµ, a) â†’ (q, S)

Î´(q, Îµ, SS) â†’ (q, S)

Î´(q, Îµ, AbS) â†’ (q, A)

Î´(q, Îµ, ab) â†’ (q, A)

Î´(q, a, Îµ) â†’ (q, a)

Î´(q, b, Îµ) â†’ (q, b)

This PDA acts as a bottom up parser for the CFL corresponding to above CFG.

Offer running on EduRev: __Apply code STAYHOME200__ to get INR 200 off on our premium plan EduRev Infinity!

36 videos|39 docs|39 tests

### Pushdown Automata - Introduction

- Video | 07:07 min
### PPT - Pushdown Automata (PDA)

- Doc | 37 pages
### Pumping Lemma for Context Free Languages (CFLs)

- Doc | 4 pages
### Pumping Lemma For Context Free Languages

- Video | 08:06 min
### PPT - Properties of Context-free Languages

- Doc | 62 pages
### PPT - Context-Free Languages & Grammars

- Doc | 40 pages

- Normal Forms for CFGs
- Doc | 7 pages
- Simplification of CFG (Reduction of CFG)
- Video | 13:57 min