Pushdown Automata Stack PDAs States 1 a , b c The States q 1 q - - PDF document

pushdown automata
SMART_READER_LITE
LIVE PREVIEW

Pushdown Automata Stack PDAs States 1 a , b c The States q 1 q - - PDF document

Review Languages and Grammars Alphabets, strings, languages Regular Languages CS 301 - Lecture 11 Deterministic Finite and Nondeterministic Automata Equivalence of NFA and DFA Nondeterministic Pushdown Regular Expressions


slide-1
SLIDE 1

1

CS 301 - Lecture 11 Nondeterministic Pushdown Automata

Fall 2008

Review

  • Languages and Grammars

– Alphabets, strings, languages

  • Regular Languages

– Deterministic Finite and Nondeterministic Automata – Equivalence of NFA and DFA – Regular Expressions – Regular Grammars – Properties of Regular Languages – Languages that are not regular and the pumping lemma

  • Context Free Languages

– Context Free Grammars – Derivations: leftmost, rightmost and derivation trees – Parsing and ambiguity – Simplifying Grammars and Normal Forms

  • Today:

– Nondeterministic Pushdown Automata

Pushdown Automata PDAs

Pushdown Automaton -- PDA

Input String Stack States

slide-2
SLIDE 2

2

The States

q1 q2 a, b → c

Input symbol Pop symbol Push symbol

q1 q2 a, b → c a   b

top input stack

a  

Replace

e h $ e h $ c q1 q2 a, λ → c a   a  

Push

b e h $ e h $ b c

top input stack

q1 q2 a, b → λ a   a  

Pop

b e h $ e h $

top input stack

slide-3
SLIDE 3

3

q1 q2 a, λ → λ a   a  

No Change

b e h $ e h $ b

top input stack

q1 q2 λ → $ , a a   a  

Pop

$

top input stack A Possible Transition empty

q1 q2 c b a → , a  

input A Bad Transition The automaton Halts in state and Rejects the input string Empty stack

q1

HALT

q1 q2 c a → λ , a  

input A Bad Transition The automaton Halts in state and Rejects the input string Empty stack

q1

HALT

slide-4
SLIDE 4

4

q1 q2 z y x → ,

No transition is allowed to be followed When the stack is empty Empty stack

q1 q2 b a → $ , a   a  

Pop

$

top input stack A Good Transition

b

Non-Determinism

q1 q2 a, b → c q3 a, b → c q1 q2 λ, b → c transition − λ

These are allowed transitions in a Non-deterministic PDA (NPDA)

NPDA: Non-Deterministic PDA

Example:

λ, λ → λ a, λ → a b, a → λ q0 q1 q2 q3 b, a → λ λ, $ → $

slide-5
SLIDE 5

5

a, λ → a b, a → λ

q

q1 q2 q3

Execution Example: Input

a a a b b b

current state

b, a → λ

Time 0

λ, λ → λ λ, $ → $

Stack

$ a, λ → a b, a → λ q0 q1 q2 q3

Input

a a a b b b b, a → λ

Time 1

λ, λ → λ λ, $ → $

Stack

$ a, λ → a b, a → λ q0 q1 q2 q3

Input Stack

a a a b b b $ a b, a → λ

Time 2

λ, λ → λ λ, $ → $ a, λ → a b, a → λ q0 q1 q2 q3

Input Stack

a a a b b b $ a a b, a → λ

Time 3

λ, λ → λ λ, $ → $

slide-6
SLIDE 6

6

a, λ → a b, a → λ q0 q1 q2 q3

Input Stack

a a a b b b $ a a a b, a → λ

Time 4

λ, λ → λ λ, $ → $ a, λ → a b, a → λ q0 q1 q2 q3

Input

a a a b b b

Stack

$ a a a b, a → λ

Time 5

λ, λ → λ λ, $ → $ a, λ → a b, a → λ q0 q1 q2 q3

Input

a a a b b b $ a

Stack

b, a → λ

Time 6

λ, λ → λ λ, $ → $ a a, λ → a b, a → λ q0 q1 q2 q3

Input

a a a b b b $

Stack

b, a → λ

Time 7

λ, λ → λ λ, $ → $ a

slide-7
SLIDE 7

7

a, λ → a b, a → λ q0 q1 q2 q3

Input

a a a b b b b, a → λ

Time 8 accept

λ, λ → λ λ, $ → $ $

Stack 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 The input string is accepted by the NPDA:

aaabbb

a, λ → a b, a → λ q0 q1 q2 q3 b, a → λ λ, λ → λ λ, $ → $

} : { ≥ = n b a L

n n is the language accepted by the NPDA:

a, λ → a b, a → λ q0 q1 q2 q3 b, a → λ

In general,

λ, λ → λ λ, $ → $

slide-8
SLIDE 8

8

Another NPDA example

λ, $ → $ q1 q2 b b a a → → λ λ , , λ, λ → λ q0 λ λ → → b b a a , ,

NPDA M

} { ) (

R

ww M L =

Execution Example: Input Time 0 Stack

$ λ, $ → $ q1 q2 b b a a → → λ λ , , λ, λ → λ q0 λ λ → → b b a a , , a a b b

Input

a a b

Time 1 Stack

$ λ, $ → $ q1 q2 b b a a → → λ λ , , λ, λ → λ q0 λ λ → → b b a a , , a b

Input Time 2 Stack

$ λ, $ → $ q1 q2 b b a a → → λ λ , , λ, λ → λ q0 λ λ → → b b a a , , a a a b b b

slide-9
SLIDE 9

9

Input Time 3 Stack

$ λ, $ → $ q1 q2 b b a a → → λ λ , , λ, λ → λ q0 λ λ → → b b a a , , a a a b b b

Guess the middle

  • f string

Input Time 4 Stack

$ λ, $ → $ q1 q2 b b a a → → λ λ , , λ, λ → λ q0 λ λ → → b b a a , , a a a b b b

Input Time 5 Stack

$ λ, $ → $

1

q

q2 b b a a → → λ λ , , λ, λ → λ q0 λ λ → → b b a a , , a a b b a

Input Time 6 Stack

$ λ, $ → $ q1 b b a a → → λ λ , , λ, λ → λ q0 λ λ → → b b a a , , a a b b

accept

q2

slide-10
SLIDE 10

10

Rejection Example: Input Time 0 Stack

$ λ, $ → $ q1 q2 b b a a → → λ λ , , λ, λ → λ q0 λ λ → → b b a a , , a b b b

Input Time 1 Stack

$ λ, $ → $ q1 q2 b b a a → → λ λ , , λ, λ → λ q0 λ λ → → b b a a , , a a b b b

Input Time 2 Stack

$ λ, $ → $ q1 q2 b b a a → → λ λ , , λ, λ → λ q0 λ λ → → b b a a , , a b a b b b

Input Time 3 Stack

$ λ, $ → $ q1 q2 b b a a → → λ λ , , λ, λ → λ q0 λ λ → → b b a a , , a b

Guess the middle

  • f string

a b b b

slide-11
SLIDE 11

11

Input Time 4 Stack

$ λ, $ → $ q1 q2 b b a a → → λ λ , , λ, λ → λ q0 λ λ → → b b a a , , a b a b b b

Input Time 5 Stack

$ λ, $ → $

1

q

q2 b b a a → → λ λ , , λ, λ → λ q0 λ λ → → b b a a , , a a b b b

There is no possible transition. Input is not consumed Another computation on same string: Input Time 0 Stack

$ λ, $ → $ q1 q2 b b a a → → λ λ , , λ, λ → λ q0 λ λ → → b b a a , , a b b b

Input Time 1 Stack

$ λ, $ → $ q1 q2 b b a a → → λ λ , , λ, λ → λ q0 λ λ → → b b a a , , a a b b b

slide-12
SLIDE 12

12

Input Time 2 Stack

$ λ, $ → $ q1 q2 b b a a → → λ λ , , λ, λ → λ q0 λ λ → → b b a a , , a b a b b b

Input Time 3 Stack

$ a b a b b b λ, $ → $ q1 q2 b b a a → → λ λ , , λ, λ → λ q0 λ λ → → b b a a , , b

Input Time 4 Stack

a b b b λ, $ → $ q1 q2 b b a a → → λ λ , , λ, λ → λ q0 λ λ → → b b a a , , $ a b b b

Input Time 5 Stack

a b b b $ a b b b λ, $ → $ q1 q2 b b a a → → λ λ , , λ, λ → λ q0 λ λ → → b b a a , ,

No final state is reached

slide-13
SLIDE 13

13

λ, $ → $ q1 q2 b b a a → → λ λ , , λ, λ → λ q0 λ λ → → b b a a , ,

There is no computation that accepts string abbb

) (M L abbb∉

A string is rejected if there is no 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 In other words, 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

Another NPDA example

q0

NPDA M

} 1 : { ) ( − ≥ = m n b a M L

m n

λ λ λ → → → $ , , , b a b a a

This NPDA generates: and for each substring u

slide-14
SLIDE 14

14

Execution Example: Input Time 0 Stack

a a

b

λ λ λ → → → $ , , , b a b a a

q0 $

Input Time 1 Stack

a a

b

q0 a $

λ λ λ → → → $ , , , b a b a a Input Time 2 Stack

a a

b

q0 a a $

λ λ λ → → → $ , , , b a b a a Input Time 3 Stack

a a

b

q0 a

accept

$

λ λ λ → → → $ , , , b a b a a

slide-15
SLIDE 15

15

Rejection example: Input Time 0 Stack

a

b

b

q0

b

$

Input Time 1 Stack

q0 a a

b

b b

$

λ λ λ → → → $ , , , b a b a a Input Time 2 Stack

q0 a

b

b b

$

λ λ λ → → → $ , , , b a b a a Input Time 3 Stack

q0 a

b

b b

λ λ λ → → → $ , , , b a b a a

slide-16
SLIDE 16

16

Input Time 4 Stack

q0

Halt and Reject

a

b

b b

λ λ λ → → → $ , , , b a b a a

Pushing Strings

q1 q2 a, b → w

Input symbol Pop symbol Push string

q1 q2 a, b → cdf a   b

top input stack

a  

Push

e h h e c d f

pushed string Example:

$ $

What’s Next

  • Read

– Linz Chapter 1,2.1, 2.2, 2.3, (skip 2.4), 3, 4, 5, 6.1, 6.2, (skip 6.3), 7.1, and 7.2 – JFLAP Chapter 1, 2.1, (skip 2.2), 3, 4, 5, 6, 7

  • Next Lecture Topics from Chapter 7.2

– Pushdown Automata and Context Free Grammars

  • Quiz 2 in Recitation on Wednesday 10/1

– Covers Linz 3, 4 and JFLAP 3, 4 – Closed book, but you may bring one sheet of 8.5 x 11 inch paper with any notes you like. – Quiz will take the full hour

  • Homework

– Homework Due Thursday