Context-Free Languages

Similar documents
CSE 105 THEORY OF COMPUTATION

CSE 105 THEORY OF COMPUTATION

CPS 220 Theory of Computation Pushdown Automata (PDA)

Pushdown Automata (Pre Lecture)

Computability Theory

Introduction to Theory of Computing

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

CS:4330 Theory of Computation Spring Regular Languages. Finite Automata and Regular Expressions. Haniel Barbosa

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

Accept or reject. Stack

Pushdown Automata (2015/11/23)

Theory of Computation (IV) Yijia Chen Fudan University

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

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

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

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

CSE 105 THEORY OF COMPUTATION

COM364 Automata Theory Lecture Note 2 - Nondeterminism

Theory of Computation (I) Yijia Chen Fudan University

CISC4090: Theory of Computation

Computational Models - Lecture 4

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

CSE 135: Introduction to Theory of Computation Nondeterministic Finite Automata

Lecture 17: Language Recognition

INF Introduction and Regular Languages. Daniel Lupp. 18th January University of Oslo. Department of Informatics. Universitetet i Oslo

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

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

Push-down Automata = FA + Stack

Pushdown Automata. Chapter 12

Computer Sciences Department

Computability Theory

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

CSE 105 THEORY OF COMPUTATION

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

September 7, Formal Definition of a Nondeterministic Finite Automaton

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

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

2017/08/29 Chapter 1.2 in Sipser Ø Announcement:

Computational Models - Lecture 5 1

Context-Free Languages

Pushdown Automata: Introduction (2)

CS 530: Theory of Computation Based on Sipser (second edition): Notes on regular languages(version 1.1)

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

Nondeterminism. September 7, Nondeterminism

(pp ) PDAs and CFGs (Sec. 2.2)

Chap. 1.2 NonDeterministic 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,

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

CPS 220 Theory of Computation

UNIT-VI PUSHDOWN AUTOMATA

Part I: Definitions and Properties

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

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

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

Formal Definition of a Finite Automaton. August 26, 2013

Chapter Five: Nondeterministic Finite Automata

Intro to Theory of Computation

Nondeterministic Finite Automata

5 Context-Free Languages

CS21 Decidability and Tractability

Theory of Computation

Automata and Computability. Solutions to Exercises

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

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

CS 154. Finite Automata, Nondeterminism, Regular Expressions

CpSc 421 Final Exam December 15, 2006

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

Variants of Turing Machine (intro)

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

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

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

Theory of Computation

I have read and understand all of the instructions below, and I will obey the University Code on Academic Integrity.

Automata and Computability. Solutions to Exercises

Theory of Computation p.1/?? Theory of Computation p.2/?? Unknown: Implicitly a Boolean variable: true if a word is

SE 3310b Theoretical Foundations of Software Engineering. Turing Machines. Aleksander Essex

CS243, Logic and Computation Nondeterministic finite automata

SCHEME FOR INTERNAL ASSESSMENT TEST 3

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

NODIA AND COMPANY. GATE SOLVED PAPER Computer Science Engineering Theory of Computation. Copyright By NODIA & COMPANY

(pp ) PDAs and CFGs (Sec. 2.2)

Finite Automata and Regular languages

Computability and Complexity

Theory of Computation Turing Machine and Pushdown Automata

Final exam study sheet for CS3719 Turing machines and decidability.

Introduction to the Theory of Computation. Automata 1VO + 1PS. Lecturer: Dr. Ana Sokolova.

Pushdown Automata. Reading: Chapter 6

CS21 Decidability and Tractability

Automata: a short introduction

Formal Definition of Computation. August 28, 2013

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

Lecture 3: Nondeterministic Finite Automata

Theory of Computation

Introduction to the Theory of Computation. Automata 1VO + 1PS. Lecturer: Dr. Ana Sokolova.

FORMAL LANGUAGES, AUTOMATA AND COMPUTATION

CS Pushdown Automata

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

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

Automata & languages. A primer on the Theory of Computation. Laurent Vanbever. ETH Zürich (D-ITET) October,

Transcription:

CS:4330 Theory of Computation Spring 2018 Context-Free Languages Pushdown Automata Haniel Barbosa

Readings for this lecture Chapter 2 of [Sipser 1996], 3rd edition. Section 2.2.

Finite automaton 1 / 13

Pushdown automaton 2 / 13

A new type of computational model Pushdown automata, PDA, are a new type of computation model PDAs are like NFAs but have an extra component called a stack The stack provides additional memory beyond the finite amount available in the control The stack allows PDA to recognize some nonregular languages 3 / 13

PDA and CFG PDAs are equivalent in specification power with CFGs This is useful because it gives us two options for proving that a language is context-free: 1. construct a CFG that generates the language, or 2. construct a PDA that recognizes the language Note Some CFLs are more easily described in terms of their generators, whereas others are more easily described in terms of their recognizers. 4 / 13

Terminology Writing a symbol on the stack is referred to as pushing the symbol Removing a symbol from the stack is referred to as popping the symbol. All accesses to the stack may be done only at the top. In other words, a stack is a last-in first-out storage device. 5 / 13

Benefits of the stack A stack can hold an unlimited amount of information A PDA can recognize a language like {0 n 1 n n 0} because it can use the stack to remember the number of 0s it has seen Informal algorithm 1. Read symbols from the input. As each 0 is read, push it into the stack. 2. As soon as an 1 is read, pop a 0 off the stack for each 1 read. 3. If input finishes when stack becomes empty, accept; if stack becomes empty while there is still input or input finishes while stack is not empty, reject. 6 / 13

PDA formalization Formal definition of PDA is similar to an NFA, except for the stack PDA may use different alphabets for input and stack, which we will denote by Σ and Γ, respectively Nondeterminism allows PDA to make transitions on empty input. Hence we will use Σ ɛ = Σ {ɛ} and Γ ɛ = Γ {ɛ} PDA transition functions has domain Q Σ ɛ Γ ɛ, where Q is the set of states Since a PDA can write on the stack while performing nondeterministic transitions the range of the PDA transition function is P(Q Γ ɛ ) The transition function of a PDA is δ : Q Σ ɛ Γ ɛ P(Q Γ ɛ ) 7 / 13

PDA formalization Formal definition of PDA is similar to an NFA, except for the stack PDA may use different alphabets for input and stack, which we will denote by Σ and Γ, respectively Nondeterminism allows PDA to make transitions on empty input. Hence we will use Σ ɛ = Σ {ɛ} and Γ ɛ = Γ {ɛ} PDA transition functions has domain Q Σ ɛ Γ ɛ, where Q is the set of states Since a PDA can write on the stack while performing nondeterministic transitions the range of the PDA transition function is P(Q Γ ɛ ) The transition function of a PDA is δ : Q Σ ɛ Γ ɛ P(Q Γ ɛ ) Definition (PDA) A PDA is a 6-tuple (Q, Σ, Γ, δ, q 0, F), in which Q is its set of states, Σ its input alphabet, Γ its stack alphabet, δ its transition function, q 0 the start state, and F Q the set of accept states. 7 / 13

Example The PDA P 1 that recognizes the language {0 n 1 n n 0} is such that Q = {q 1,q 2,q 3,q 4 } Σ = {0,1} Γ = {0,$} F = {q 1,q 4 } with δ : Input 0 1 ɛ Stack 0 $ ɛ 0 $ ɛ 0 $ ɛ q 1 {(q 2,$)} q 2 {(q 2,0)} {(q 3,ɛ)} q 3 {(q 3,ɛ)} {(q 4,ɛ)} q 4 8 / 13

Example The PDA P 1 that recognizes the language {0 n 1 n n 0} is such that Q = {q 1,q 2,q 3,q 4 } Σ = {0,1} Γ = {0,$} F = {q 1,q 4 } with δ s.t. ɛ,ɛ $ start q 1 q 2 0,ɛ 0 1,0 ɛ q 4 ɛ,$ ɛ q 3 1,0 ɛ 8 / 13

PDA computation A PDA P = (Q, Σ, Γ, δ, q 0, F) accepts a word w Σ where w = w 1,..., w m, with w i Σ ɛ if there exists a sequence where r i Q, with r 0 = q 0, (r 0,s 0 ) (r 1,s 1 ) (r 2,s 2 ) (r m,s m ) s i Γ (representing the stack), with s 0 = ɛ, q m F, (r i+1,b) δ(r i,w i,a) where s i = at and s i+1 = bt for some a,b Γ ɛ and t Γ 9 / 13

Transition diagrams of PDA Transition diagrams for PDAs are similar to the ones used for finite automata To show how it manipulates the stack we write a,b c to signify that the machine: 1. is reading a from the input 2. may replace the symbol b on the top of the stack with the symbol c where a,b,c may be ɛ If a = ɛ, the machine may take this transition without reading any symbol from the input If b = ɛ, the machine may make this transition without popping any symbol from stack If c = ɛ, the machine may make this transition without pushing any pushing any symbol on the stack 10 / 13

Note The formal definition of a PDA contains no explicit mechanism for testing the empty stack The PDA P 1 in the previous example tests whether stack is empty by initially placing a special symbol $ on the stack If it ever sees $ again on the stack, it knows that the stack is effectively empty. We use this convention to test whether the stack is empty. 11 / 13

Another example: palyndromes The PDA P 2 that recognizes the language {ww R w {a 1,..., a n } } is such that 12 / 13

Another example: palyndromes The PDA P 2 that recognizes the language {ww R w {a 1,..., a n } } is such that ɛ,ɛ $ a 1,ɛ a... 1 a n,ɛ a n start q 1 q 2 ɛ,ɛ ɛ q 4 ɛ,$ ɛ q 3 a 1,a 1 ɛ... a n,a n ɛ 12 / 13

Another example The PDA P 3 that recognizes the language {a i b j c k i,j,k 0 i = j i = k} is such that The PDA reads and push a s on the stack When this is done, it can mach a s b s or c s Since the machine does not know in advance whether a s are matched with b s or c s, nondeterminism helps Using nondeterminism the machine can guess: it branches into two possibilities, one for each guess If either of these branches matches the input, that branch accepts the word, as does the machine. 13 / 13

Another example The PDA P 3 that recognizes the language {a i b j c k i,j,k 0 i = j i = k} is such that b,a ɛ c,ɛ ɛ start q 1 ɛ,$ ɛ q 3 q 4 ɛ,ɛ $ ɛ,ɛ ɛ q 2 ɛ,ɛ ɛ ɛ,ɛ ɛ ɛ,$ ɛ q 5 q 6 q 7 a,ɛ a b,ɛ ɛ c,a ɛ 13 / 13