CSE 105 THEORY OF COMPUTATION

Similar documents
CSE 105 THEORY OF COMPUTATION

CSE 105 THEORY OF COMPUTATION

Context-Free Languages

CSE 105 THEORY OF COMPUTATION

CPS 220 Theory of Computation Pushdown Automata (PDA)

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

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

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

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

CSE 105 THEORY OF COMPUTATION

CSE 105 THEORY OF COMPUTATION

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

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

CSE 105 THEORY OF COMPUTATION

Pushdown Automata: Introduction (2)

COM364 Automata Theory Lecture Note 2 - Nondeterminism

Computational Models - Lecture 4

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

Theory of Computation (IV) Yijia Chen Fudan University

Pushdown Automata (2015/11/23)

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

Pushdown Automata. Chapter 12

CSE 105 THEORY OF COMPUTATION

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

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

CISC4090: Theory of Computation

Lecture 17: Language Recognition

CS 154. Finite Automata, Nondeterminism, Regular Expressions

Introduction to Theory of Computing

Foundations of Informatics: a Bridging Course

Accept or reject. Stack

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

Pushdown Automata (Pre Lecture)

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

Computational Models - Lecture 5 1

Computability Theory

MA/CSSE 474 Theory of Computation

PS2 - Comments. University of Virginia - cs3102: Theory of Computation Spring 2010

CSE 105 THEORY OF COMPUTATION

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

CSE 105 THEORY OF COMPUTATION. Spring 2018 review class

(pp ) PDAs and CFGs (Sec. 2.2)

Languages, regular languages, finite automata

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

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

Finite Automata Part Two

Automata and Computability. Solutions to Exercises

Nondeterministic Finite Automata

CISC 4090 Theory of Computation

CSE 135: Introduction to Theory of Computation Nondeterministic Finite Automata (cont )

CS 154, Lecture 3: DFA NFA, Regular Expressions

Automata and Computability. Solutions to Exercises

Intro to Theory of Computation

5 Context-Free Languages

Computability Theory

Chapter Five: Nondeterministic Finite Automata

CSE 311: Foundations of Computing. Lecture 23: Finite State Machine Minimization & NFAs

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

CSE 105 Theory of Computation

Decidability. Human-aware Robotics. 2017/10/31 Chapter 4.1 in Sipser Ø Announcement:

CS21 Decidability and Tractability

CISC 4090 Theory of Computation

Turing Machines Part III

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,

Equivalence of CFG s and PDA s

Theory Bridge Exam Example Questions

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

Clarifications from last time. This Lecture. Last Lecture. CMSC 330: Organization of Programming Languages. Finite Automata.

Theory of Computation

CS375: Logic and Theory of Computing

Computability and Complexity

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

CSE 105 THEORY OF COMPUTATION

Part I: Definitions and Properties

THEORY OF COMPUTATION (AUBER) EXAM CRIB SHEET

Nondeterminism. September 7, Nondeterminism

CS Pushdown Automata

CSE 105 THEORY OF COMPUTATION

NPDA, CFG equivalence

MTH401A Theory of Computation. Lecture 17

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

Computational Models Lecture 5

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

Lecture 4: Nondeterministic Finite Automata

Push-down Automata = FA + Stack

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

CSE 135: Introduction to Theory of Computation Nondeterministic Finite Automata

Theory of Computation

Lecture 3: Nondeterministic Finite Automata

Computational Models: Class 5

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

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

CS 301. Lecture 18 Decidable languages. Stephen Checkoway. April 2, 2018

CSE 105 Theory of Computation Professor Jeanne Ferrante

Introduction to Languages and Computation

Final exam study sheet for CS3719 Turing machines and decidability.

CSE 105 THEORY OF COMPUTATION

Section 1 (closed-book) Total points 30

CSE 105 THEORY OF COMPUTATION

Properties of Context-Free Languages. Closure Properties Decision Properties

Transcription:

CSE 105 THEORY OF COMPUTATION Spring 2017 http://cseweb.ucsd.edu/classes/sp17/cse105-ab/

Review of CFG, CFL, ambiguity What is the language generated by the CFG below: G 1 = ({S,T 1,T 2 }, {0,1,2}, { S T 1 T 2, T 1 0T 1 1 ε, T 2 0T 2 2 ε }, S) In the grammar G 2 = ({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 G 2 is ambiguous?

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

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.

Designing a PDA L = { 0 i 1 i+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.

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"? A. 0, ε ε B. ε, 0 ε C. ε, ε 0 D. ε ε, 0 E. I don't know.

Formal definition of PDA Sipser Def 2.13 p. 111

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

Useful trick What would ε, ε $ mean? A. Without reading any input or popping any symbol from stack, push $ B. If the input string and stack are both empty strings, push $ C. At the end of reading the input string, push $ to top of stack D. 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 = { 0 i 1 i+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

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

Example L = { a i b j c k i=j or i=k, with i,j,k 0 } Which of the following strings are not in L? A. b B. abc C. abbcc D. aabcc E. I don't know.

Example L = { a i b j c k i=j or i=k, with i,j,k 0 } To design a CFG that generates L L = { a i b j c k i=j, with i,j,k 0 } U { a i b j c k i=k, with i,j,k 0 }

Example L = { a i b j c k i=j or i=k, with i,j,k 0 } To design a CFG that generates L L = { a i b j c k i=j, with i,j,k 0 } U { a i b j c k i=k, with i,j,k 0 } S Sc T T atb ε

Example L = { a i b j c k i=j or i=k, with i,j,k 0 } To design a CFG that generates L L = { a i b j c k i=j, with i,j,k 0 } U { a i b j c k i=k, with i,j,k 0 } S T asc T Tb ε

Designing a PDA L = { a i b j c k 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?

Designing a PDA L = { a i b j c k 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.

Designing a PDA L = { a i b j c k 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!