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.

Slides:



Advertisements
Similar presentations
Pushdown Automata Section 2.2 CSC 4170 Theory of Computation.
Advertisements

Pushdown Automata CPSC 388 Ellen Walker Hiram College.
Pushdown Automata Chapter 12. Recognizing Context-Free Languages Two notions of recognition: (1) Say yes or no, just like with FSMs (2) Say yes or no,
Pushdown Automata Chapter 12. Recognizing Context-Free Languages We need a device similar to an FSM except that it needs more power. The insight: Precisely.
Pushdown Automata (PDA)
CS21 Decidability and Tractability
Introduction to Computability Theory
1 Introduction to Computability Theory Lecture7: PushDown Automata (Part 1) Prof. Amos Israeli.
Costas Busch - RPI1 Pushdown Automata PDAs. Costas Busch - RPI2 Pushdown Automaton -- PDA Input String Stack States.
Courtesy Costas Busch - RPI1 Pushdown Automata PDAs.
Costas Busch - RPI1 NPDAs Accept Context-Free Languages.
Courtesy Costas Busch - RPI1 NPDAs Accept Context-Free Languages.
CS 310 – Fall 2006 Pacific University CS310 Pushdown Automata Sections: 2.2 page 109 October 9, 2006.
1 Normal Forms for Context-free Grammars. 2 Chomsky Normal Form All productions have form: variable and terminal.
Fall 2004COMP 3351 NPDA’s Accept Context-Free Languages.
Foundations of (Theoretical) Computer Science Chapter 2 Lecture Notes (Section 2.2: Pushdown Automata) Prof. Karen Daniels, Fall 2009 with acknowledgement.
Fall 2004COMP 3351 Pushdown Automata PDAs. Fall 2004COMP 3352 Pushdown Automaton -- PDA Input String Stack States.
Fall 2006Costas Busch - RPI1 Pushdown Automata PDAs.
January 14, 2015CS21 Lecture 51 CS21 Decidability and Tractability Lecture 5 January 14, 2015.
CS5371 Theory of Computation Lecture 8: Automata Theory VI (PDA, PDA = CFG)
Prof. Busch - LSU1 Pushdown Automata PDAs. Prof. Busch - LSU2 Pushdown Automaton -- PDA Input String Stack States.
Fall 2005Costas Busch - RPI1 Pushdown Automata PDAs.
1 Pushdown Automata PDAs. 2 Pushdown Automaton -- PDA Input String Stack States.
CS 3240: Languages and Computation Pushdown Automata & CF Grammars NOTE: THESE ARE ONLY PARTIAL SLIDES RELATED TO WEEKS 9 AND 10. PLEASE REFER TO THE TEXTBOOK.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 8 Mälardalen University 2010.
Pushdown Automata.
Pushdown Automata CS 130: Theory of Computation HMU textbook, Chap 6.
Pushdown Automata (PDAs)
Cs3102: Theory of Computation Class 6: Pushdown Automata Spring 2010 University of Virginia David Evans TexPoint fonts used in EMF. Read the TexPoint manual.
Pushdown Automata Part I: PDAs Chapter Recognizing Context-Free Languages Two notions of recognition: (1) Say yes or no, just like with FSMs (2)
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 11 Midterm Exam 2 -Context-Free Languages Mälardalen University 2005.
1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 6 Mälardalen University 2010.
Complexity and Computability Theory I Lecture #11 Instructor: Rina Zviel-Girshin Lea Epstein.
Chapter 7 Pushdown Automata
Foundations of (Theoretical) Computer Science Chapter 2 Lecture Notes (Section 2.2: Pushdown Automata) Prof. Karen Daniels, Fall 2010 with acknowledgement.
CSCI 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Pushdown.
Formal Languages, Automata and Models of Computation
Pushdown Automata Hopcroft, Motawi, Ullman, Chap 6.
1.Draw a parse tree for the following derivation: S  C A C  C A b b  b b A b b  b b B b b  b b a A a a b b  b b a b a a b b 2. Show on your parse.
Grammar Set of variables Set of terminal symbols Start variable Set of Production rules.
1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 8 Mälardalen University 2011.
Pushdown Automata Chapter 12. Recognizing Context-Free Languages Two notions of recognition: (1) Say yes or no, just like with FSMs (2) Say yes or no,
1 Chapter Pushdown Automata. 2 Section 12.2 Pushdown Automata A pushdown automaton (PDA) is a finite automaton with a stack that has stack operations.
CS 154 Formal Languages and Computability March 10 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak.
CS 154 Formal Languages and Computability March 15 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak.
Recap: Nondeterministic Finite Automaton (NFA) A deterministic finite automaton (NFA) is a 5-tuple (Q, , ,s,F) where: Q is a finite set of elements called.
Formal Languages, Automata and Models of Computation
Pushdown Automata.
Theory of Computation Pushdown Automata pda Lecture #10.
Non Deterministic Automata
Pushdown Automata PDAs
Pushdown Automata PDAs
Pushdown Automata PDAs
PDAs Accept Context-Free Languages
Pushdown Automata PDAs
Pushdown Automata.
Theory of Computation Lecture #27-28.
Chapter 7 PUSHDOWN AUTOMATA.
Pushdown Automata.
Pushdown Automata (PDA). Part 3
NPDAs Accept Context-Free Languages
Principles of Computing – UFCFA3-30-1
Non-Deterministic Finite Automata
Non Deterministic Automata
Principles of Computing – UFCFA3-30-1
… NPDAs continued.
Recap lecture 37 New format for FAs, input TAPE, START, ACCEPT , REJECT, READ states Examples of New Format of FAs, PUSHDOWN STACK , PUSH and POP states,
More About Nondeterminism
Normal Forms for Context-free Grammars
Presentation transcript:

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

What is a PDA? A PDA is an 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 of the form a, x ⟶ y require that the next input symbol should be a and the top stack symbol should be x. qq’ a, x ⟶ y xwxw...abb... StackInput q q’ a, x ⟶ y ywyw...abb... StackInput

Transitions Transitions of the form ε, x ⟶ y require that the top stack symbol is x. qq’ ε, x ⟶ y xwxw StackInput q q’ ε, x ⟶ y ywyw StackInput...abb...

Transitions Transitions of the form a, ε ⟶ y require that the next input symbol is a. qq’ a, ε ⟶ y xwxw StackInput q q’ a, ε ⟶ y yxwyxw StackInput...abb...

Transitions Transitions of the form ε, ε ⟶ y can be followed without restrictions. qq’ ε, ε ⟶ y xwxw StackInput q q’ ε, ε ⟶ y yxwyxw StackInput...abb...

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} 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? 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.

Stack push and pop in PDA a, ε ⟶ t when you see an a in the input push t on the stack a, b ⟶ ε when you see an a in the input and b is on the top of the stack, pop b out.

A PDA for {a n b n : n ≥ 0} q0q0 q1q1 q3q3 q2q2 ε, ε ⟶ $ ε, $ ⟶ ε a, ε ⟶ a b, a ⟶ ε

Visualization of {a n b n :n ≥ 0} aaabbb q0q0 q1q1 q3q3 q2q2 ε, ε ⟶ $ ε, $ ⟶ ε a, ε ⟶ a b, a ⟶ ε

Visualization of {a n b n :n ≥ 0} aaabbb $ q0q0 q1q1 q3q3 q2q2 ε, ε ⟶ $ ε, $ ⟶ ε a, ε ⟶ a b, a ⟶ ε

Visualization of {a n b n :n ≥ 0} aaabbb a$a$ q0q0 q1q1 q3q3 q2q2 ε, ε ⟶ $ ε, $ ⟶ ε a, ε ⟶ a b, a ⟶ ε

Visualization of {a n b n :n ≥ 0} aaabbb aa$aa$ q0q0 q1q1 q3q3 q2q2 ε, ε ⟶ $ ε, $ ⟶ ε a, ε ⟶ a b, a ⟶ ε

Visualization of {a n b n :n ≥ 0} aaabbb aaa$aaa$ q0q0 q1q1 q3q3 q2q2 ε, ε ⟶ $ ε, $ ⟶ ε a, ε ⟶ a b, a ⟶ ε

Visualization of {a n b n :n ≥ 0} aaabbb aa$aa$ q0q0 q1q1 q3q3 q2q2 ε, ε ⟶ $ ε, $ ⟶ ε a, ε ⟶ a b, a ⟶ ε

Visualization of {a n b n :n ≥ 0} aaabbb a$a$ q0q0 q1q1 q3q3 q2q2 ε, ε ⟶ $ ε, $ ⟶ ε a, ε ⟶ a b, a ⟶ ε

Visualization of {a n b n :n ≥ 0} aaabbb $ q0q0 q1q1 q3q3 q2q2 ε, ε ⟶ $ ε, $ ⟶ ε a, ε ⟶ a b, a ⟶ ε

Visualization of {a n b n :n ≥ 0} aaabbb  q0q0 q1q1 q3q3 q2q2 ε, ε ⟶ $ ε, $ ⟶ ε a, ε ⟶ a b, a ⟶ ε

Visualization of {a n b n :n ≥ 0} aab q0q0 q1q1 q3q3 q2q2 ε, ε ⟶ $ ε, $ ⟶ ε a, ε ⟶ a b, a ⟶ ε

Visualization of {a n b n :n ≥ 0} aab $ q0q0 q1q1 q3q3 q2q2 ε, ε ⟶ $ ε, $ ⟶ ε a, ε ⟶ a b, a ⟶ ε

Visualization of {a n b n :n ≥ 0} aab a$a$ q0q0 q1q1 q3q3 q2q2 ε, ε ⟶ $ ε, $ ⟶ ε a, ε ⟶ a b, a ⟶ ε

Visualization of {a n b n :n ≥ 0} aab aa$aa$ q0q0 q1q1 q3q3 q2q2 ε, ε ⟶ $ ε, $ ⟶ ε a, ε ⟶ a b, a ⟶ ε

Visualization of {a n b n :n ≥ 0} aab a$a$ q0q0 q1q1 q3q3 q2q2 ε, ε ⟶ $ ε, $ ⟶ ε a, ε ⟶ a b, a ⟶ ε

Visualization of {a n b n :n ≥ 0} aab  a$a$ q0q0 q1q1 q3q3 q2q2 ε, ε ⟶ $ ε, $ ⟶ ε a, ε ⟶ a b, a ⟶ ε

Visualization of {a n b n :n ≥ 0} abb q0q0 q1q1 q3q3 q2q2 ε, ε ⟶ $ ε, $ ⟶ ε a, ε ⟶ a b, a ⟶ ε

Visualization of {a n b n :n ≥ 0} abb $ q0q0 q1q1 q3q3 q2q2 ε, ε ⟶ $ ε, $ ⟶ ε a, ε ⟶ a b, a ⟶ ε

Visualization of {a n b n :n ≥ 0} abb a$a$ q0q0 q1q1 q3q3 q2q2 ε, ε ⟶ $ ε, $ ⟶ ε a, ε ⟶ a b, a ⟶ ε

Visualization of {a n b n :n ≥ 0} abb $ q0q0 q1q1 q3q3 q2q2 ε, ε ⟶ $ ε, $ ⟶ ε a, ε ⟶ a b, a ⟶ ε

Visualization of {a n b n :n ≥ 0} abb  $ q0q0 q1q1 q3q3 q2q2 ε, ε ⟶ $ ε, $ ⟶ ε a, ε ⟶ a b, a ⟶ ε

PDA formally A PDA is a sextuple (Q, Σ, Γ, δ, q 0, F), where: – Q is the set of states – Σ is the input alphabet – Γ is the alphabet for the stack – δ is the transition function – q 0 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 (, ε ⟶ * ), * ⟶ ε q0q0 q1q1 ε, ε ⟶ $ ε, $ ⟶ ε

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 q0q0 q1q1 q2q2 ε, $ ⟶ ε 0, ε ⟶ * 1, * ⟶ ε q3q3 ε, ε ⟶ $ ε, $ ⟶ ε 1, ε ⟶ * 0, * ⟶ ε 1, ε ⟶ *

L = : equal number of 0s and 1s NPDA for this language 0, ε ⟶ 0 0, 1 ⟶ ε 1, ε ⟶ 1 1, 0 ⟶ ε q0q0 q1q1 ε, ε ⟶ $ ε, $ ⟶ ε

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 = {a n b n : n≥0} is recognized by some PDA. – L is not regular.

Non-Determinism Non- determinism means that we can have more than one choice. Non-Deterministic: q1q1 q2q2 0, a ⟶ 1 q3q3

Non-Determinism Non- determinism means that we can have more than one choice. Non-Deterministic: q1q1 q2q2 0, a ⟶ 0 q3q3 0, a ⟶ 1

Non-Determinism Non- determinism means that we can have more than one choice. Non-Deterministic: q1q1 q2q2 0, a ⟶ 0 0, a ⟶ 1

Non-Determinism Non- determinism means that we can have more than one choice. Non-Deterministic: q1q1 q2q2 0, ε ⟶ 0 q3q3 0, a ⟶ 1

Non-Determinism Non- determinism means that we can have more than one choices. Non-Deterministic: q1q1 q2q2 ε, b ⟶ 0 q3q3 0, b ⟶ 1

Non-Determinism Non- determinism means that we can have more than one choices. Deterministic: q1q1 q2q2 0, b ⟶ 0 q3q3 0, a ⟶ 1

Non-Determinism Non- determinism means that we can have more than one choices. Deterministic: q1q1 q2q2 ε, ε ⟶ 0 No other possible transitions

Definition of DPDA (deterministic push down automata) δ : Q x Σ ε x Γ ε  (Q x Γ ε ) U {φ} A DPDA has exactly one legal move in every situation where its stack is non empty Given any state q, any letter a, any stack letter x Only one of the following is allowed to be non empty δ(q,a,x) δ(q,a, ε) δ(q, ε, x) δ(q, ε, ε)

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: L R = { ww R : 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} * } q0q0 q1q1 q3q3 q2q2 ε, ε ⟶ $ ε, $ ⟶ ε 0, ε ⟶ 0 1, ε ⟶ 1 #, ε ⟶ ε 0, 0 ⟶ ε 1, 1 ⟶ ε

L R = { ww R : w in {0,1} * } q0q0 q1q1 q3q3 q2q2 ε, ε ⟶ $ ε, $ ⟶ ε 0, ε ⟶ 0 1, ε ⟶ 1 ε, ε ⟶ ε 0, 0 ⟶ ε 1, 1 ⟶ ε Compare the previous DPDA with this NPDA

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.