Homework 5 - Solution

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

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

Simplification of CFG and Normal Forms. Wen-Guey Tzeng Computer Science Department National Chiao Tung University

Simplification of CFG and Normal Forms. Wen-Guey Tzeng Computer Science Department National Chiao Tung University

Pumping Lemma for CFLs

Context-Free Languages (Pre Lecture)

Homework 4 Solutions. 2. Find context-free grammars for the language L = {a n b m c k : k n + m}. (with n 0,

Cliff s notes for equivalence of CFLs and L(PDAs) LisaCFL L = L(M) for some PDA M L=L(M)forsomePDAM L = L(G) for some CFG G

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Context-Free and Noncontext-Free Languages

Formal Languages, Automata and Models of Computation

Closure under the Regular Operations

CSE 355 Test 2, Fall 2016

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

Homework 4. Chapter 7. CS A Term 2009: Foundations of Computer Science. By Li Feng, Shweta Srivastava, and Carolina Ruiz

CS 341 Homework 16 Languages that Are and Are Not Context-Free

Computational Models - Lecture 4

CS500 Homework #2 Solutions

HW 3 Solutions. Tommy November 27, 2012

ÖVNINGSUPPGIFTER I SAMMANHANGSFRIA SPRÅK. 17 april Classrum Edition

Automata Theory. CS F-10 Non-Context-Free Langauges Closure Properties of Context-Free Languages. David Galles

Solution Scoring: SD Reg exp.: a(a

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

Computability and Complexity

CS 154 Formal Languages and Computability Assignment #2 Solutions

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

NPDA, CFG equivalence

MA/CSSE 474 Theory of Computation

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

More Properties of Regular Languages

Section 1 (closed-book) Total points 30

Intro to Theory of Computation

Sheet 1-8 Dr. Mostafa Aref Format By : Mostafa Sayed

Theory of Computation (IV) Yijia Chen Fudan University

Theory of Computation - Module 3

Properties of Regular Languages. Wen-Guey Tzeng Department of Computer Science National Chiao Tung University

Theory of Computation

Introduction to Theory of Computing

The View Over The Horizon

CISC4090: Theory of Computation

Chapter 6. Properties of Regular Languages

Finite Automata and Regular languages

GEETANJALI INSTITUTE OF TECHNICAL STUDIES, UDAIPUR I

Closure Properties of Context-Free Languages. Foundations of Computer Science Theory

Computational Models - Lecture 3 1

CpSc 421 Final Exam December 15, 2006

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

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

PUSHDOWN AUTOMATA (PDA)

Properties of Context Free Languages

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

Solution to CS375 Homework Assignment 11 (40 points) Due date: 4/26/2017

Theory of Computation (Classroom Practice Booklet Solutions)

HW6 Solutions. Micha l Dereziński. March 20, 2015

The Pumping Lemma for Context Free Grammars

6.8 The Post Correspondence Problem

Context-free Languages and Pushdown Automata

CS 154. Finite Automata, Nondeterminism, Regular Expressions

Recitation 4: Converting Grammars to Chomsky Normal Form, Simulation of Context Free Languages with Push-Down Automata, Semirings

Closure Properties of Regular Languages. Union, Intersection, Difference, Concatenation, Kleene Closure, Reversal, Homomorphism, Inverse Homomorphism

Properties of context-free Languages

CS 154, Lecture 3: DFA NFA, Regular Expressions

Lecture 12 Simplification of Context-Free Grammars and Normal Forms

(b) If G=({S}, {a}, {S SS}, S) find the language generated by G. [8+8] 2. Convert the following grammar to Greibach Normal Form G = ({A1, A2, A3},

3.13. PUSHDOWN AUTOMATA Pushdown Automata

Final exam study sheet for CS3719 Turing machines and decidability.

AC68 FINITE AUTOMATA & FORMULA LANGUAGES JUNE 2014

Problem 2.6(d) [4 pts] Problem 2.12 [3pts] Original CFG:

VTU QUESTION BANK. Unit 1. Introduction to Finite Automata. 1. Obtain DFAs to accept strings of a s and b s having exactly one a.

DM17. Beregnelighed. Jacob Aae Mikkelsen

Functions on languages:

CS375 Midterm Exam Solution Set (Fall 2017)

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

THEORY OF COMPUTATION (AUBER) EXAM CRIB SHEET

Computability Theory

FORMAL LANGUAGES, AUTOMATA AND COMPUTATION

Ogden s Lemma for CFLs

Indexed Languages and why you care. Presented by Pieter Hooimeijer

Deterministic PDA s. Deepak D Souza. 08 Nov Department of Computer Science and Automation Indian Institute of Science, Bangalore.

BASIC MATHEMATICAL TECHNIQUES

Question Bank UNIT I

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

Fundamentele Informatica II

Pushdown Automata. Reading: Chapter 6

Assignment #2 COMP 3200 Spring 2012 Prof. Stucki

CSE 105 THEORY OF COMPUTATION

Fall 1999 Formal Language Theory Dr. R. Boyer. Theorem. For any context free grammar G; if there is a derivation of w 2 from the

CSci 311, Models of Computation Chapter 4 Properties of Regular Languages

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

ECS120 Fall Discussion Notes. October 25, The midterm is on Thursday, November 2nd during class. (That is next week!)

Chap. 7 Properties of Context-free Languages

Note: In any grammar here, the meaning and usage of P (productions) is equivalent to R (rules).

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,

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

Deterministic PDA s. Deepak D Souza. 21 October Department of Computer Science and Automation Indian Institute of Science, Bangalore.

Notes for Comp 497 (Comp 454) Week 10 4/5/05

Properties of Context-Free Languages. Closure Properties Decision Properties

10. The GNFA method is used to show that

Lecture 17: Language Recognition

Languages, regular languages, finite automata

Transcription:

DCP3122 Introduction to Formal Languages, Spring 2015 Instructor: Prof. Wen-Guey Tzeng Homework 5 - Solution 5-May-2015 Due: 18-May-2015 1. Given Σ = {a, b, c}, find an NPDA that accepts L = {a n b n+m c m : n 0, m 1}. Ans. An NPDA that accepts L is M = (Q, Σ, Γ, δ, q 0, z, F ), where Q = {q 0, q 1,..., q 5 }, Σ = {a, b, c}, Γ = {0, 1, z}, F = {q 5 }, and the transition function δ is represented as the following graph 2. Given Σ = {a, b, c}, find an NPDA that accepts L = {w 1 cw 2 : w 1, w 2 {a, b}, w 1 w R 2 }. Ans. An NPDA that accepts L is M = (Q, Σ, Γ, δ, q 0, z, F ), where Q = {q 0, q 1, q 2 }, Σ = {a, b, c}, Γ = {0, 1, z}, F = {q 2 }, and the transition function δ is represented as the following graph 3. What language is accepted by the PDA M = ({q 0, q 1,..., q 5 }, {a, b}, {0, 1, a, z}, δ, z, q 0, {q 5 }), 1-1

with δ(q 0, b, z) = {(q 1, 1z)}, δ(q 1, b, 1) = {(q 1, 11)}, δ(q 2, a, 1) = {(q 3, λ)}, δ(q 3, a, 1) = {(q 4, λ)}, δ(q 4, a, z) = {(q 4, z), (q 5, z)}? Ans. L =, because the transition function would never reach the final state. 4. Construct an NPDA that accepts the language generated by the grammar S asbb aab. Ans. The Greibach normal form of the grammar is S asbb aab, B b, A a. An NPDA that accepts L is M = (Q, Σ, Γ, δ, q 0, z, F ), where Q = {q 0, q 1, q 2 }, Σ = {a, b}, Γ = {S, A, B, z}, F = {q 2 }, and the transition function δ is represented as the following graph 5. Find a context-free grammar that generates the language accepted by the NPDA M = ({q 0, q 1 }, {a, b}, {A, z}, δ, q 0, z, {q 1 }), with transitions δ(q 0, a, z) = {(q 0, Az)}, δ(q 0, b, A) = {(q 0, AA)}, δ(q 0, a, A) = {(q 1, λ)}. Ans. We first transform the NPDA into a new one that satisfies the following two requirements: (1) It has a single final state q f that is entered if and only if the stack is empty; (2) While a Σ {λ}, all transitions must have the form δ(q i, a, A) = {c 1, c 2,..., c n }, where c i = (q j, λ) or c i = (q j, BC). The NPDA satisfies requirement (2), but not (1). To satisfy the latter, we introduce a new final state q 2 so that Q new = {q 0, q 1, q 2 }, F new = {q 2 }, and δ new is δ(q 0, a, z) = {(q 0, Az)}, δ(q 0, b, A) = {(q 0, AA)}, δ(q 0, a, A) = {(q 1, λ)}, δ(q 1, λ, A) = {(q 1, λ)}, δ(q 1, λ, z) = {(q 2, λ)}. 1-2

The last three transitions yield the corresponding productions (q 0 Aq 1 ) a, (q 1 Aq 1 ) λ, (q 1 zq 2 ) λ. From the first two transitions we get the set of productions (q 0 zq 0 ) a(q 0 Aq 0 )(q 0 zq 0 ) a(q 0 Aq 1 )(q 1 zq 0 ) a(q 0 Aq 2 )(q 2 zq 0 ), (q 0 zq 1 ) a(q 0 Aq 0 )(q 0 zq 1 ) a(q 0 Aq 1 )(q 1 zq 1 ) a(q 0 Aq 2 )(q 2 zq 1 ), (q 0 zq 2 ) a(q 0 Aq 0 )(q 0 zq 2 ) a(q 0 Aq 1 )(q 1 zq 2 ) a(q 0 Aq 2 )(q 2 zq 2 ), (q 0 Aq 0 ) a(q 0 Aq 0 )(q 0 Aq 0 ) a(q 0 Aq 1 )(q 1 Aq 0 ) a(q 0 Aq 2 )(q 2 Aq 0 ), (q 0 Aq 1 ) a(q 0 Aq 0 )(q 0 Aq 1 ) a(q 0 Aq 1 )(q 1 Aq 1 ) a(q 0 Aq 2 )(q 2 Aq 1 ), (q 0 Aq 2 ) a(q 0 Aq 0 )(q 0 Aq 2 ) a(q 0 Aq 1 )(q 1 Aq 2 ) a(q 0 Aq 2 )(q 2 Aq 2 ). To simplify the transitions, we remove the useless variables: A variable that does not occur on the left side of any production: (q 1 zq 0 ), (q 1 zq 1 ), (q 1 zq 2 ), (q 2 zq 0 ), (q 2 zq 1 ), (q 2 zq 2 ), (q 1 Aq 0 ), (q 1 Aq 1 ), (q 1 Aq 2 ), (q 2 Aq 0 ), (q 2 Aq 1 ), and (q 2 Aq 2 ). Non-reachable path: None. The result grammar is with the start variable is (q 0 zq 2 ). (q 0 Aq 1 ) a, (q 1 Aq 1 ) λ, (q 1 zq 2 ) λ, (q 0 zq 0 ) a(q 0 Aq 0 )(q 0 zq 0 ), (q 0 zq 1 ) a(q 0 Aq 0 )(q 0 zq 1 ), (q 0 zq 2 ) a(q 0 Aq 0 )(q 0 zq 2 ), (q 0 Aq 0 ) a(q 0 Aq 0 )(q 0 Aq 0 ), (q 0 Aq 1 ) a(q 0 Aq 0 )(q 0 Aq 1 ), (q 0 Aq 2 ) a(q 0 Aq 0 )(q 0 Aq 2 ), 6. Show that the language L = {w {a, b, c} : n a (w) = n b (w) n c (w)} is not context-free. Ans. We pick a string w = a m b m c m L, m N. There are many ways to decompose w as w = uvxyz with vxy m and vy 1. However, for all of them have a winning countermove such that uv i xy i z / L: v = a k, y = a k : uv 0 xy 0 z = a m 2k b m c m / L. v = a k, y = a k b k : uv 0 xy 0 z = a m 2k b m k c m / L. v = a k, y = b l : uv 0 xy 0 z = a m k b m l c m / L. v = a k b k, y = b k : uv 0 xy 0 z = a m k b m 2k c m / L. v = b k, y = b k : uv 0 xy 0 z = a m b m 2k c m / L. v = b k, y = b k c k : uv 0 xy 0 z = a m b m 2k c m k / L. 1-3

v = b k, y = c k uv 0 xy 0 z = a m b m k c m k / L. v = b k c k, y = c k : uv 0 xy 0 z = a m b m 2k c m k / L. v = c k, y = c k : uv 0 xy 0 z = a m b m c m 2k / L. 7. Show that the language L = {a n b m : n and m are both prime} is not context-free. Ans. We pick a string w = a m b m L, m is an odd prime. There are many ways to decompose w as w = uvxyz with vxy m and vy 1. However, for all of them have a winning countermove such that uv i xy i z / L: v = a k, y = a l with k + l is odd: uv 0 xy 0 z = a m k l b m / L since m k l is even. v = a k 1, y = a k 2 b l with one of k 1 and k 2 is odd, or l is odd: uv 0 xy 0 z = a m k 1 k 2 b m l / L since m k 1 k 2 is even or m l is even. v = a k, y = b l with one of k and l is odd: uv 0 xy 0 z = a m k b m l / L since m k is even or m l is even. v = a l b k 1, y = b k 2 with one of k 1 and k 2 is odd, or l is odd: uv 0 xy 0 z = a m l b m k 1 k 2 / L since m l is even or m k 1 k 2 is even. v = b k, y = b l with k + l is odd: uv 0 xy 0 z = a m b m k l / L since m k l is even. 8. Determine whether or not L = {a n b j a k b l : n k, j l} is context-free. You have to prove your answer. Ans. We pick a string w = a m b m a m b m L, m N. There are many ways to decompose w as w = uvxyz with vxy m and vy 1. However, for all of them have a winning countermove such that uv i xy i z / L: [1st a] v = a k, y = a k with k N: uv i xy i z = a m+2(i 1)k b m a m b m / L for i = 2, 3,.... [1st a, 1st b] v = a k, y = a k b k : uv i xy i z = a m+2(i 1)k b m+(i 1)k a m b m / L for i = 2, 3,.... [1st a, 1st b] v = a k, y = b k : uv i xy i z = a m+(i 1)k b m+(i 1)k a m b m / L for i = 2, 3,.... [1st a, 1st b] v = a k b k, y = b k : uv i xy i z = a m+(i 1)k b m+2(i 1)k a m b m / L for i = 2, 3,.... [1st b] v = b k, y = b k : uv i xy i z = a m b m+2(i 1)k a m b m / L for i = 2, 3,.... [1st b, 2nd a] v = b k, y = b k a k : uv i xy i z = a m b m+2(i 1)k a m+(i 1)k b m / L for i = 2, 3,.... [1st b, 2nd a] v = b k, y = a k : uv i xy i z = a m b m+(i 1)k a m+(i 1)k b m / L for i = 2, 3,.... [1st b, 2nd a] v = b k a k, y = a k : uv i xy i z = a m b m+(i 1)k a m+2(i 1)k b m / L for i = 2, 3,.... [2nd a] v = a k, y = a k : uv 0 xy 0 z = a m b m a m 2k b m / L. [2nd a, 2nd b] v = a k, y = a k b k : uv 0 xy 0 z = a m b m a m 2k b m k / L. [2nd a, 2nd b] v = a k, y = b k : uv 0 xy 0 z = a m b m a m k b m k / L. [2nd a, 2nd b] v = a k b k, y = b k : uv 0 xy 0 z = a m b m a m k b m 2k / L. [2nd b] v = b k, y = b k : uv 0 xy 0 z = a m b m a m b m 2k / L. 1-4

9. Show that the family of context-free languages is not closed under difference in general, but is closed under regular difference, that is, if L 1 is context-free and L 2 is regular, then L 1 L 2 is context-free. Ans. The answer contains the following two parts: Let L 1 and L 2 be context-free languages. By theorem, we have that the family of contextfree languages is not close under intersection and complement. Thus, L 1 L 2 = L 1 L 2 is not close under difference in general. Let L 1 be a context-free language and L 2 a regular language. By the closure property of regular languages, we know that L 2 is also regular. By theorem, we know that L 1 L 2 is context-free by the closure property under regular intersection. Therefore, L 1 L 2 = L 1 L 2 is also context-free by the closure property under regular intersection. 10. Show that L = {w {a, b} : n a (w) = n b (w); w does not contain a substring aab} is contextfree. Ans. Let L 1 = {w {a, b} : n a (w) = n b (w)} and L 2 = {w {a, b} : w contains aab as a string}. The following shows that L 1 is context-free and L 2 is regular. An NPDA that accepts L 1 is M 1 = ({q 0, q 1 }, {a, b}, {a, b, z}, δ, q 0, z, {q 1 }), where the transition function δ is defined as follows: δ(q 0, λ, z) = (q 1, z), δ(q 0, a, z) = (q 0, az), δ(q 0, a, a) = (q 0, aa), δ(q 0, a, b) = (q 0, λ), δ(q 0, b, z) = (q 0, bz), δ(q 0, b, a) = (q 0, λ), δ(q 0, b, b) = (q 0, bb). An NFA that accepts L 2 is M 2 = ({q 0, q 1, q 2, q 3 }, {a, b}, δ, q 0, {q 3 }) accepts L, where the transition function δ is defined as follows: δ(q 0, a) = q 1, δ(q 0, b) = q 0, δ(q 1, a) = q 2, δ(q 1, b) = q 0, δ(q 2, a) = q 0, δ(q 2, b) = q 3, δ(q 3, a) = q 3, δ(q 3, b) = q 3. Therefore, L = L 1 L 2 is context-free by the closure property under regular intersection. 1-5