Pushdown Automata (PDA) The structure and the content of the lecture is based on

Similar documents
Accept or reject. Stack

Pushdown Automata (2015/11/23)

CSE 211. Pushdown Automata. CSE 211 (Theory of Computation) Atif Hasan Rahman

UNIT-VI PUSHDOWN AUTOMATA

CPS 220 Theory of Computation Pushdown Automata (PDA)

CS Pushdown Automata

Equivalence of CFG s and PDA s

60-354, Theory of Computation Fall Asish Mukhopadhyay School of Computer Science University of Windsor

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 tree u,

October 6, Equivalence of Pushdown Automata with Context-Free Gramm

Harvard CS 121 and CSCI E-207 Lecture 10: Ambiguity, Pushdown Automata

Pushdown Automata: Introduction (2)

CSE 105 THEORY OF COMPUTATION

(pp ) PDAs and CFGs (Sec. 2.2)

Context-Free Languages

Theory of Computation (IV) Yijia Chen Fudan University

TAFL 1 (ECS-403) Unit- IV. 4.1 Push Down Automata. 4.2 The Formal Definition of Pushdown Automata. EXAMPLES for PDA. 4.3 The languages of PDA

Pushdown Automata (Pre Lecture)

Harvard CS 121 and CSCI E-207 Lecture 10: CFLs: PDAs, Closure Properties, and Non-CFLs

(pp ) PDAs and CFGs (Sec. 2.2)

Pushdown automata. Twan van Laarhoven. Institute for Computing and Information Sciences Intelligent Systems Radboud University Nijmegen

CS5371 Theory of Computation. Lecture 7: Automata Theory V (CFG, CFL, CNF)

Introduction to Formal Languages, Automata and Computability p.1/42

THEORY OF COMPUTATION (AUBER) EXAM CRIB SHEET

CSE 105 THEORY OF COMPUTATION

Computational Models - Lecture 5 1

Fundamentele Informatica II

Pushdown Automata. Pushdown Automata. Pushdown Automata. Pushdown Automata. Pushdown Automata. Pushdown Automata. The stack

Foundations of Informatics: a Bridging Course

Outline. CS21 Decidability and Tractability. Machine view of FA. Machine view of FA. Machine view of FA. Machine view of FA.

CISC4090: Theory of Computation

Pushdown Automata. Reading: Chapter 6

Pushdown Automata. Notes on Automata and Theory of Computation. Chia-Ping Chen

Introduction to Theory of Computing

Einführung in die Computerlinguistik

Theory of Computation

CFGs and PDAs are Equivalent. We provide algorithms to convert a CFG to a PDA and vice versa.

MTH401A Theory of Computation. Lecture 17

Computational Models - Lecture 4

Homework. Context Free Languages. Announcements. Before We Start. Languages. Plan for today. Final Exam Dates have been announced.

5 Context-Free Languages

Push-down Automata = FA + Stack

Context-free Languages and Pushdown Automata

This lecture covers Chapter 6 of HMU: Pushdown Automata

CS375: Logic and Theory of Computing

Fooling Sets and. Lecture 5

Miscellaneous. Closure Properties Decision Properties

Properties of Context-Free Languages. Closure Properties Decision Properties

Computational Models: Class 5

Section 1 (closed-book) Total points 30

CS481F01 Prelim 2 Solutions

Definition: A grammar G = (V, T, P,S) is a context free grammar (cfg) if all productions in P have the form A x where

Lecture 17: Language Recognition

2.1 Solution. E T F a. E E + T T + T F + T a + T a + F a + a

Please give details of your answer. A direct answer without explanation is not counted.

HKN CS/ECE 374 Midterm 1 Review. Nathan Bleier and Mahir Morshed

Pushdown Automata. Chapter 12

THE AUSTRALIAN NATIONAL UNIVERSITY Second Semester COMP2600/COMP6260 (Formal Methods for Software Engineering)

Automata Theory (2A) Young Won Lim 5/31/18

Intro to Theory of Computation

SCHEME FOR INTERNAL ASSESSMENT TEST 3

Finite Automata. Finite Automata

CFG and PDA accept the same languages

Computability and Complexity

Lecture 13: Turing Machine

FORMAL LANGUAGES, AUTOMATA AND COMPUTATION

Theory of Computation Turing Machine and Pushdown Automata

Turing Machines Part II

AC68 FINITE AUTOMATA & FORMULA LANGUAGES DEC 2013

PUSHDOWN AUTOMATA (PDA)

Formal Languages and Automata

Automata and Computability. Solutions to Exercises

CSE 105 Theory of Computation

Context Free Languages (CFL) Language Recognizer A device that accepts valid strings. The FA are formalized types of language recognizer.

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

CISC 4090 Theory of Computation

Automata and Formal Languages. Push Down Automata. Sipser pages Lecture 13. Tim Sheard 1

COMP-330 Theory of Computation. Fall Prof. Claude Crépeau. Lec. 10 : Context-Free Grammars

CS21 Decidability and Tractability

Undecidable Problems and Reducibility

Automata and Computability. Solutions to Exercises

Part I: Definitions and Properties

CS Rewriting System - grammars, fa, and PDA

Deterministic Finite Automata. Non deterministic finite automata. Non-Deterministic Finite Automata (NFA) Non-Deterministic Finite Automata (NFA)

ECS 120: Theory of Computation UC Davis Phillip Rogaway February 16, Midterm Exam

Turing Machines (TM) Deterministic Turing Machine (DTM) Nondeterministic Turing Machine (NDTM)

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

CS481F01 Solutions 6 PDAS

CSE 105 THEORY OF COMPUTATION

SYLLABUS. Introduction to Finite Automata, Central Concepts of Automata Theory. CHAPTER - 3 : REGULAR EXPRESSIONS AND LANGUAGES

Lecture III CONTEXT FREE LANGUAGES

CSE 105 Homework 5 Due: Monday November 13, Instructions. should be on each page of the submission.

CpSc 421 Final Exam December 15, 2006

CPSC 421: Tutorial #1

CS5371 Theory of Computation. Lecture 9: Automata Theory VII (Pumping Lemma, Non-CFL, DPDA PDA)

CISC 4090 Theory of Computation

Theory of Computation - Module 3

Properties of Context-free Languages. Reading: Chapter 7

Automata Theory - Quiz II (Solutions)

The Idea of a Pushdown Automaton

Transcription:

Pushdown Automata (PDA) The structure and the content of the lecture is based on http://www.eecs.wsu.edu/~ananth/cpts317/lectures/index.htm 1

Excursion: Previous lecture n Context-free grammar G=(V,T,P,S), where: n n n n V: set of variables or non-terminals T: set of terminals (= alphabet U {e}) P: set of productions, each of which is of the form V ==> a 1 a 2 n Where each a i is an arbitrary string of variables and terminals S ==> start variable Regular (FA/RE) Contextfree (PDA/CFG) 2

PDA - the automata for CFLs n What is? n FA to Reg Lang, PDA is to CFL n PDA == [ e -NFA + a stack ] n Why a stack? Input string e-nfa Accept/reject A stack filled with stack symbols 3

Pushdown Automata - Definition n A PDA P := ( Q,,G, δ,q 0,Z 0,F ): n Q: states of the e-nfa n : input alphabet n G : stack symbols n δ: transition function n q 0 : start state n Z 0 : Initial stack top symbol n F: Final/accepting states 4

old state input symb. Stack top new state(s) new Stack top(s) δ : Q x x G => Q x G δ : The Transition Function δ(q,a,x) = {(p,y), } 1. state transition from q to p 2. a is the next input symbol 3. X is the current stack top symbol 4. Y is the replacement for X; it is in G* (a string of stack symbols) i. Set Y = e for: Pop(X) ii. If Y=X: stack top is unchanged iii. If Y=Z 1 Z 2 Z k : X is popped and is replaced by Y in reverse order (i.e., Z 1 will be the new stack top) q a Y =? p X Action i) Y=e Pop(X) ii) Y=X Pop(X) Push(X) iii) Y=Z 1 Z 2..Z k Pop(X) Push(Z k ) Push(Z k-1 ) Push(Z 2 ) Push(Z 1 ) Y 5

Example (palindrome) Let L wwr = {ww R w is in {0,1}*} n CFG for L wwr : S==> 0S0 1S1 e n PDA for L wwr : n P := ( Q,, G, δ,q 0,Z 0,F ) = ( {q 0, q 1, q 2 },{0,1},{0,1,Z 0 },δ,q 0,Z 0,{q 2 }) Mark the botom of the stack 6

Initial state of the PDA: PDA for L wwr Stack top Z 0 q 0 1. δ(q 0,0, Z 0 )={(q 0,0Z 0 )} 2. δ(q 0,1, Z 0 )={(q 0,1Z 0 )} 3. δ(q 0,0, 0)={(q 0,00)} 4. δ(q 0,0, 1)={(q 0,01)} 5. δ(q 0,1, 0)={(q 0,10)} 6. δ(q 0,1, 1)={(q 0,11)} 7. δ(q 0, e, 0)={(q 1, 0)} 8. δ(q 0, e, 1)={(q 1, 1)} 9. δ(q 0, e, Z 0 )={(q 1, Z 0 )} 10. δ(q 1,0, 0)={(q 1, e)} 11. δ(q 1,1, 1)={(q 1, e)} 12. δ(q 1, e, Z 0 )={(q 2, Z 0 )} First symbol push on stack Grow the stack by pushing new symbols on top of old (w-part) Switch to popping mode, nondeterministically (boundary between w and w R ) Shrink the stack by popping matching symbols (w R -part) Enter acceptance state 7

PDA as a state diagram δ(q i,a, X)={(q j,y)} Current state Next input symbol Current stack top Stack Top Replacement (w/ string Y) q i a, X / Y q j Next state 8

PDA for L wwr : Transition Diagram Grow stack 0, Z 0 /0Z 0 1, Z 0 /1Z 0 0, 0/00 0, 1/01 1, 0/10 1, 1/11 Pop stack for matching symbols 0, 0/ e 1, 1/ e = {0, 1} G= {Z 0, 0, 1} Q = {q 0,q 1,q 2 } e, Z 0 /Z 0 q 0 q 1 q 2 e, Z 0 /Z 0 e, 0/0 e, 1/1 Switch to popping mode Non-deterministic PDA: 2 output transitions i.e. e, Z 0 /Z 0 Go to acceptance Push input symbols onto the stack Non-deterministically move to a popping state (with or without consuming a single input symbol) If next input symbol is same as top of stack, pop If Z 0 on top of stack move to accept state 9

How does the PDA for L wwr work on input 1111? Instantaneous (q 0,1111,Z 0 ) Description (ID) (q 0,111,1Z 0 ) All moves made by the non-deterministic PDA (q 1,1111,Z 0 ) Path dies (q 0,11,11Z 0 ) (q 1,111,1Z 0 ) Path dies (q 0,1,111Z 0 ) (q 1,11,11Z 0 ) (q 0,e,1111Z 0 ) (q 1,1,111Z 0 ) (q 1,1,1Z 0 ) Acceptance by final state: (q 1, e,1111z 0 ) (q 1, e,11z 0 ) Path dies Path dies (q 1, e,z 0 ) (q 2, e,z 0 ) = empty input AND final state 10

Example 2: language of balanced paranthesis Grow stack (, Z 0 / ( Z 0 (, ( / ( ( Pop stack for matching symbols ), ( / e = { (, ) } G= {Z 0, ( } Q = {q 0,q 1,q 2 } e, Z 0 / Z 0 Switch to popping mode q 0 q 1 q 2 ), ( / e e, Z 0 / Z 0 e, Z 0 / Z 0 (, ( / ( ( (, Z 0 / ( Z 0 Go to acceptance (by final state) when you see the stack bottom symbo On seeing a ( push it onto the stack On seeing a ) pop if a ( is in the stack To allow adjacent blocks of nested paranthesis 11

Example 2: language of balanced paranthesis (another design) (,Z 0 / ( Z 0 (,( / ( ( ), ( / e = { (, ) } G= {Z 0, ( } Q = {q 0,q 1 } start q 0 e,z 0 / Z 0 q 1 e,z 0 / Z 0 12

There are two types of PDAs that one can design: those that accept by final state or by empty stack Acceptance by n PDAs that accept by final state: n For a PDA P, the language accepted by P, denoted by L(P) by final state, is: n {w (q 0,w,Z 0 ) ---* (q,e, A) }, s.t., q Î F Checklist: - input exhausted? - in a final state? n PDAs that accept by empty stack: n For a PDA P, the language accepted by P, denoted by N(P) by empty stack, is: n {w (q 0,w,Z 0 ) ---* (q, e, e) }, for any q Î Q. Q) Does a PDA that accepts by empty stack need any final state specified in the design? Checklist: - input exhausted? - is the stack empty? 13

Example: L of balanced parenthesis PDA that accepts by final state P F : P N : (,Z 0 / ( Z 0 (,( / ( ( ), ( / e An equivalent PDA that accepts by empty stack (,Z 0 / ( Z 0 (, ( / ( ( ), ( / e e,z 0 / e start e,z 0 / Z 0 q 0 e,z 0 / Z 0 q 1 start e,z 0 / Z 0 q 0 How will these two PDAs work on the input: ( ( ( ) ) ( ) ) ( ) 14

Equivalence of PDAs and CFGs 15

CFGs == PDAs ==> CFLs PDA by final state PDA by empty stack? CFG 16

This is same as: implementing a CFG using a PDA Converting CFG to PDA Main idea: The PDA simulates the leftmost derivation on a given w, and upon consuming it fully it either arrives at acceptance (by empty stack) or non-acceptance. INPUT w PDA (acceptance by empty stack) accept reject OUTPUT implements CFG 17

This is same as: implementing a CFG using a PDA Converting a CFG into a PDA Main idea: The PDA simulates the leftmost derivation on a given w, and upon consuming it fully it either arrives at acceptance (by empty stack) or non-acceptance. Steps: 1. Push the right hand side of the production onto the stack, with leftmost symbol at the stack top 2. If stack top is the leftmost variable, then replace it by all its productions (each possible substitution will represent a distinct path taken by the non-deterministic PDA) 3. If stack top has a terminal symbol, and if it matches with the next symbol in the input string, then pop it. 18

Formal construction of PDA Before: A Before: a from CFG n Given: G= (V,T,P,S) n Output: P N = ({q}, T, V U T, δ, q, S) n δ: n For all A Î V, add the following transition(s) in the PDA: n δ(q, e,a) = { (q, a) A ==>a Î P} n For all a Î T, add the following transition(s) in the PDA: n δ(q,a,a)= { (q, e ) } Note: Initial stack symbol (S) same as the start variable in the grammar ( Q,, G, δ,q 0,Z 0,F ) After: After: a a a pop 19

Example: CFG to PDA n G = ( {S,A}, {0,1}, P, S) n P: n S ==> AS e n A ==> 0A1 A1 01 e,s / S n PDA = ({q}, {0,1}, {0,1,A,S}, δ, q, S) n δ: n δ(q, e, S) = { (q, AS), (q, e )} n δ(q, e, A) = { (q,0a1), (q,a1), (q,01) } n δ(q, 0, 0) = { (q, e ) } n δ(q, 1, 1) = { (q, e ) } How will this new PDA work? 1,1 / e 0,0 / e e,a / 01 e,a / A1 e,a / 0A1 e,s / e e,s / AS Lets simulate string 0011 q 20

Simulating string 0011 on the new PDA Leftmost deriv.: PDA (δ): δ(q, e, S) = { (q, AS), (q, e )} δ(q, e, A) = { (q,0a1), (q,a1), (q,01) } δ(q, 0, 0) = { (q, e ) } δ(q, 1, 1) = { (q, e ) } Stack moves (shows only the successful path): e,s / S 1,1 / e 0,0 / e e,a / 01 e,a / A1 e,a / 0A1 e,s / e e,s / AS q S => AS => 0A1S => 0011S => 0011 S A S 0 A 1 S A 1 S 0 0 1 1 S 1 1 S 0 1 S 1 S 1 e Accept by empty stack S =>AS =>0A1S =>0011S => 0011 21

Summary n PDA n Definition n With acceptance by final state n With cceptance by empty stack n PDA (by final state) = PDA (by empty stack) <== CFG n CFG ==> PDA (next lecture ) 22