1 of 42

Session 1: �Pushdown Automata- Definitions – Moves-Deterministic pushdown automata

By

Dr. Ashok Kumar

Amity School of Engineering & Technology

2 of 42

Pushdown Automaton -- PDA

2

Input String

Stack

States

Amity School of Engineering & Technology

3 of 42

3

Initial Stack Symbol

Stack

Stack

bottom

special symbol

stack

head

top

Amity School of Engineering & Technology

4 of 42

The States

4

Input

symbol

Pop

symbol

Push

symbol

Alternatively

Amity School of Engineering & Technology

5 of 42

5

top

input

stack

Replace

Amity School of Engineering & Technology

6 of 42

6

Push

top

input

stack

Amity School of Engineering & Technology

7 of 42

7

Pop

top

input

stack

Amity School of Engineering & Technology

8 of 42

8

No Change

top

input

stack

Amity School of Engineering & Technology

9 of 42

9

Pop

top

input

stack

A Possible Transition

empty

Amity School of Engineering & Technology

10 of 42

10

input

A Bad Transition

The automaton Halts in state

and Rejects the input string

Empty stack

HALT

Amity School of Engineering & Technology

11 of 42

11

input

A Bad Transition

The automaton Halts in state

and Rejects the input string

Empty stack

HALT

Amity School of Engineering & Technology

12 of 42

12

No transition is allowed to be followed

When the stack is empty

Empty stack

Amity School of Engineering & Technology

13 of 42

13

Pop

top

input

stack

A Good Transition

Amity School of Engineering & Technology

14 of 42

A Pushdown automata PDA M can be defined as 7 Tuples

Amity School of Engineering & Technology

15 of 42

Amity School of Engineering & Technology

16 of 42

Non-Determinism

16

These are allowed transitions in a

Non-deterministic PDA (NPDA)

Amity School of Engineering & Technology

17 of 42

17

Transition function:

Amity School of Engineering & Technology

18 of 42

18

Transition function:

Amity School of Engineering & Technology

19 of 42

Difference between NPDA and DPDA�

Amity School of Engineering & Technology

20 of 42

Amity School of Engineering & Technology

21 of 42

21

A string is accepted if there is

a computation such that:

All the input is consumed

AND

The last state is a final state

At the end of the computation,

we do not care about the stack contents

Amity School of Engineering & Technology

22 of 42

22

A string is rejected if in every

computation with this string:

The input cannot be consumed

OR

The input is consumed and the last state is not a final state

OR

The stack head moves below the bottom of the stack

Amity School of Engineering & Technology

23 of 42

23

Example: Design PDA for the language

Amity School of Engineering & Technology

24 of 42

24

Execution Example:

Input

current

state

Time 0

Stack

Amity School of Engineering & Technology

25 of 42

25

Input

Time 1

Stack

Amity School of Engineering & Technology

26 of 42

26

Input

Stack

Time 2

Amity School of Engineering & Technology

27 of 42

27

Input

Stack

Time 3

Amity School of Engineering & Technology

28 of 42

28

Input

Stack

Time 4

Amity School of Engineering & Technology

29 of 42

29

Input

Stack

Time 5

Amity School of Engineering & Technology

30 of 42

30

Input

Stack

Time 6

Amity School of Engineering & Technology

31 of 42

31

Input

Stack

Time 7

Amity School of Engineering & Technology

32 of 42

32

Input

Time 8

accept

Stack

Amity School of Engineering & Technology

33 of 42

33

The input string

is accepted by the NPDA:

Amity School of Engineering & Technology

34 of 42

Another example

34

NPDA

Amity School of Engineering & Technology

35 of 42

Pushing Strings

35

Input

symbol

Pop

symbol

Push

string

Amity School of Engineering & Technology

36 of 42

36

top

input

stack

Push

pushed

string

Example:

Amity School of Engineering & Technology

37 of 42

Problems

# 4:

Design a NPDA to accept the following Language:

L(M) = { anb2n , n ≥ 0 }

37

Amity School of Engineering & Technology

38 of 42

38

q3

q1

q4

q2

λ,λ 🡪 λ

a,λ 🡪 00

b,0 🡪 λ

b,0 🡪 λ

λ,$ 🡪$

a

a

b

b

b

b

$

Stack

Input String

Time - 0

Amity School of Engineering & Technology

39 of 42

Problems

# 5:

Design a NPDA to accept the following Language:

L(M) = { wcwR, w∈{a,b}* }

39

Amity School of Engineering & Technology

40 of 42

L(M) = { wcwR, w∈{a,b}* }

40

Amity School of Engineering & Technology

41 of 42

# 6:

Design a NPDA to accept the following Language:

L(M) = { anbn+mcm , n ≥0, m≥1 }

41

Amity School of Engineering & Technology

42 of 42

42

q2

q1

b,0 🡪λ

b,0 🡪 λ

a, λ 🡪 0

q3

a

a

b

b

b

c

Input String

$

Stack

Time 0

b,$ 🡪 0$

b, λ 🡪 0

q4

c,0 🡪 λ

c,0 🡪 λ

q5

λ,$ 🡪 $

Amity School of Engineering & Technology