1 of 90

Pushdown Automata�PDAs

1

2 of 90

Pushdown Automaton -- PDA

2

Input String

Stack

States

3 of 90

3

Initial Stack Symbol

Stack

Stack

bottom

special symbol

stack

head

top

Appears at time 0

4 of 90

The States

4

Input

symbol

Pop

symbol

Push

symbol

5 of 90

5

top

input

stack

Replace

6 of 90

6

Push

top

input

stack

7 of 90

7

Pop

top

input

stack

8 of 90

8

No Change

top

input

stack

9 of 90

9

Pop

top

input

stack

Empty Stack

empty

The automaton HALTS

No possible transition after

10 of 90

10

Pop

top

input

stack

A Possible Transition

11 of 90

Non-Determinism

11

PDAs are non-deterministic

Allowed non-deterministic transitions

12 of 90

Example PDA

12

PDA

13 of 90

13

Basic Idea:

  1. Push the a’s

on the stack

2. Match the b’s on input

with a’s on stack

3. Match

found

14 of 90

14

Execution Example:

Input

current

state

Time 0

Stack

15 of 90

15

Input

Time 1

Stack

16 of 90

16

Input

Stack

Time 2

17 of 90

17

Input

Stack

Time 3

18 of 90

18

Input

Stack

Time 4

19 of 90

19

Input

Stack

Time 5

20 of 90

20

Input

Stack

Time 6

21 of 90

21

Input

Stack

Time 7

22 of 90

22

Input

Time 8

accept

Stack

23 of 90

23

A string is accepted if there is

a computation such that:

All the input is consumed

AND

The last state is an accepting state

At the end of the computation,

we do not care about the stack contents

(the stack can be empty at the last state)

24 of 90

24

The input string

is accepted by the PDA:

25 of 90

25

is the language accepted by the PDA:

In general,

26 of 90

26

Rejection Example:

Input

current

state

Time 0

Stack

27 of 90

27

Rejection Example:

Input

current

state

Time 1

Stack

28 of 90

28

Rejection Example:

Input

current

state

Time 2

Stack

29 of 90

29

Rejection Example:

Input

current

state

Time 3

Stack

30 of 90

30

Rejection Example:

Input

current

state

Time 4

Stack

31 of 90

31

Rejection Example:

Input

current

state

Time 4

Stack

reject

32 of 90

32

The input string

is rejected by the PDA:

33 of 90

33

A string is rejected if there is

no computation such that:

All the input is consumed

AND

The last state is an accept state

At the end of the computation,

we do not care about the stack contents

34 of 90

Another PDA example

34

PDA

35 of 90

35

Basic Idea:

  1. Push v

on stack

2. Guess

middle

of input

3. Match on input

with v on stack

4. Match

found

36 of 90

36

Execution Example:

Input

Time 0

Stack

37 of 90

37

Input

Time 1

Stack

38 of 90

38

Input

Time 2

Stack

39 of 90

39

Input

Time 3

Stack

Guess the middle

of string

40 of 90

40

Input

Time 4

Stack

41 of 90

41

Input

Time 5

Stack

42 of 90

42

Input

Time 6

Stack

accept

43 of 90

43

Rejection Example:

Input

Time 0

Stack

44 of 90

44

Input

Time 1

Stack

45 of 90

45

Input

Time 2

Stack

46 of 90

46

Input

Time 3

Stack

Guess the middle

of string

47 of 90

47

Input

Time 4

Stack

48 of 90

48

Input

Time 5

Stack

There is no possible transition.

Input is not consumed

49 of 90

49

Another computation on same string:

Input

Time 0

Stack

50 of 90

50

Input

Time 1

Stack

51 of 90

51

Input

Time 2

Stack

52 of 90

52

Input

Time 3

Stack

53 of 90

53

Input

Time 4

Stack

54 of 90

54

Input

Time 5

Stack

No final state

is reached

55 of 90

55

There is no computation

that accepts string

56 of 90

Another PDA example

56

PDA

57 of 90

57

Execution Example:

Input

Time 0

Stack

58 of 90

58

Input

Time 1

Stack

59 of 90

59

Input

Time 2

Stack

60 of 90

60

Input

Time 3

Stack

accept

61 of 90

61

Rejection example:

Input

Time 0

Stack

62 of 90

62

Input

Time 1

Stack

63 of 90

63

Input

Time 2

Stack

64 of 90

64

Input

Time 3

Stack

65 of 90

65

Input

Time 4

Stack

Halt and Reject

66 of 90

Pushing Strings

66

Input

symbol

Pop

symbol

Push

string

67 of 90

67

top

input

stack

Push

pushed

string

Example:

68 of 90

Another PDA example

68

PDA

69 of 90

69

Time 0

Input

current

state

Stack

Execution Example:

70 of 90

70

Time 1

Input

Stack

71 of 90

71

Time 3

Input

Stack

72 of 90

72

Time 4

Input

Stack

73 of 90

73

Time 5

Input

Stack

74 of 90

74

Time 6

Input

Stack

75 of 90

75

Time 7

Input

Stack

76 of 90

76

Time 8

Input

Stack

accept

77 of 90

Formalities for PDAs

77

78 of 90

78

Transition function:

79 of 90

79

Transition function:

80 of 90

Formal Definition

80

Pushdown Automaton (PDA)

States

Input

alphabet

Stack

alphabet

Transition

function

Final

states

Stack

start

symbol

Initial

state

81 of 90

Instantaneous Description

81

Current

state

Remaining

input

Current

stack

contents

82 of 90

82

Input

Stack

Time 4:

Example:

Instantaneous Description

83 of 90

83

Input

Stack

Time 5:

Example:

Instantaneous Description

84 of 90

84

We write:

Time 4

Time 5

85 of 90

85

A computation:

86 of 90

86

For convenience we write:

87 of 90

Formal Definition

87

Language of PDA :

Initial state

Final state

88 of 90

88

Example:

PDA :

89 of 90

89

PDA :

90 of 90

90

PDA :

Therefore: