CSE 105 theory of computation

Slides:



Advertisements
Similar presentations
Chapter 5 Pushdown Automata
Advertisements

Pushdown Automata Section 2.2 CSC 4170 Theory of Computation.
C O N T E X T - F R E E LANGUAGES ( use a grammar to describe a language) 1.
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.
CS21 Decidability and Tractability
Introduction to Computability Theory
1 Introduction to Computability Theory Lecture7: PushDown Automata (Part 1) Prof. Amos Israeli.
CFG => PDA Sipser 2 (pages ). CS 311 Fall Formally… A pushdown automaton is a sextuple M = (Q, Σ, Γ, δ, q 0, F), where – Q is a finite set.
Costas Busch - RPI1 Pushdown Automata PDAs. Costas Busch - RPI2 Pushdown Automaton -- PDA Input String Stack States.
Courtesy Costas Busch - RPI1 Pushdown Automata PDAs.
CS 310 – Fall 2006 Pacific University CS310 Pushdown Automata Sections: 2.2 page 109 October 11, 2006.
CS 310 – Fall 2006 Pacific University CS310 Pushdown Automata Sections: 2.2 page 109 October 9, 2006.
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.
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.
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.
Pushdown Automata.
Pushdown Automata CS 130: Theory of Computation HMU textbook, Chap 6.
Pushdown Automata (PDAs)
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 11 Midterm Exam 2 -Context-Free Languages Mälardalen University 2005.
Complexity and Computability Theory I Lecture #11 Instructor: Rina Zviel-Girshin Lea Epstein.
1Computer Sciences Department. Book: INTRODUCTION TO THE THEORY OF COMPUTATION, SECOND EDITION, by: MICHAEL SIPSER Reference 3Computer Sciences Department.
Foundations of (Theoretical) Computer Science Chapter 2 Lecture Notes (Section 2.2: Pushdown Automata) Prof. Karen Daniels, Fall 2010 with acknowledgement.
Formal Languages, Automata and Models of Computation
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Pushdown.
Donghyun (David) Kim Department of Mathematics and Physics North Carolina Central University 1 Chapter 2 Context-Free Languages Some slides are in courtesy.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Pushdown.
1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 8 Mälardalen University 2011.
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.
Theory of Computation Automata Theory Dr. Ayman Srour.
Formal Languages, Automata and Models of Computation
Pushdown Automata.
Lecture 14 Push Down Automata (PDA)
CSE 105 theory of computation
CSE 105 theory of computation
Pushdown Automata PDAs
Pushdown Automata PDAs
Pushdown Automata PDAs
Pushdown Automata PDAs
Pushdown Automata.
Theory of Computation Lecture #27-28.
Chapter 7 PUSHDOWN AUTOMATA.
Pushdown Automata.
CSE 105 theory of computation
Pushdown Automata Reading: Chapter 6.
Intro to Theory of Computation
Intro to Theory of Computation
CSE 105 theory of computation
Intro to Data Structures
فصل دوم Context-Free Languages
Definition Moves of the PDA Languages of the PDA Deterministic PDA’s
Definition Moves of the PDA Languages of the PDA Deterministic PDA’s
Chapter 2 Context-Free Language - 01
CSE 105 theory of computation
… NPDAs continued.
CSE 105 theory of computation
CSE 105 theory of computation
CSE 105 theory of computation
Pushdown automata The Chinese University of Hong Kong Fall 2011
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
CSE 105 theory of computation
CSE 105 theory of computation
CSE 105 theory of computation
CSE 105 theory of computation
CSE 105 theory of computation
Presentation transcript:

CSE 105 theory of computation Fall 2017 http://cseweb.ucsd.edu/classes/fa17/cse105-a/

Review of CFG, CFL, ambiguity What is the language generated by the CFG below: G1 = ({S,T1,T2}, {0,1,2}, { S  T1 | T2, T1  0T11 | ε, T2  0T22 | ε }, S) In the grammar G2 = ({S}, {0,1}, { S  SS | 0 } , S) S  SS  0S  00 S  SS  S0  00 are both derivations of the string 00. Does this mean that G2 is ambiguous? Consider the string 000 S  SS  0SS  00S  000 S  SS  SSS  0SS  00S  000

Today's learning goals Sipser Ch 1.4, 2.1 Define push down automata Trace the computation of a push down automaton Design a push down automaton recognizing a given language Compare class of regular languages and class of CFLs

Context-free languages over Σ Birds' eye view All languages over Σ Context-free languages over Σ Regular languages over Σ Finite languages over Σ

Recap: Context-free languages Context-free grammar One-step derivation Derivation Language generated by grammar

An alternative … Sipser p. 109 NFA + stack

Pushdown automata Sipser p. 109 NFA + stack At each step 1. Transition to new state based on current state, letter read, and top letter of stack. 2. (Possibly) push or pop a letter to (or from) top of stack

Pushdown automata Sipser p. 109 NFA + stack Accept a string if there is some sequence of states and some sequence of stack contents which processes the entire input string and ends in an accepting state.

State diagram for PDA Sipser p. 109 If hand-drawn or in Sipser State transition labelled a, b  c means "when machine reads an a from the input and the top symbol of the stack is a b, it may replace the b with a c." In JFLAP use ; instead of 

State diagram for PDA Sipser p. 109 If hand-drawn or in Sipser State transition labelled a, b  c means "when machine reads an a from the input and the top symbol of the stack is a b, it may replace the b with a c." What edge label would indicate "Read a 0, don't pop anything from stack, don’t push anything to the stack"? 0, ε  ε ε, 0  ε ε, ε  0 ε  ε, 0 I don't know.

Formal definition of PDA Sipser Def 2.13 p. 111

Designing a PDA L = { 0i1i+1 | i ≥ 0 } Which of these CFGs generate L? Assume V = set of variables mentioned in rules; Σ={0,1}, S start S  ε | 0S1 S  ε | 0S11 S  T1 | 0S1, T  ε S  ε | 0T1, T  ε | 0T1 I don't know.

Designing a PDA L = { 0i1i+1 | i ≥ 0 } Informal description of PDA: Read symbols from the input. As each 0 is read, push it onto the stack. As soon as 1s are seen, pop a 0 off the stack for each 1 read. If the stack becomes empty and there is exactly one 1 left to read, read that 1 and accept the input. If the stack becomes empty and there are either zero or more than one 1s left to read, or if the 1s are finished while the stack still contains 0s, or if any 0s appear in the input following 1s, reject the input.

Useful trick What would ε, ε  $ mean? Without reading any input or popping any symbol from stack, push $ If the input string and stack are both empty strings, push $ At the end of reading the input string, push $ to top of stack I don't know.

Useful trick What would ε, ε  $ mean? Without reading any input or popping any symbol from stack, push $ If the input string and stack are both empty strings, push $ At the end of reading the input string, push $ to top of stack I don't know. Why is this useful? Commonly used from initial state (at start of computation) to record top of stack with a special symbol) "If the stack becomes empty and …"

Designing/Tracing a PDA L = { 0i1i+1 | i ≥ 0 } Sample computations? nondeterminism stack contents

PDAs and CFGs are equivalently expressive Theorem 2.20: A language is context-free if and only some nondeterministic PDA recognizes it. Consequences Quick proof that every regular language is context free To prove closure of class of CFLs under a given operation, can choose two modes of proof (via CFGs or PDAs) depending on which is easier

L = { aibjck | i=j or i=k, with i,j,k≥0 } Example L = { aibjck | i=j or i=k, with i,j,k≥0 } Which of the following strings are not in L? b abc abbcc aabcc I don't know.

Example L = { aibjck | i=j or i=k, with i,j,k≥0 } To design a CFG that generates L… L = { aibjck | i=j, with i,j,k≥0 } U { aibjck | i=k, with i,j,k≥0 }

Example L = { aibjck | i=j or i=k, with i,j,k≥0 } To design a CFG that generates L… L = { aibjck | i=j, with i,j,k≥0 } U { aibjck | i=k, with i,j,k≥0 } S  Sc | T T  aTb | ε

Example L = { aibjck | i=j or i=k, with i,j,k≥0 } To design a CFG that generates L… L = { aibjck | i=j, with i,j,k≥0 } U { aibjck | i=k, with i,j,k≥0 } S  T | aSc T  Tb | ε

L = { aibjck | i=j or i=k, with i,j,k≥0 } Designing a PDA L = { aibjck | i=j or i=k, with i,j,k≥0 } Informal description of PDA: How would you design an algorithm that, given a string, decides if it is in this set? What information do you need to track? How much memory do you need? Are you using non-determinism?

L = { aibjck | i=j or i=k, with i,j,k≥0 } Designing a PDA L = { aibjck | i=j or i=k, with i,j,k≥0 } Informal description of PDA: The PDA pushes a $ to indicate the top of the stack, then starts reading a's, pushing each one on to the stack. The PDA guesses when it's reached the end of the a's and whether to match the number of a's to the number of b's or the number of c's. If trying to match number of b's with number of a's: PDA pops off a's for each b read. If there are more a's on the stack but no more b's being read, reject. When the end of the stack ($) is reached, the number of a's matches the number of b's. If this is the end of the input or if any number of c's is read at this point, accept; otherwise, reject. If trying to match the number of c's with number of a's: first read any number of b's without changing stack contents and then nondeterministically guess when to start reading c's. For each c read, pop one a off the stack. When the end of the stack ($) is reached the number of a's and c's so far match.

L = { aibjck | i=j or i=k, with i,j,k≥0 } Designing a PDA L = { aibjck | i=j or i=k, with i,j,k≥0 } Formal definition of PDA:

Conventions for PDAs Can "test for end of stack" without providing details We can always push the end-of-stack symbol, $, at the start. Can "test for end of input" without providing details Can transform PDA to one where accepting states are only those reachable when there are no more input symbols. Don't always need to provide a state transition diagram!