176
Computational Models - Lecture 4 Push Down Automata (PDA) Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.1

Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

  • Upload
    doanbao

  • View
    233

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Computational Models - Lecture 4

Push Down Automata (PDA)

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.1

Page 2: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Computational Models - Lecture 4

Push Down Automata (PDA)

Nondeterminismadds powerto PDAs

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.1

Page 3: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Computational Models - Lecture 4

Push Down Automata (PDA)

Nondeterminismadds powerto PDAs

Equivalenceof CFGs and PDAs

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.1

Page 4: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Computational Models - Lecture 4

Push Down Automata (PDA)

Nondeterminismadds powerto PDAs

Equivalenceof CFGs and PDAs

Pumping Lemmafor context free languages

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.1

Page 5: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Computational Models - Lecture 4

Push Down Automata (PDA)

Nondeterminismadds powerto PDAs

Equivalenceof CFGs and PDAs

Pumping Lemmafor context free languages

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.1

Page 6: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Computational Models - Lecture 4

Push Down Automata (PDA)

Nondeterminismadds powerto PDAs

Equivalenceof CFGs and PDAs

Pumping Lemmafor context free languages

Sipser’s book, 2.2 & 2.3

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.1

Page 7: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

even if youcan’t hear me

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.2

Page 8: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

even if youcan’t hear me

There will be a mid-termexam on Friday, Dec. 3

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.2

Page 9: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

even if youcan’t hear me

There will be a mid-termexam on Friday, Dec. 3Material includes first five lectures

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.2

Page 10: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

even if youcan’t hear me

There will be a mid-termexam on Friday, Dec. 3Material includes first five lectures

Can use4 pages, double sided, any size font youcan read, and also your heads (optionally)

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.2

Page 11: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

String Generators and String Acceptors

Regular expressions arestring generators– theytell us how to generate all strings in a languageL

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.3

Page 12: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

String Generators and String Acceptors

Regular expressions arestring generators– theytell us how to generate all strings in a languageL

Finite Automata (DFA, NFA) arestring acceptors– they tell us if a specific stringw is inL

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.3

Page 13: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

String Generators and String Acceptors

Regular expressions arestring generators– theytell us how to generate all strings in a languageL

Finite Automata (DFA, NFA) arestring acceptors– they tell us if a specific stringw is inL

CFGs arestring generators

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.3

Page 14: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

String Generators and String Acceptors

Regular expressions arestring generators– theytell us how to generate all strings in a languageL

Finite Automata (DFA, NFA) arestring acceptors– they tell us if a specific stringw is inL

CFGs arestring generators

Are therestring acceptors forContext-Freelanguages?

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.3

Page 15: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

String Generators and String Acceptors

Regular expressions arestring generators– theytell us how to generate all strings in a languageL

Finite Automata (DFA, NFA) arestring acceptors– they tell us if a specific stringw is inL

CFGs arestring generators

Are therestring acceptors forContext-Freelanguages?

YES! Push-down automata

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.3

Page 16: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

A Finite Automaton

011011001

read unread

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.4

Page 17: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

A PushDown Automaton

01101

read unread

pop

push

10

abba

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.5

Page 18: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

An Example

Recall that the language{0n1n | n ≥ 0} is not regular.Consider the following PDA:

Read input symbols

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.6

Page 19: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

An Example

Recall that the language{0n1n | n ≥ 0} is not regular.Consider the following PDA:

Read input symbols

For each0, push it on the stack

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.6

Page 20: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

An Example

Recall that the language{0n1n | n ≥ 0} is not regular.Consider the following PDA:

Read input symbols

For each0, push it on the stack

As soon as a1 is seen, pop a0 for each1 read

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.6

Page 21: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

An Example

Recall that the language{0n1n | n ≥ 0} is not regular.Consider the following PDA:

Read input symbols

For each0, push it on the stack

As soon as a1 is seen, pop a0 for each1 read

Acceptif stack isemptywhenlast symbol read

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.6

Page 22: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

An Example

Recall that the language{0n1n | n ≥ 0} is not regular.Consider the following PDA:

Read input symbols

For each0, push it on the stack

As soon as a1 is seen, pop a0 for each1 read

Acceptif stack isemptywhenlast symbol read

Rejectif

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.6

Page 23: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

An Example

Recall that the language{0n1n | n ≥ 0} is not regular.Consider the following PDA:

Read input symbols

For each0, push it on the stack

As soon as a1 is seen, pop a0 for each1 read

Acceptif stack isemptywhenlast symbol read

RejectifStack isnon-emptywhenlast symbol read

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.6

Page 24: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

An Example

Recall that the language{0n1n | n ≥ 0} is not regular.Consider the following PDA:

Read input symbols

For each0, push it on the stack

As soon as a1 is seen, pop a0 for each1 read

Acceptif stack isemptywhenlast symbol read

RejectifStack isnon-emptywhenlast symbol readStack isemptybut input symbol(s) still exist,

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.6

Page 25: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

An Example

Recall that the language{0n1n | n ≥ 0} is not regular.Consider the following PDA:

Read input symbols

For each0, push it on the stack

As soon as a1 is seen, pop a0 for each1 read

Acceptif stack isemptywhenlast symbol read

RejectifStack isnon-emptywhenlast symbol readStack isemptybut input symbol(s) still exist,0 is read after1.

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.6

Page 26: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

PDA Configuration

A Configurationof a Push-Down Automata is atriplet

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.7

Page 27: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

PDA Configuration

A Configurationof a Push-Down Automata is atriplet

(<state>,<remaining input string>,<stack>)

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.7

Page 28: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

PDA Configuration

A Configurationof a Push-Down Automata is atriplet

(<state>,<remaining input string>,<stack>)

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.7

Page 29: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

PDA Configuration

A Configurationof a Push-Down Automata is atriplet

(<state>,<remaining input string>,<stack>)

A configuration is like asnapshotof PDAprogress

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.7

Page 30: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

PDA Configuration

A Configurationof a Push-Down Automata is atriplet

(<state>,<remaining input string>,<stack>)

A configuration is like asnapshotof PDAprogress

A PDA computationis a sequence of successiveconfigurations, starting fromstart configuration

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.7

Page 31: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

PDA Configuration

A Configurationof a Push-Down Automata is atriplet

(<state>,<remaining input string>,<stack>)

A configuration is like asnapshotof PDAprogress

A PDA computationis a sequence of successiveconfigurations, starting fromstart configuration

The string describing the stack has top of thestack on the left (technical item)

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.7

Page 32: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Comparing PDA and Finite Automata

PDA may be deterministic or non-deterministic.

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.8

Page 33: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Comparing PDA and Finite Automata

PDA may be deterministic or non-deterministic.

Unlike finite automata, non-determinism addspower.

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.8

Page 34: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Comparing PDA and Finite Automata

PDA may be deterministic or non-deterministic.

Unlike finite automata, non-determinism addspower.

There are some languages acceptedonly bynon-deterministicPDAs.

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.8

Page 35: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Comparing PDA and Finite Automata

PDA may be deterministic or non-deterministic.

Unlike finite automata, non-determinism addspower.

There are some languages acceptedonly bynon-deterministicPDAs.

Transition functionδ looks different than DFA or NFA

cases, reflectingstackfunctionality.

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.8

Page 36: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

The Transition FunctionDenote input alphabet byΣ and stack alphabet byΓ.

thedomainof the transition functionδ is

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.9

Page 37: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

The Transition FunctionDenote input alphabet byΣ and stack alphabet byΓ.

thedomainof the transition functionδ iscurrent state:Q

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.9

Page 38: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

The Transition FunctionDenote input alphabet byΣ and stack alphabet byΓ.

thedomainof the transition functionδ iscurrent state:Qnext input, if any:Σε (=Σ ∪ {ε})

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.9

Page 39: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

The Transition FunctionDenote input alphabet byΣ and stack alphabet byΓ.

thedomainof the transition functionδ iscurrent state:Qnext input, if any:Σε (=Σ ∪ {ε})stack symbol popped, if any:Γε(=Γ ∪ {ε})

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.9

Page 40: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

The Transition FunctionDenote input alphabet byΣ and stack alphabet byΓ.

thedomainof the transition functionδ iscurrent state:Qnext input, if any:Σε (=Σ ∪ {ε})stack symbol popped, if any:Γε(=Γ ∪ {ε})

and itsrangeis

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.9

Page 41: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

The Transition FunctionDenote input alphabet byΣ and stack alphabet byΓ.

thedomainof the transition functionδ iscurrent state:Qnext input, if any:Σε (=Σ ∪ {ε})stack symbol popped, if any:Γε(=Γ ∪ {ε})

and itsrangeisnew state:Q

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.9

Page 42: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

The Transition FunctionDenote input alphabet byΣ and stack alphabet byΓ.

thedomainof the transition functionδ iscurrent state:Qnext input, if any:Σε (=Σ ∪ {ε})stack symbol popped, if any:Γε(=Γ ∪ {ε})

and itsrangeisnew state:Qstack symbol pushed, if any:Γε

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.9

Page 43: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

The Transition FunctionDenote input alphabet byΣ and stack alphabet byΓ.

thedomainof the transition functionδ iscurrent state:Qnext input, if any:Σε (=Σ ∪ {ε})stack symbol popped, if any:Γε(=Γ ∪ {ε})

and itsrangeisnew state:Qstack symbol pushed, if any:Γε

non-determinism:P(two components above)

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.9

Page 44: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

The Transition FunctionDenote input alphabet byΣ and stack alphabet byΓ.

thedomainof the transition functionδ iscurrent state:Qnext input, if any:Σε (=Σ ∪ {ε})stack symbol popped, if any:Γε(=Γ ∪ {ε})

and itsrangeisnew state:Qstack symbol pushed, if any:Γε

non-determinism:P(two components above)

δ : Q× Σε × Γε → P(Q× Γε)

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.9

Page 45: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Formal DefinitionsA pushdown automaton(PDA) is a 6-tuple(Q,Σ,Γ, δ, q0, F ), where

Q is a finite set called thestates,

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.10

Page 46: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Formal DefinitionsA pushdown automaton(PDA) is a 6-tuple(Q,Σ,Γ, δ, q0, F ), where

Q is a finite set called thestates,

Σ is a finite set called theinput alphabet,

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.10

Page 47: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Formal DefinitionsA pushdown automaton(PDA) is a 6-tuple(Q,Σ,Γ, δ, q0, F ), where

Q is a finite set called thestates,

Σ is a finite set called theinput alphabet,

Γ is a finite set called thestack alphabet,

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.10

Page 48: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Formal DefinitionsA pushdown automaton(PDA) is a 6-tuple(Q,Σ,Γ, δ, q0, F ), where

Q is a finite set called thestates,

Σ is a finite set called theinput alphabet,

Γ is a finite set called thestack alphabet,

δ : Q× Σε × Γε → P(Q× Γε) is thetransitionfunction,

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.10

Page 49: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Formal DefinitionsA pushdown automaton(PDA) is a 6-tuple(Q,Σ,Γ, δ, q0, F ), where

Q is a finite set called thestates,

Σ is a finite set called theinput alphabet,

Γ is a finite set called thestack alphabet,

δ : Q× Σε × Γε → P(Q× Γε) is thetransitionfunction,

q0 ∈ Q is thestart state, and

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.10

Page 50: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Formal DefinitionsA pushdown automaton(PDA) is a 6-tuple(Q,Σ,Γ, δ, q0, F ), where

Q is a finite set called thestates,

Σ is a finite set called theinput alphabet,

Γ is a finite set called thestack alphabet,

δ : Q× Σε × Γε → P(Q× Γε) is thetransitionfunction,

q0 ∈ Q is thestart state, and

F ⊆ Q is the set ofaccept states.

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.10

Page 51: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

ConventionsIt will be convenient to be able to know when thestack is empty, but there isno built-in mechanismto do that.

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.11

Page 52: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

ConventionsIt will be convenient to be able to know when thestack is empty, but there isno built-in mechanismto do that.

Solution:

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.11

Page 53: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

ConventionsIt will be convenient to be able to know when thestack is empty, but there isno built-in mechanismto do that.

Solution:Start by pushing$ onto stack.

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.11

Page 54: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

ConventionsIt will be convenient to be able to know when thestack is empty, but there isno built-in mechanismto do that.

Solution:Start by pushing$ onto stack.When you see it again, stack is empty.

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.11

Page 55: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

ConventionsIt will be convenient to be able to know when thestack is empty, but there isno built-in mechanismto do that.

Solution:Start by pushing$ onto stack.When you see it again, stack is empty.

Question: When is input string exhausted?

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.11

Page 56: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

ConventionsIt will be convenient to be able to know when thestack is empty, but there isno built-in mechanismto do that.

Solution:Start by pushing$ onto stack.When you see it again, stack is empty.

Question: When is input string exhausted?It doesn’t matter. No modifications needed!

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.11

Page 57: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

ConventionsIt will be convenient to be able to know when thestack is empty, but there isno built-in mechanismto do that.

Solution:Start by pushing$ onto stack.When you see it again, stack is empty.

Question: When is input string exhausted?It doesn’t matter. No modifications needed!’Caus accepting state is effective only if inputstring was exhausted!

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.11

Page 58: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

NotationTransitiona, b→ c means

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.12

Page 59: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

NotationTransitiona, b→ c means

reada from input

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.12

Page 60: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

NotationTransitiona, b→ c means

reada from inputpopb from stack

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.12

Page 61: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

NotationTransitiona, b→ c means

reada from inputpopb from stackpushc onto stack

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.12

Page 62: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

NotationTransitiona, b→ c means

reada from inputpopb from stackpushc onto stack

Meaning ofε transitions:

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.12

Page 63: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

NotationTransitiona, b→ c means

reada from inputpopb from stackpushc onto stack

Meaning ofε transitions:

if a = ε, don’t read inputs

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.12

Page 64: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

NotationTransitiona, b→ c means

reada from inputpopb from stackpushc onto stack

Meaning ofε transitions:

if a = ε, don’t read inputsif b = ε, don’t pop any symbols

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.12

Page 65: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

NotationTransitiona, b→ c means

reada from inputpopb from stackpushc onto stack

Meaning ofε transitions:

if a = ε, don’t read inputsif b = ε, don’t pop any symbolsif c = ε, don’t push any symbols

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.12

Page 66: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Example

The PDA

ε,ε $1q q2

q3q4

0,ε $

1,0 ε

1,0 εε,$ ε

accepts{0n1n|n ≥ 1}.

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.13

Page 67: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Example

The PDA

ε,ε $1q q2

q3q4

0,ε $

1,0 ε

1,0 εε,$ ε

accepts{0n1n|n ≥ 1}.

(does it also accept the empty string?)

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.13

Page 68: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Another Example

A PDA that accepts{

aibjck|i, j, k > 0 andi = j or i = k}

Informally:

read and pusha’s

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.14

Page 69: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Another Example

A PDA that accepts{

aibjck|i, j, k > 0 andi = j or i = k}

Informally:

read and pusha’s

either pop and match withb’s

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.14

Page 70: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Another Example

A PDA that accepts{

aibjck|i, j, k > 0 andi = j or i = k}

Informally:

read and pusha’s

either pop and match withb’s

or else pop and match withc’s

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.14

Page 71: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Another Example

A PDA that accepts{

aibjck|i, j, k > 0 andi = j or i = k}

Informally:

read and pusha’s

either pop and match withb’s

or else pop and match withc’s

anon-deterministicchoice!

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.14

Page 72: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Another Example (cont.)

ε,ε $

1q

q2

q3 q4ε,$ ε

q5 q0 q7ε,ε

ε

εb,a εc, ε

εa, a εb, ε c,a ε

ε,ε ε ε,ε ε ε,ε ε

A PDA that accepts{

aibjck|i, j, k > 0 andi = j or i = k}

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.15

Page 73: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Another Example (cont.)

A PDA that accepts{

aibjck|i, j, k > 0 andi = j or i = k}

Note: non-determinism is essential here!

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.16

Page 74: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Another Example (cont.)

A PDA that accepts{

aibjck|i, j, k > 0 andi = j or i = k}

Note: non-determinism is essential here!

Unlike finite automata, non-determinismdoes add power.

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.16

Page 75: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Another Example (cont.)

A PDA that accepts{

aibjck|i, j, k > 0 andi = j or i = k}

Note: non-determinism is essential here!

Unlike finite automata, non-determinismdoes add power.

Let us try to think how a proof could go,

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.16

Page 76: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Another Example (cont.)

A PDA that accepts{

aibjck|i, j, k > 0 andi = j or i = k}

Note: non-determinism is essential here!

Unlike finite automata, non-determinismdoes add power.

Let us try to think how a proof could go,...

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.16

Page 77: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Another Example (cont.)

A PDA that accepts{

aibjck|i, j, k > 0 andi = j or i = k}

Note: non-determinism is essential here!

Unlike finite automata, non-determinismdoes add power.

Let us try to think how a proof could go,...and realize it does not seem trivial or immediate.

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.16

Page 78: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

NonDeterministm Essential for PDAsTheorem: LetM be a PDA that accepts

L = {xnyn|n ≥ 0} ∪{

xny2n | n ≥ 0}

.

ThenM is non-deterministic.Proof: (www.cs.may.ie/∼jpower/Courses/parsing/node38.html)

Suppose, by way ofcontradiction,M is deterministic.

Create two copies of this PDA, denotededM1

andM2.

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.17

Page 79: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

NonDeterministm Essential for PDAsTheorem: LetM be a PDA that accepts

L = {xnyn|n ≥ 0} ∪{

xny2n | n ≥ 0}

.

ThenM is non-deterministic.Proof: (www.cs.may.ie/∼jpower/Courses/parsing/node38.html)

Suppose, by way ofcontradiction,M is deterministic.

Create two copies of this PDA, denotededM1

andM2.

Say two states“cousins”if they are copies of thesame state in the original PDA.

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.17

Page 80: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

NonDeterministm Essential for PDAsTheorem: LetM be a PDA that accepts

L = {xnyn|n ≥ 0} ∪{

xny2n | n ≥ 0}

.

ThenM is non-deterministic.Proof: (www.cs.may.ie/∼jpower/Courses/parsing/node38.html)

Suppose, by way ofcontradiction,M is deterministic.

Create two copies of this PDA, denotededM1

andM2.

Say two states“cousins”if they are copies of thesame state in the original PDA.

We now modify these copies to make them intoone PDA,M0, over the alphabet{x, y, z}.

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.17

Page 81: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

NonDeterministm Essential (cont.)

States of the newM0 are those ofM1 unionM2.

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.18

Page 82: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

NonDeterministm Essential (cont.)

States of the newM0 are those ofM1 unionM2.

Start state of the newM0 is the start state ofM1.

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.18

Page 83: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

NonDeterministm Essential (cont.)

States of the newM0 are those ofM1 unionM2.

Start state of the newM0 is the start state ofM1.

The accepting states of the newM0 are theaccepting states ofM2.

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.18

Page 84: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

NonDeterministm Essential (cont.)

States of the newM0 are those ofM1 unionM2.

Start state of the newM0 is the start state ofM1.

The accepting states of the newM0 are theaccepting states ofM2.

For bothM1 andM2, add a newz transitionforevery existingy transition.

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.18

Page 85: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

NonDeterministm Essential (cont.)

States of the newM0 are those ofM1 unionM2.

Start state of the newM0 is the start state ofM1.

The accepting states of the newM0 are theaccepting states ofM2.

For bothM1 andM2, add a newz transitionforevery existingy transition.

Now changeany transition(x, y, or z) originatingfrom an red accept state inM1 so it goes to its“cousin” destination inM2.

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.18

Page 86: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

NonDeterministm Essential (cont.)

What languageM0 recognizes? Consider itsactions on an input of the formxkykzk for somefixedk.

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.19

Page 87: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

NonDeterministm Essential (cont.)

What languageM0 recognizes? Consider itsactions on an input of the formxkykzk for somefixedk.

Initially M0 moves from the start state to anaccept state ofM1 while consumingxkyk.

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.19

Page 88: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

NonDeterministm Essential (cont.)

What languageM0 recognizes? Consider itsactions on an input of the formxkykzk for somefixedk.

Initially M0 moves from the start state to anaccept state ofM1 while consumingxkyk.

Since no prefix ofxkyk is inL,M0 doesnotgothrough any accept state earlier.

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.19

Page 89: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

NonDeterministm Essential (cont.)

What languageM0 recognizes? Consider itsactions on an input of the formxkykzk for somefixedk.

Initially M0 moves from the start state to anaccept state ofM1 while consumingxkyk.

Since no prefix ofxkyk is inL,M0 doesnotgothrough any accept state earlier.

BecauseM0 is deterministic, it could reach noother state while consumingxkyk.

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.19

Page 90: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

NonDeterministm Essential (cont.)

What languageM0 recognizes? Consider itsactions on an input of the formxkykzk for somefixedk.

Initially M0 moves from the start state to anaccept state ofM1 while consumingxkyk.

Since no prefix ofxkyk is inL,M0 doesnotgothrough any accept state earlier.

BecauseM0 is deterministic, it could reach noother state while consumingxkyk.

BecauseM1 acceptsL, it would go on to acceptanotheryk block. Therefore, by construction,M0

will move onzk to its “M2” half, and accept.Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.19

Page 91: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Conclusion of ProofWe can conclude (after a few more arguments)thatM0 accepts the language{xnynzn|n ≥ 0}.Contradiction. ♣

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.20

Page 92: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Conclusion of ProofWe can conclude (after a few more arguments)thatM0 accepts the language{xnynzn|n ≥ 0}.Contradiction. ♣

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.20

Page 93: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Conclusion of ProofWe can conclude (after a few more arguments)thatM0 accepts the language{xnynzn|n ≥ 0}.Contradiction. ♣

Contradiction? What contradiction?What the $%&# does this contradict?

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.20

Page 94: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Conclusion of ProofWe can conclude (after a few more arguments)thatM0 accepts the language{xnynzn|n ≥ 0}.Contradiction. ♣

Contradiction? What contradiction?What the $%&# does this contradict?

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.20

Page 95: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Conclusion of ProofWe can conclude (after a few more arguments)thatM0 accepts the language{xnynzn|n ≥ 0}.Contradiction. ♣

Contradiction? What contradiction?What the $%&# does this contradict?

And while in the mode of thinking about theproof, where would such argument fail if theoriginalM werenon-deterministic?

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.20

Page 96: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

And Yet Another PDA Example

A palindromehas the formwwR.

“Madam I’m Adam”

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.21

Page 97: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

And Yet Another PDA Example

A palindromehas the formwwR.

“Madam I’m Adam”

“Dennis and Edna sinned”

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.21

Page 98: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

And Yet Another PDA Example

A palindromehas the formwwR.

“Madam I’m Adam”

“Dennis and Edna sinned”

“Red rum, sir, is murder”

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.21

Page 99: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

And Yet Another PDA Example

A palindromehas the formwwR.

“Madam I’m Adam”

“Dennis and Edna sinned”

“Red rum, sir, is murder”

“In girum imus nocte et consumimur igni”

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.21

Page 100: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

And Yet Another PDA Example

A palindromehas the formwwR.

“Madam I’m Adam”

“Dennis and Edna sinned”

“Red rum, sir, is murder”

“In girum imus nocte et consumimur igni”

“νιψoν ανoµηµατα µη µoναν oψιν”

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.21

Page 101: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Yet Another Example (cont.)

This PDA

ε,ε $1q q2

q3q4 ε,$ ε

0,ε 0ε1, 1

ε,ε ε

ε1,1ε0,0

accepts binary palindromes.

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.22

Page 102: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

PDA Languages

The Push-Down Automata Languages,LPDA, is theset of all languages that can be described by somePDA:

LPDA = {L : ∃ PDAM ∧ L[M ] = L}

We already knowLPDA ) LDFA (why)?

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.23

Page 103: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

PDA Languages

The Push-Down Automata Languages,LPDA, is theset of all languages that can be described by somePDA:

LPDA = {L : ∃ PDAM ∧ L[M ] = L}

We already knowLPDA ) LDFA –since every DFA is just a PDA thatignores the stack.

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.24

Page 104: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

PDA Languages

The Push-Down Automata Languages,LPDA, is theset of all languages that can be described by somePDA:

LPDA = {L : ∃ PDAM ∧ L[M ] = L}

We already knowLPDA ) LDFA –since every DFA is just a PDA thatignores the stack.

LCFG ⊆ LPDA ?

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.24

Page 105: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

PDA Languages

The Push-Down Automata Languages,LPDA, is theset of all languages that can be described by somePDA:

LPDA = {L : ∃ PDAM ∧ L[M ] = L}

We already knowLPDA ) LDFA –since every DFA is just a PDA thatignores the stack.

LCFG ⊆ LPDA ?

LPDA ⊆ LCFG ?

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.24

Page 106: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Equivalence Theorem

Theorem: A language is context free if and only ifsome pushdown automaton accepts it.

This time, both the “if” part and the “only if” part arenon-trivial.

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.25

Page 107: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

LCFG ⊆ LPDA

Given any CFGG, can we create a PDAM such thatL[M ] = L[G]?

Idea: We will first use the stack to derive theinput string, and then check to make sure ourderivation matches the input

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.26

Page 108: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

If PartTheorem: If a language is context free, then somepushdown automaton accepts it.

LetL be a context-free language.

We knowL has a context-free grammarG.

on inputw, the PDAP should figure out if thereis a derivation ofw usingG.

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.27

Page 109: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

If PartTheorem: If a language is context free, then somepushdown automaton accepts it.

LetL be a context-free language.

We knowL has a context-free grammarG.

on inputw, the PDAP should figure out if thereis a derivation ofw usingG.

Question: How doesP figure out which substitutionto make?

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.27

Page 110: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

If PartTheorem: If a language is context free, then somepushdown automaton accepts it.

LetL be a context-free language.

We knowL has a context-free grammarG.

on inputw, the PDAP should figure out if thereis a derivation ofw usingG.

Question: How doesP figure out which substitutionto make?

Answer: It guesses.

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.27

Page 111: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

CFL Implies PDA

Informally:

P pushes start variableS on stack

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.28

Page 112: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

CFL Implies PDA

Informally:

P pushes start variableS on stack

keeps making substitutions

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.28

Page 113: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

CFL Implies PDA

Informally:

P pushes start variableS on stack

keeps making substitutions

when only terminals remain . . .

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.28

Page 114: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

CFL Implies PDA

Informally:

P pushes start variableS on stack

keeps making substitutions

when only terminals remain . . .

tests whetherderived stringequalsinput

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.28

Page 115: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

CFL Implies PDA (cont.)

Where do we keep the intermediate string?

read unread

pop

push

A1A0$

011001

intermediate string: A1A001

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.29

Page 116: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

CFL Implies PDA (cont.)

Where do we keep the intermediate string?

read unread

pop

push

A1A0$

011001

intermediate string: A1A001

can’t put it all on the stack

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.29

Page 117: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

CFL Implies PDA (cont.)

Where do we keep the intermediate string?

read unread

pop

push

A1A0$

011001

intermediate string: A1A001

can’t put it all on the stack

only strings whose first letter is a variable arekept on stack

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.29

Page 118: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

CFL Implies PDA (cont.)

Informal description:

pushS$ on stack

if top of stack is variableA, non-deterministicallyselect rule and substitute.

if top of stack is terminala, read next input andcompare. If they differ, reject.

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.30

Page 119: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

CFL Implies PDA (cont.)

Need shorthand to push entire string onto stack.

(r, w) ∈ δ(q, a, s)

Easy to do by introducing intermediate states.

q

r

q

r

a,s xyz

a,s z

ε,ε y

ε,ε x

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.31

Page 120: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

CFL Implies PDA (cont.)

States ofP are

start stateqsaccept stateqaloop stateqℓ

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.32

Page 121: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Transition FunctionInitialize stack

δ(qs, ε, ε) = {qℓ, S$}

Top of stack is variable

δ(qℓ, ε, A) = {(qℓ, w)| whereA→ w is a rule}

Top of stack is terminal

δ(qℓ, a, a) = {(qℓ, ε)}

End of Stack

δ(qℓ, ε, $) = {(qa, ε)}

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.33

Page 122: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Transition Function

ε,$ ε

qs

qa

ql

ε,ε S$

εa,aε,A w

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.34

Page 123: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Example

S → aTb|b

T → Ta|ε

qs

ql

ε,ε S$

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.35

Page 124: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Example

S → aTb|b

T → Ta|ε

Rules forS

qs

qa

ql

ε,ε S$Sε, b

Tε,ε

ε,ε a

Sε, b

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.36

Page 125: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Example

S → aTb|b

T → Ta|ε

Rules forT

qs

qa

ql

ε,ε S$Sε, b

Tε,ε

ε,ε a

ε, aT ε,ε a

Sε, bε,T ε

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.37

Page 126: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Example

S → aTb|b

T → Ta|ε

Rules for terminalsqs

qa

ql

ε,ε S$

Sε, b

Tε,ε

ε,ε a

ε, aT ε,ε a

Sε, bε,T ε

εaaεbb

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.38

Page 127: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Example

S → aTb|b

T → Ta|εTermination:

qs

qa

ql

ε,ε S$

Sε, b

Tε,ε

ε,ε a

ε, aT ε,ε a

Sε, bε,T ε

εaaεbbε, ε$

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.39

Page 128: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Only If Part

Theorem: If a PDA accepts a language,L, thenL iscontext-free.

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.40

Page 129: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Only If Part

Theorem: If a PDA accepts a language,L, thenL iscontext-free.

Given a pushdown automataP , we want to design acontext-free grammarG that “simulates” it:

The strings generated byG should be exactly those that

causeP to go from thestart stateto anaccepting state.

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.40

Page 130: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Only If Part

Theorem: If a PDA accepts a language,L, thenL iscontext-free.

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.41

Page 131: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Only If Part

Theorem: If a PDA accepts a language,L, thenL iscontext-free.

Proof: After constructing the grammarG , shouldprove it generates exactly the same language acceptedby the PDA.This is done by induction on the length of anycomputation ofP on any input stringx.

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.41

Page 132: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Only If Part

Theorem: If a PDA accepts a language,L, thenL iscontext-free.

Proof: After constructing the grammarG , shouldprove it generates exactly the same language acceptedby the PDA.This is done by induction on the length of anycomputation ofP on any input stringx.The induction argument is a bit lengthy and tedious,and we’ll skip it.

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.41

Page 133: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Only If Part

Theorem: If a PDA accepts a language,L, thenL iscontext-free.

Proof: After constructing the grammarG , shouldprove it generates exactly the same language acceptedby the PDA.This is done by induction on the length of anycomputation ofP on any input stringx.The induction argument is a bit lengthy and tedious,and we’ll skip it.

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.41

Page 134: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Only If Part

Theorem: If a PDA accepts a language,L, thenL iscontext-free.

Proof: After constructing the grammarG , shouldprove it generates exactly the same language acceptedby the PDA.This is done by induction on the length of anycomputation ofP on any input stringx.The induction argument is a bit lengthy and tedious,and we’ll skip it.

Diehards are welcome to consult pp. 106–114 inSipser’s book, and/or last year’s slides (fall 2003/4).

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.41

Page 135: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Corollary

Every regular language is context-free.

context freelanguages

regularlanguages

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.42

Page 136: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Non-Context-Free Languages

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.43

Page 137: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Non-Context-Free Languages

pumping lemmafor finite automata is our(almost) only tool for showing that languagesarenot regular.

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.43

Page 138: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Non-Context-Free Languages

pumping lemmafor finite automata is our(almost) only tool for showing that languagesarenot regular.

we will now do the same for context-freelanguages.

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.43

Page 139: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Non-Context-Free Languages

pumping lemmafor finite automata is our(almost) only tool for showing that languagesarenot regular.

we will now do the same for context-freelanguages.

it’s slightly more complicated . . .

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.43

Page 140: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Pumping Lemma for CFL

Also known as theuvxyz Theorem.

Theorem: If A is a CFL , there is anℓ (criticallength), such that ifs ∈ A and|s| ≥ ℓ, thens = uvxyz where

for everyi ≥ 0, uvixyiz ∈ A

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.44

Page 141: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Pumping Lemma for CFL

Also known as theuvxyz Theorem.

Theorem: If A is a CFL , there is anℓ (criticallength), such that ifs ∈ A and|s| ≥ ℓ, thens = uvxyz where

for everyi ≥ 0, uvixyiz ∈ A

|vy| > 0, (non-triviality)

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.44

Page 142: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Pumping Lemma for CFL

Also known as theuvxyz Theorem.

Theorem: If A is a CFL , there is anℓ (criticallength), such that ifs ∈ A and|s| ≥ ℓ, thens = uvxyz where

for everyi ≥ 0, uvixyiz ∈ A

|vy| > 0, (non-triviality)

|vxy| ≤ ℓ.

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.44

Page 143: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Basic IntuitionLetA be a CFL andG its CFG.

Let s be a “very long” string inA.

Thens has a “tall” parse tree.

And some root-to-leaf path must repeat a symbol.ahmmm,. . . why is that so?

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.45

Page 144: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Basic IntuitionLetA be a CFL andG its CFG.

Let s be a “very long” string inA.

Thens has a “tall” parse tree.

And some root-to-leaf path must repeat a symbol.ahmmm,. . . why is that so?

T

R

u v x y z

R

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.45

Page 145: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

ProofletG be a CFG for CFLA.

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.46

Page 146: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

ProofletG be a CFG for CFLA.

let c be the max number of symbols inright-hand-side of any rule.

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.46

Page 147: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

ProofletG be a CFG for CFLA.

let c be the max number of symbols inright-hand-side of any rule.

no node in parse tree has> c children.

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.46

Page 148: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

ProofletG be a CFG for CFLA.

let c be the max number of symbols inright-hand-side of any rule.

no node in parse tree has> c children.

at depthd, no more thancd leaves.

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.46

Page 149: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

ProofletG be a CFG for CFLA.

let c be the max number of symbols inright-hand-side of any rule.

no node in parse tree has> c children.

at depthd, no more thancd leaves.

let |V | be the number of variables inG.

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.46

Page 150: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

ProofletG be a CFG for CFLA.

let c be the max number of symbols inright-hand-side of any rule.

no node in parse tree has> c children.

at depthd, no more thancd leaves.

let |V | be the number of variables inG.

let ℓ = c|V |+2.

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.46

Page 151: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Proof (2)

let s be a string where|s| ≥ ℓ

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.47

Page 152: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Proof (2)

let s be a string where|s| ≥ ℓ

let τ be parse tree fors with fewest nodes

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.47

Page 153: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Proof (2)

let s be a string where|s| ≥ ℓ

let τ be parse tree fors with fewest nodes

τ has height≥ |V | + 2

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.47

Page 154: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Proof (2)

let s be a string where|s| ≥ ℓ

let τ be parse tree fors with fewest nodes

τ has height≥ |V | + 2

some path inτ has length≥ |V | + 2

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.47

Page 155: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Proof (2)

let s be a string where|s| ≥ ℓ

let τ be parse tree fors with fewest nodes

τ has height≥ |V | + 2

some path inτ has length≥ |V | + 2

that pathrepeatsa variableR

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.47

Page 156: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Proof (3)

Split s = uvxyz

T

R

u v x y z

R

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.48

Page 157: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Proof (3)

Split s = uvxyz

T

R

u v x y z

R

each occurrence ofR produces a string

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.48

Page 158: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Proof (3)

Split s = uvxyz

T

R

u v x y z

R

each occurrence ofR produces a string

upper produces stringvxy

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.48

Page 159: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Proof (3)

Split s = uvxyz

T

R

u v x y z

R

each occurrence ofR produces a string

upper produces stringvxy

lower produces stringxSlides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.48

Page 160: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

ProofReplacing smaller by larger yieldsuvixyiz, for i > 0.

T

R

u v x y z

R

v yx

R

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.49

Page 161: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Proof (4)

Replacing larger by smaller yieldsuxz.

T

R

u

x

zTogether, they establish:

for i ≥ 0, uvixyiz ∈ A

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.50

Page 162: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Proof (5)

Next condition is:

|vy| > 0

If v andy are bothε, thenT

R

u

x

z

is a parse tree fors with fewer nodes.Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.51

Page 163: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Proof (6)

Final condition is|vxy| ≤ ℓ:T

R

u v x y z

R |V|+2

b |V|+2

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.52

Page 164: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Proof (6)

Final condition is|vxy| ≤ ℓ:T

R

u v x y z

R |V|+2

b |V|+2

the upper occurrence ofR generatesvxy.

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.52

Page 165: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Proof (6)

Final condition is|vxy| ≤ ℓ:T

R

u v x y z

R |V|+2

b |V|+2

the upper occurrence ofR generatesvxy.

can choose symbols such that both occurrences ofR lie in bottom|V | + 1 variables on path.

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.52

Page 166: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Proof (6)

Final condition is|vxy| ≤ ℓ:T

R

u v x y z

R |V|+2

b |V|+2

the upper occurrence ofR generatesvxy.

can choose symbols such that both occurrences ofR lie in bottom|V | + 1 variables on path.

subtree whereR generatesvxy is≤ |V | + 2 high.

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.52

Page 167: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Proof (6)

Final condition is|vxy| ≤ ℓ:T

R

u v x y z

R |V|+2

b |V|+2

the upper occurrence ofR generatesvxy.

can choose symbols such that both occurrences ofR lie in bottom|V | + 1 variables on path.

subtree whereR generatesvxy is≤ |V | + 2 high.

strings by subtree at mostb|V |+2 = ℓ long.Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.52

Page 168: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Example

Theorem: B = {anbncn} is not a CFL.Proof: By contradiction.

Let ℓ be the critical length.

Considers = aℓbℓcℓ.If s = uvxyz, neitherv nory can contain

botha’s andb’s, or

bothb’s andc’s, because

uv2xy2z would have out-of-order symbols.But if v andy contain only one symbol, thenuv2xy2zhas an imbalance!

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.53

Page 169: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Example (2)

The languageC ={

aibjck|0 ≤ i ≤ j ≤ k}

is notcontext-free.Let ℓ be the critical length, ands = aℓbℓcℓ.

Let s = uvxyz

neitherv nory contains contains two distinct symbols,

becauseuv2xy2z would have out-of-order symbols.

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.54

Page 170: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Example (2)

The languageC ={

aibjck|0 ≤ i ≤ j ≤ k}

is notcontext-free.Let ℓ be the critical length, ands = aℓbℓcℓ.

Let s = uvxyz

neitherv nory contains contains two distinct symbols,

becauseuv2xy2z would have out-of-order symbols.

vxy not all b’s (why?)

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.54

Page 171: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Example (2)

The languageC ={

aibjck|0 ≤ i ≤ j ≤ k}

is notcontext-free.Let ℓ be the critical length, ands = aℓbℓcℓ.

Let s = uvxyz

neitherv nory contains contains two distinct symbols,

becauseuv2xy2z would have out-of-order symbols.

vxy not all b’s (why?)

vxy < ℓ, so either

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.54

Page 172: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Example (2)

The languageC ={

aibjck|0 ≤ i ≤ j ≤ k}

is notcontext-free.Let ℓ be the critical length, ands = aℓbℓcℓ.

Let s = uvxyz

neitherv nory contains contains two distinct symbols,

becauseuv2xy2z would have out-of-order symbols.

vxy not all b’s (why?)

vxy < ℓ, so either

v contains onlya’s andy contains onlyb’s, but then

uv2xy2z has too fewc’s.

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.54

Page 173: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Example (2)

The languageC ={

aibjck|0 ≤ i ≤ j ≤ k}

is notcontext-free.Let ℓ be the critical length, ands = aℓbℓcℓ.

Let s = uvxyz

neitherv nory contains contains two distinct symbols,

becauseuv2xy2z would have out-of-order symbols.

vxy not all b’s (why?)

vxy < ℓ, so either

v contains onlya’s andy contains onlyb’s, but then

uv2xy2z has too fewc’s.

v contains onlyb’s andy contains onlyc’s. but then

uv0xy0z has too manya’s.Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.54

Page 174: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Example (3)

The languageD = {ww|w ∈ {0, 1}∗} is notcontext-free.Let s = 0ℓ1ℓ0ℓ1ℓ As before, supposes = uvxyz .

Recall that|vxy| ≤ ℓ.

if vxy is in the first half ofs, uv2xy2z moves a 1 into the

first position in second half.

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.55

Page 175: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Example (3)

The languageD = {ww|w ∈ {0, 1}∗} is notcontext-free.Let s = 0ℓ1ℓ0ℓ1ℓ As before, supposes = uvxyz .

Recall that|vxy| ≤ ℓ.

if vxy is in the first half ofs, uv2xy2z moves a 1 into the

first position in second half.

if vxy is in the second half,uv2xy2z moves a 0 into the last

position in first half.

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.55

Page 176: Push Down Automata (PDA) - Tel Aviv Universitybchor/CM05/Compute4.pdf · Push Down Automata (PDA) Nondeterminism adds power to PDAs Equivalence of CFGs and PDAs Pumping Lemma for

Example (3)

The languageD = {ww|w ∈ {0, 1}∗} is notcontext-free.Let s = 0ℓ1ℓ0ℓ1ℓ As before, supposes = uvxyz .

Recall that|vxy| ≤ ℓ.

if vxy is in the first half ofs, uv2xy2z moves a 1 into the

first position in second half.

if vxy is in the second half,uv2xy2z moves a 0 into the last

position in first half.

if vxy straddles the midpoint, then pumpingdown to uxz

yields0ℓ1i0j1ℓ wherei andj cannot both beℓ.

Slides modified by Benny Chor, based on original slides by David Galles, Univ. of San Francisco, and Maurice Herlihy, Brown Univ. – p.55