pushdown automata n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
PushDown Automata PowerPoint Presentation
Download Presentation
PushDown Automata

Loading in 2 Seconds...

play fullscreen
1 / 56

PushDown Automata - PowerPoint PPT Presentation


  • 361 Views
  • Uploaded on

PushDown Automata. What is a stack?. A stack is a Last In First Out data structure where I only have access to the last element inserted in the stack. In order to access other elements I have to remove those that are on top one by one. Stack. Stack. Stack. Stack. Stack. Stack. Stack.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'PushDown Automata' - arleen


Download Now An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
what is a stack
What is a stack?
  • A stack is a Last In First Out data structure where I only have access to the last element inserted in the stack.
  • In order to access other elements I have to remove those that are on top one by one.
what is a pda
What is a PDA?
  • A PDA is en enhanced finite automaton that also contains an infinite stack.
  • The transitions in a PDA are of the form

a, x ⟶ y

meaning that if you see an a in the input string and the stack contains the symbol x on top then you remove the x and add a y.

  • The stack gives us extra power to recognize non-regular languages.
transitions
Transitions
  • Transitions of the form a, x ⟶ y require that the next input symbol should be a and the top stack symbol should be x.

a, x⟶ y

a, x⟶ y

q’

q

q’

q

x

w

y

w

...abb...

...abb...

Stack Input

Stack Input

transitions1
Transitions
  • Transitions of the form ε, x ⟶ y require that the top stack symbol is x.

ε, x⟶ y

ε, x⟶ y

q’

q

q’

q

x

w

y

w

...abb...

...abb...

Stack Input

Stack Input

transitions2
Transitions
  • Transitions of the form a, ε⟶ y require that the next input symbol is a.

a, ε ⟶ y

a, ε ⟶ y

q’

q

q’

q

x

w

y

x

w

...abb...

...abb...

Stack Input

Stack Input

transitions3
Transitions
  • Transitions of the form ε, ε⟶ ycan be followed without restrictions.

ε, ε ⟶ y

ε, ε ⟶ y

q’

q

q’

q

x

w

y

x

w

...abb...

...abb...

Stack Input

Stack Input

pda accept reject status
PDA Accept – Reject Status
  • The PDA accepts when there exists a computation path such that:
    • The computation path ends in an accept state
    • All the input is consumed
    • (no requirement for the stack)
  • The PDA rejects when all the paths:
    • Either end in a non-accepting state
    • Or are incomplete (meaning that at some point there is no possible transition under the current input and stack symbols)
a pda for a n b n n 0
A PDA for {anbn : n ≥ 0}
  • We usually use the stack for counting.
  • For this language for example, you first insert all the as in the stack until you start seeing bs .
  • When you see the first b start removing as from the stack.
  • When you have consumed the whole string you check the stack: if it’s empty then this means that the number of as equals the number of bs.
is the stack empty
Is the stack empty?

How can you check if the stack is empty?

  • What we usually do is to place a special symbol (for example a $) at the bottom of the stack.
  • Whenever we find the $ again we know that we reached the end of the stack.
  • In order to accept a string there is no need for the stack to be empty.
a pda for a n b n n 01
A PDA for {anbn : n ≥ 0}

a, ε ⟶ a

ε, ε ⟶ $

q0

q1

b, a⟶ ε

ε, $ ⟶ ε

q3

q2

b, a⟶ ε

visualization of a n b n n 0
Visualization of {anbn:n ≥ 0}

aaabbb

a, ε ⟶ a

ε, ε ⟶ $

q0

q1

b, a⟶ ε

ε, $ ⟶ ε

q3

q2

b, a⟶ ε

visualization of a n b n n 01
Visualization of {anbn:n ≥ 0}

aaabbb

a, ε ⟶ a

$

ε, ε ⟶ $

q0

q1

b, a⟶ ε

ε, $ ⟶ ε

q3

q2

b, a⟶ ε

visualization of a n b n n 02
Visualization of {anbn:n ≥ 0}

aaabbb

a, ε ⟶ a

a

$

ε, ε ⟶ $

q0

q1

b, a⟶ ε

ε, $ ⟶ ε

q3

q2

b, a⟶ ε

visualization of a n b n n 03
Visualization of {anbn:n ≥ 0}

aaabbb

a, ε ⟶ a

a

a

$

ε, ε ⟶ $

q0

q1

b, a⟶ ε

ε, $ ⟶ ε

q3

q2

b, a⟶ ε

visualization of a n b n n 04
Visualization of {anbn:n ≥ 0}

aaabbb

a, ε ⟶ a

a

a

a

$

ε, ε ⟶ $

q0

q1

b, a⟶ ε

ε, $ ⟶ ε

q3

q2

b, a⟶ ε

visualization of a n b n n 05
Visualization of {anbn:n ≥ 0}

aaabbb

a, ε ⟶ a

a

a

$

ε, ε ⟶ $

q0

q1

b, a⟶ ε

ε, $ ⟶ ε

q3

q2

b, a⟶ ε

visualization of a n b n n 06
Visualization of {anbn:n ≥ 0}

aaabbb

a, ε ⟶ a

a

$

ε, ε ⟶ $

q0

q1

b, a⟶ ε

ε, $ ⟶ ε

q3

q2

b, a⟶ ε

visualization of a n b n n 07
Visualization of {anbn:n ≥ 0}

aaabbb

a, ε ⟶ a

$

ε, ε ⟶ $

q0

q1

b, a⟶ ε

ε, $ ⟶ ε

q3

q2

b, a⟶ ε

visualization of a n b n n 08
Visualization of {anbn:n ≥ 0}

aaabbb

a, ε ⟶ a

ε, ε ⟶ $

q0

q1

b, a⟶ ε

ε, $ ⟶ ε

q3

q2

b, a⟶ ε

visualization of a n b n n 09
Visualization of {anbn:n ≥ 0}

aab

a, ε ⟶ a

ε, ε ⟶ $

q0

q1

b, a⟶ ε

ε, $ ⟶ ε

q3

q2

b, a⟶ ε

visualization of a n b n n 010
Visualization of {anbn:n ≥ 0}

aab

a, ε ⟶ a

$

ε, ε ⟶ $

q0

q1

b, a⟶ ε

ε, $ ⟶ ε

q3

q2

b, a⟶ ε

visualization of a n b n n 011
Visualization of {anbn:n ≥ 0}

aab

a, ε ⟶ a

a

$

ε, ε ⟶ $

q0

q1

b, a⟶ ε

ε, $ ⟶ ε

q3

q2

b, a⟶ ε

visualization of a n b n n 012
Visualization of {anbn:n ≥ 0}

aab

a, ε ⟶ a

a

a

$

ε, ε ⟶ $

q0

q1

b, a⟶ ε

ε, $ ⟶ ε

q3

q2

b, a⟶ ε

visualization of a n b n n 013
Visualization of {anbn:n ≥ 0}

aab

a, ε ⟶ a

a

$

ε, ε ⟶ $

q0

q1

b, a⟶ ε

ε, $ ⟶ ε

q3

q2

b, a⟶ ε

visualization of a n b n n 014
Visualization of {anbn:n ≥ 0}

aab

a, ε ⟶ a

a

$

ε, ε ⟶ $

q0

q1

b, a⟶ ε

ε, $ ⟶ ε

q3

q2

b, a⟶ ε

visualization of a n b n n 015
Visualization of {anbn:n ≥ 0}

abb

a, ε ⟶ a

ε, ε ⟶ $

q0

q1

b, a⟶ ε

ε, $ ⟶ ε

q3

q2

b, a⟶ ε

visualization of a n b n n 016
Visualization of {anbn:n ≥ 0}

abb

a, ε ⟶ a

$

ε, ε ⟶ $

q0

q1

b, a⟶ ε

ε, $ ⟶ ε

q3

q2

b, a⟶ ε

visualization of a n b n n 017
Visualization of {anbn:n ≥ 0}

abb

a, ε ⟶ a

a

$

ε, ε ⟶ $

q0

q1

b, a⟶ ε

ε, $ ⟶ ε

q3

q2

b, a⟶ ε

visualization of a n b n n 018
Visualization of {anbn:n ≥ 0}

abb

a, ε ⟶ a

$

ε, ε ⟶ $

q0

q1

b, a⟶ ε

ε, $ ⟶ ε

q3

q2

b, a⟶ ε

visualization of a n b n n 019
Visualization of {anbn:n ≥ 0}

abb

a, ε ⟶ a

$

ε, ε ⟶ $

q0

q1

b, a⟶ ε

ε, $ ⟶ ε

q3

q2

b, a⟶ ε

pda formally
PDA formally
  • A PDA is a sextuple (Q, Σ, Γ, δ, q0, F), where:
    • Q is the set of states
    • Σ is the input alphabet
    • Γ is the alphabet for the stack
    • δ is the transition function
    • q0 is the start state
    • F is the set of accepting states

About Γ: The stack alphabet can contain any symbol you want. It can be completely disjoint from Σ.

l proper opening and closing parenthesis
L() : proper opening and closing parenthesis

ε, ε ⟶ $

(, ε ⟶ *

q0

q1

), *⟶ ε

ε, $ ⟶ ε

try it yourself
Try it yourself
  • Create a PDA for the language:

L= = {w : w contains an equal number of 0s and 1s}

l equal number of 0s and 1s
L= : equal number of 0s and 1s

0, ε ⟶ *

1, *⟶ ε

q2

ε, $ ⟶ ε

0, ε ⟶ *

ε, ε ⟶ $

q0

q1

1, ε ⟶ *

ε, $ ⟶ ε

1, ε ⟶ *

0, *⟶ ε

q3

l equal number of 0s and 1s1
L= : equal number of 0s and 1s

NPDA for this language

ε, ε ⟶ $

0, ε ⟶ 0

0, 1⟶ ε

1, ε ⟶ 1

1, 0 ⟶ ε

q0

q1

ε, $ ⟶ ε

pda and regular languages
PDA and Regular Languages
  • Regular languages can be recognized by PDA:
    • For every regular language there is an NFAεrecognizing it.
    • Simply add ε⟶ε in every transition for the stack (i.e just don’t use it at all).
  • The languages recognized by PDA is a superset of regular languages.
    • As we saw the language L = {anbn : n≥0} is recognized by some PDA.
    • L is not regular.
non determinism
Non-Determinism
  • Non- determinism means that we can have more than one choices.
  • Non-Deterministic:

q2

0, a⟶ 1

q1

0, a⟶ 1

q3

non determinism1
Non-Determinism
  • Non- determinism means that we can have more than one choices.
  • Non-Deterministic:

q2

0, a⟶ 0

q1

0, a⟶ 1

q3

non determinism2
Non-Determinism
  • Non- determinism means that we can have more than one choices.
  • Non-Deterministic:

0, a⟶ 0

0, a⟶ 1

q1

q2

non determinism3
Non-Determinism
  • Non- determinism means that we can have more than one choices.
  • Non-Deterministic:

q2

0, ε⟶ 0

q1

0, a⟶ 1

q3

non determinism4
Non-Determinism
  • Non- determinism means that we can have more than one choices.
  • Non-Deterministic:

q2

ε, b⟶ 0

q1

0, b⟶ 1

q3

non determinism5
Non-Determinism
  • Non- determinism means that we can have more than one choices.
  • Deterministic:

q2

0, b⟶ 0

q1

0, a⟶ 1

q3

non determinism6
Non-Determinism
  • Non- determinism means that we can have more than one choices.
  • Deterministic:

ε, ε ⟶ 0

q1

q2

No other possible transitions

dpda vs npda
DPDA vs NPDA
  • Although non-deterministic and deterministic FA are equivalent this is not the case with PDA. Non-determinism helps us recognize more languages.
  • Intuition:

LR = { wwR : w in {0,1}* }

An NPDA for this language pushes the first half of the string in the stack and pops the second half.

It has to guess where the middle of the string is.

l r w w r w in 0 1
L#R = { w#wR : w in {0,1}* }

0, ε ⟶ 0

1, ε ⟶ 1

ε, ε ⟶ $

q0

q1

#, ε ⟶ ε

ε, $ ⟶ ε

q3

q2

0, 0 ⟶ ε

1, 1 ⟶ ε

l r ww r w in 0 1
LR = { wwR : w in {0,1}* }
  • Compare the previous DPDA with this NPDA

0, ε ⟶ 0

1, ε ⟶ 1

ε, ε ⟶ $

q0

q1

ε, ε ⟶ ε

ε, $ ⟶ ε

q3

q2

0, 0 ⟶ ε

1, 1 ⟶ ε

npda and cf languages
NPDA and CF languages
  • It can be shown that non-deterministic PDA are equivalent with context free grammars.
  • NPDA accept exactly the set of CF languages.
  • In order to prove that a language is CF you can
    • Construct a CF grammar that generates it
    • Construct a NPDA that recognizes it.