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

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

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

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,

Languages. Non deterministic finite automata with ε transitions. First there was the DFA. Finite Automata. Non-Deterministic Finite Automata (NFA)

CSE 105 THEORY OF COMPUTATION

CSE 105 THEORY OF COMPUTATION

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

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

CPS 220 Theory of Computation Pushdown Automata (PDA)

Computability and Complexity

Pushdown Automata: Introduction (2)

Languages, regular languages, finite automata

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

Theory of Computation

Context-Free Languages

Fundamentele Informatica II

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

CISC4090: Theory of Computation

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

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

Pushdown Automata. Chapter 12

Pushdown Automata (2015/11/23)

Theory of Computation Turing Machine and Pushdown Automata

CS Pushdown Automata

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

Nondeterministic Finite Automata

CSE 105 THEORY OF COMPUTATION

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

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

Rumination on the Formal Definition of DPDA

Einführung in die Computerlinguistik

Part I: Definitions and Properties

Part 4 out of 5 DFA NFA REX. Automata & languages. A primer on the Theory of Computation. Last week, we showed the equivalence of DFA, NFA and REX

C6.2 Push-Down Automata

Pushdown Automata (Pre Lecture)

Recap DFA,NFA, DTM. Slides by Prof. Debasis Mitra, FIT.

Equivalent Variations of Turing Machines

Chapter 1. Formal Definition and View. Lecture Formal Pushdown Automata on the 28th April 2009

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

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

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

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

Automata and Languages

Automata and Computability. Solutions to Exercises

Computational Models - Lecture 5 1

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

Theory of Computation (IV) Yijia Chen Fudan University

Automata Theory CS F-04 Non-Determinisitic Finite Automata

Section 1 (closed-book) Total points 30

Context-free Languages and Pushdown Automata

input tape head moves current state a a

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

COM364 Automata Theory Lecture Note 2 - Nondeterminism

Pushdown Automata. Reading: Chapter 6

UNIT-VI PUSHDOWN AUTOMATA

THEORY OF COMPUTATION (AUBER) EXAM CRIB SHEET

AC68 FINITE AUTOMATA & FORMULA LANGUAGES DEC 2013

The Pumping Lemma. for all n 0, u 1 v n u 2 L (i.e. u 1 u 2 L, u 1 vu 2 L [but we knew that anyway], u 1 vvu 2 L, u 1 vvvu 2 L, etc.

Automata and Computability. Solutions to Exercises

Theory of Computation

UNIT-I. Strings, Alphabets, Language and Operations

Lecture 17: Language Recognition

Finite Automata. Finite Automata

Turing s thesis: (1930) Any computation carried out by mechanical means can be performed by a Turing Machine

MA/CSSE 474 Theory of Computation

Automata Theory - Quiz II (Solutions)

Notes for Comp 497 (Comp 454) Week 12 4/19/05. Today we look at some variations on machines we have already seen. Chapter 21

Theory of Computation - Module 3

Chap. 1.2 NonDeterministic Finite Automata (NFA)

Push-down Automata = FA + Stack

5 Context-Free Languages

Pushdown Automata. We have seen examples of context-free languages that are not regular, and hence can not be recognized by finite automata.

Chapter Five: Nondeterministic Finite Automata

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

Theory Bridge Exam Example Questions

SCHEME FOR INTERNAL ASSESSMENT TEST 3

Computational Models - Lecture 4

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

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

Homework. Turing Machines. Announcements. Plan for today. Now our picture looks like. Languages

Before We Start. Turing Machines. Languages. Now our picture looks like. Theory Hall of Fame. The Turing Machine. Any questions? The $64,000 Question

CS375: Logic and Theory of Computing

Formal Definition of a Finite Automaton. August 26, 2013

MTH401A Theory of Computation. Lecture 17

(pp ) PDAs and CFGs (Sec. 2.2)

Intro to Theory of Computation

Finite Automata. Wen-Guey Tzeng Computer Science Department National Chiao Tung University

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

Fundamentele Informatica 3 Antwoorden op geselecteerde opgaven uit Hoofdstuk 7 en Hoofdstuk 8

CpSc 421 Final Exam December 15, 2006

Further discussion of Turing machines

Automata: a short introduction

Section: Pushdown Automata

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

CISC 4090 Theory of Computation

CISC 4090: Theory of Computation Chapter 1 Regular Languages. Section 1.1: Finite Automata. What is a computer? Finite automata

CS 154, Lecture 2: Finite Automata, Closure Properties Nondeterminism,

CSE 105 THEORY OF COMPUTATION

CSC236 Week 11. Larry Zhang

Lecture 13: Turing Machine

Transcription:

A pushdown automata (PDA) is essentially: An NFA with a stack A move of a PDA will depend upon Current state of the machine Current symbol being read in Current symbol popped off the top of the stack With each move, the machine can Move into a new state Push symbols on to the stack Input tape 1 2 3 5 4 State machine Stack The stack The stack has its own alphabet Included in this alphabet is a special symbol used to indicate an empty stack. (z) Note that the basic PDA is nondeterministic! Let s formalize this: A pushdown automata (PDA) is a 7-tuple: M = (Q, Σ, Γ, δ, q 0, z, F) where Q = finite set of states Σ = tape alphabet Γ = stack alphabet (may have symbols in common w/ Σ) q 0 Q = start state z Γ = initial stack symbol F Q = set of accepting states δ = transition function About this transition function δ: During a move of a PDA: At most one character is read from the input tape λ transitions are okay The topmost character is popped from the stack The machine will move to a new state based on: The character read from the tape The character popped off the stack The current state of the machine 0 or more symbols from the stack alphabet are pushed onto the stack. 1

Formally: δ: Q x (Σ {λ}) x Γ (finite subsets of Q x Γ * ) Domain: Q = state (Σ {λ}) = symbol read off tape Γ = symbol popped off stack Range Q = new state Γ * = symbols pushed onto the stack Example: δ (q, a, a ) = ( p, aa) Meaning: When in state q, Reading in an a from the tape With an a popped off the stack The machine will Go into state p Push the string aa onto the stack Configuration of a PDA Gives the current configuration of the machine (p, x, α) where p is the current state x is a string indicating what remains to be read on the tape α is the current contents of the stack. Move of a PDA: We can describe a single move of a PDA: (q, x, α) a(p, y, β) If: x = ay, α = γx, β = YX And δ (q, x, γ) includes (p, Y) or δ (q, ε, γ) includes (p, Y) and x = y. Moves of a PDA We can write: (q, x, α) a * (p, y, β) If You can get from one configuration to the other by applying 0 or more moves. Strings accepted by a PDA by Final State Start at (q 0, x, z) Start state q 0 X on the input tape Empty stack End with (q, λ, β) End in an accepting state (q F) All characters of x have been read Some string on the stack (doesn t matter what). 2

Strings accepted by a PDA (Final State) Let M = (Q, Σ, Γ, δ, q 0,z, F) be a PDA x is accepted by M if (q 0, x, z) a * (q, λ, β) Where q F β Γ * The language accepted by a PDA Let M = (Q, Σ, Γ, q 0, z, F, δ) be a PDA The language accepted by M by final state, Denoted L(M) is The set of all strings x that are accepted by M by final state Let s look at an example: L = { xcx r x { a,b } * } Let s look at an example: L = { xcx r x { a,b } * } Basic idea for building a PDA Read chars off the tape until you reach the c. As you read chars push them on the stack After reading the c, match the chars read with the chars popped off the stack until all chars are read If at any point the char read does not match the char popped, the machine crashes The PDA will have 4 states State 0 (initial) : reading before the c State 1: read the c State 2 :read after c, comparing chars State 3: (accepting): move only after all chars read and stack empty b, z / b z a, z / a z b, b / bb a, b / ab b, a / ba Let s look at an example: L = { xcx r x { a,b } * } q 0 q 1 q 2 a, a / aa c, z / z c, a / a c, b / b λ, a / a λ, b / b b, b / λ a, a / λ q 3 PDA Example Transition for abcba (q 0, abcba, Z) a(q 0, bcba, a) // push a a(q 0, cba, ba) // push b a(q 1, ba, ba) // goto 1 a(q 2, ba, ba) // λ trans a(q 2, a, a) // pop b a(q 2, λ, z) // pop a a(q 3, λ, z) // Accept! 3

PDA Example Transition for abcb (q 0, abcb, z) a(q 0, bcb, a) // push a a(q 0, cb, ba) // push b a(q 1, b, ba) // goto 1 a(q 2, b, ba) // ε trans a(q 2, λ, a) // pop b Nowhere to go // Reject! I bet you re wondering if JFLAP can handle PDAs! Yes, it can Let s take a look. Let s look at another example: L = { xx r x { a,b } * } Basic idea for building a PDA Much like last example, except This time we don t know when to start popping and comparing Since PDAs are non-deterministic, this is not a problem Let s look at another example: L = { xx r x { a,b } * } The PDA will have 3 states State 0 (initial) : reading before the center of string State 1: read after center of string, comparing chars State 2 (accepting): after all chars read, stack should be empty The machine can choose to go from state 0 to state 1 at any time: Will result in many wrong set of moves All you need is one right set of moves for a string to be accepted. PDA Example b, z / b z a, z / a z b, b / bb a, b / ab b, a / ba Let s look at an example: L = { xx r x { a,b } * } q 0 q 1 a, a / aa λ, a / a λ, b / b b, b / λ a, a / λ q 2 Let s see a bad transition set for abba (q 0, abba,z) a(q 0, bba, a) // push a a(q 0, ba, ba) // push b a(q 0, a, bba) // push b a(q 1, a, bba) // λ trans Nowhere to go // Reject! 4

PDA Example Let s see a good transition set for abba (q 0, abba, z) a(q 0, bba, a) // push a a(q 0, ba, ba) // push b a(q 1, ba, ba) // ε trans a(q 1, a, a) // pop b a(q 1, λ, Z) // pop a a(q 2, λ, Z) // Accept! Let s go to the video tape Actually JFLAP Strings accepted by a PDA by Final State Start at (q 0, x, z) Start state q 0 X on the input tape Empty stack End with (q, λ, β) End in an accepting state (q F) All characters of x have been read Some string on the stack (doesn t matter what). Strings accepted by a PDA (Final State) Let M = (Q, Σ, Γ, δ, q 0, z, F) be a PDA x is accepted by M if (q 0, x, z) a * (q, λ, β) Where q A β Γ * Strings accepted by a PDA by Empty Stack Start at (q 0, x, z) Start state q 0 X on the input tape Empty stack End with (q, λ, λ) End in any state All characters of x have been read Stack is empty Strings accepted by a PDA (Empty Stack) Let M = (Q, Σ, Γ, δ, q 0, z, F) be a PDA x is accepted by M if (q 0, x, z) a * (q, λ, λ) Where q Q 5

The language accepted by a PDA Let M = (Q, Σ, Γ, q 0, z, F, δ) be a PDA The language accepted by M by final state, Denoted L(M) is The set of all strings x that are accepted by M by final state The language accepted by M by empty stack, Denoted N(M) is The set of all strings x that are accepted by M by empty stack We will show that all languages accepted by a PDA by final state will be accepted by an equivalent PDA by empty stack and visa versa Final State vs. Empty Stack The two means by which a PDA can accept are equivalent wrt the class of languages accepted Given a PDA M such that L = L(M), there exists a PDA M such that L = N(M ) Given a PDA M such that L = N(M), there exists a PDA M such that L = L(M ) Final State Empty Stack Final State Empty Stack Given a PDA P F = (Q, Σ, Γ,δ F, q 0, z,f) and L = L (P F ) then there exists a PDA P N such that L = N (P N ) We will build such a PDA Accept by Empty Stack Final State Empty Stack Basic idea Transitions of P N will mimic those of P F Create a new state in P N that will empty the stack. The machine can move into this new state whenever the machine is in an accepting state of P F Accept by Empty Stack Final State Empty Stack Final State Empty Stack We must be careful though P F may crash when the stack is empty. In those cases we need to assure that P N does not accept To solve this: Create a new empty stack symbol X 0 which is placed on the stack before P F s empty stack marker (z) z will only be popped by the new stack emptying state The first move of P N will be to place zx 0 on P N stack. Final State Empty Stack P N = ( Q {p o, p}, Σ, Γ {X 0 } δ N p 0, X 0 ) 6

Accept by Empty Stack Final State Empty Stack Empty Stack Final State Empty Stack Final State Given a PDA P N = (Q, Σ, Γ,δ N, q 0, Z 0 ) and L = N (P N ) then there exists a PDA P F such that L = L (P F ) We will build such a PDA Actually, you will Exercise 17 Reality Check Next time NFAs with a stack Move depends on tape symbol, state, and top of stack. Move involves popping stack, moving to new state and pushing onto stack Basic PDA is nod-deterministic. PDAs the perfect machine for CFLs Questions? Accept by final state Accept by empty stack 7