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

Similar documents
CSE 105 Homework 3 Due: Monday October 23, Instructions. should be on each page of the submission.

CSE 105 Homework 1 Due: Monday October 9, Instructions. should be on each page of the submission.

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

Section 1 (closed-book) Total points 30

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

Properties of Context-Free Languages. Closure Properties Decision Properties

CSE 105 THEORY OF COMPUTATION

Properties of Context-Free Languages

CS20a: summary (Oct 24, 2002)

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

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

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

V Honors Theory of Computation

Unit 6. Non Regular Languages The Pumping Lemma. Reading: Sipser, chapter 1

Automata and Computability. Solutions to Exercises

Ogden s Lemma. and Formal Languages. Automata Theory CS 573. The proof is similar but more fussy. than the proof of the PL4CFL.

CS481F01 Solutions 6 PDAS

CSE 355 Test 2, Fall 2016

The Pumping Lemma for Context Free Grammars

Computational Models - Lecture 4

NPDA, CFG equivalence

Computational Models - Lecture 4 1

CS311 Computational Structures More about PDAs & Context-Free Languages. Lecture 9. Andrew P. Black Andrew Tolmach

Context-Free Languages (Pre Lecture)

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

Notes on Pumping Lemma

Closure under the Regular Operations

CSE 105 THEORY OF COMPUTATION

Computational Models - Lecture 3 1

Automata and Computability. Solutions to Exercises

CS500 Homework #2 Solutions

DD2371 Automata Theory

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

Introduction to Theory of Computing

Computer Sciences Department

AC68 FINITE AUTOMATA & FORMULA LANGUAGES JUNE 2014

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

Ogden s Lemma for CFLs

Chap. 7 Properties of Context-free Languages

Computational Models - Lecture 4 1

CISC4090: Theory of Computation

Computability and Complexity

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

CSE 105 THEORY OF COMPUTATION

CS375: Logic and Theory of Computing

Exam 1 CSU 390 Theory of Computation Fall 2007

SCHEME FOR INTERNAL ASSESSMENT TEST 3

Context-Free and Noncontext-Free Languages

Properties of Context-free Languages. Reading: Chapter 7

3515ICT: Theory of Computation. Regular languages

Theory of Computation

Notes for Comp 497 (454) Week 10

Undecidability COMS Ashley Montanaro 4 April Department of Computer Science, University of Bristol Bristol, UK

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

Before We Start. The Pumping Lemma. Languages. Context Free Languages. Plan for today. Now our picture looks like. Any questions?

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

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

Theory of Computation (II) Yijia Chen Fudan University

Your Name: UVa Id:

Solution. S ABc Ab c Bc Ac b A ABa Ba Aa a B Bbc bc.

Computational Models - Lecture 3

6.1 The Pumping Lemma for CFLs 6.2 Intersections and Complements of CFLs

CS154 Final Examination

Properties of context-free Languages

Context Free Language Properties

Finite Automata and Regular languages

Fundamentele Informatica II

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

CSE 105 THEORY OF COMPUTATION. Spring 2018 review class

1. Induction on Strings

HW 3 Solutions. Tommy November 27, 2012

Computational Models - Lecture 5 1

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

CSE 105 THEORY OF COMPUTATION

Computational Models - Lecture 5 1

The View Over The Horizon

Languages, regular languages, finite automata

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Einführung in die Computerlinguistik

Computational Models: Class 5

CSE 105 THEORY OF COMPUTATION

Finite Automata and Formal Languages TMV026/DIT321 LP Useful, Useless, Generating and Reachable Symbols

CS5371 Theory of Computation. Lecture 5: Automata Theory III (Non-regular Language, Pumping Lemma, Regular Expression)

CpSc 421 Final Exam December 15, 2006

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Miscellaneous. Closure Properties Decision Properties

The Power of One-State Turing Machines

Tree Adjoining Grammars

What we have done so far

Theory of Computation (I) Yijia Chen Fudan University

CSE 105 THEORY OF COMPUTATION

Theory of Computation

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

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

Fooling Sets and. Lecture 5

Context Free Languages. Automata Theory and Formal Grammars: Lecture 6. Languages That Are Not Regular. Non-Regular Languages

CS 154. Finite Automata, Nondeterminism, Regular Expressions

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.

Final exam study sheet for CS3719 Turing machines and decidability.

Chapter 6. Properties of Regular Languages

Transcription:

CSE 05 Homework 5 Due: Monday November 3, 207 Instructions Upload a single file to Gradescope for each group. should be on each page of the submission. All group members names and PIDs Your assignments in this class will be evaluated not only on the correctness of your answers, but on your ability to present your ideas clearly and logically. You should always explain how you arrived at your conclusions, using mathematically sound reasoning. Whether you use formal proof techniques or write a more informal argument for why something is true, your answers should always be well-supported. Your goal should be to convince the reader that your results and methods are sound. eading Sipser Chapter 2. Key Concepts CFG, PDA (0 points) Let P be a PDA defined as follows. Q = {q 0, q, q 2 }, Σ = {0, }, Γ = {}, F = {q, q 2 } δ(q 0, 0, ɛ) = {(q 0, )} δ(q 0, ɛ, ɛ) = {(q, ɛ)} δ(q 0,, ) = {(q 2, ɛ)} δ(q, ɛ, ) = {(q, ɛ)} δ(q 2,, ) = {(q 2, ɛ)} δ(q 2, ɛ, ) = {(q 2, ɛ)}. Describe the language accepted by P. 2. Give the state diagram of P. 3. Write down the traces of computations of 00, 00 in P. 4. Show that 00 L(P ). Solution:. Describe the language accepted by P. The language is {0 m n 0 n m}. 2. Give the state diagram of P.

3. Write down the traces of computations of 00, 00 in P. Write each computation path of 00 first. 00 00 00 0 0 00 0 q2 q2 00 0 Now we show all the computation paths for 00.

4. Show that 00 L(P ). q 0 00 ɛ q 00 ɛ q 0 00 ɛ q 0 0 q 0 q 0 ɛ q 0 00 ɛ q 0 0 q 2 0 ɛ To show that 00 L(P ), it s enough to give one computation path that halts at an accept state. q 0 00 ɛ q 0 0 q 0 q 2 q 2 ɛ ɛ 2 (8 points) Give context-free grammars for each of the following languages. To get full credit, it s enough to solve four out of six items. More, will be considered bonus points.. L = { 2m 0 m m 0} 2. L = {0, } \{ 2m 0 m m 0} 3. L = {0, } \{ww w {0, } } 4. L = {w Number of 0 s is exactly twice the number of s} 5. L = {wz w, z {0, }, w = z, w z} 6. L = {x i y j z k i, j, k 0 and i + j = k} Solution: In all the solutions the upper case letters are variables and S is the starting variable. The lower case letters are terminals.. L = { 2m 0 m m 0} S ɛ S0 2. L = {0, } \{ 2m 0 m m 0} One can write the language L as the union of two languages L = { 0 } c { m 0 n m 2n}. We write a CFG for each of these two languages separately and finally combine them to get a CFG for L. L = { 0 } c Notice that a regular expression for L is (0 ) 0(0 ). Let S be the starting variable in the CFG.

S X0X X ɛ X 0X Now we write a CFG for L 2 = { m 0 n m 2n}. Let S 2 be the starting variable. S 2 S 2 0 P T P 0 0P T P Now we construct the union of these two CFGs. Let S be the starting variable. 3. L = {0, } \{ww w {0, } } S S S 2 S X0X X ɛ X 0X S 2 S 2 0 P T P 0 0P T P Note that all strings of odd length are in L Any even length string in L can be divided into two odd length strings such that one has a 0 in the center and the other has a in the center. S XY Y X X Y X 0 ZXZ Y ZY Z Z 0 4. L = {w Number of 0 s is exactly twice the number of s} 5. L = {wz w, z {0, }, w = z, w z} S ɛ SS 00S 0SS0 S00 Note that this language is exactly the even length strings in language of item 5. Any string in this language can be written as concatenation of two odd length strings such that one has a 0 at the center and the other has a at the center. 6. L = {x i y j z k i, j, k 0 and i + j = k} S XY Y X X 0 ZXZ Y ZY Z Z 0 S xsz T T ysz ɛ

3 (2 points) Construct push-down automata recognizing the following languages.. L = {2m 03m m 0} 2. L = {w {), (} w is a valid string of parentheses.}. For example ()(()) L, )() / L. 3. L = {xi y j z k i, j, k 0 and i + j = k} 4. L = {xi y j z k i 6= j or j 6= k} Solution:. L = {2m 03m m 0} 2. L = {w {), (} w is a valid string of parentheses.}. For example ()(()) L, )() / L. 3. L = {xi y j z k i, j, k 0 and i + j = k}

4. L = {xi y j z k i 6= j or j 6= k} 4 (0 points) Prove that the class of context-free languages is closed under concatenation. Solution: Suppose we have two context-free languages L and L2. We know that there are CFGs G = {Σ,, S, V } for L and G2 = {Σ2, 2, S2, V2 } for L2. Suppose that the variables V of G are distinct from the set of variables V2 of G2. Moreover assume that the starting variable of G is S and the starting variable of G2 is S2. Then we define a new variable S as the starting variable of our CFG G = {Σ, V, S, } for L = L L2 as follows. = 2 {S S S2 } V = V V2 {S} Σ = Σ Σ2

Now we prove the construction is correct. Let L be the language defined by the CFG above. We have to prove L = L L 2. First, suppose that there is x L. Therefor there is a computation path for constructing x via the CFG G. However, the only rule that would produce x is S S S 2. This means x could be written as x x 2 such that S produces x and S 2 produces x 2. However, since the variables in the rules involving S are disjoint from the variables in the rules involving S 2 ; any output of S is in L and any output of S 2 is in L 2. This means that the x L and x 2 L 2, therefore, x L L 2. Secondly, suppose x L L 2. We show that x L as well. We can write x = x x 2 such that x L, x 2 L 2. Therefor, there is a computation path in the CFG for L such that S produces x and similarly, S 2 produces x 2. Now we can apply the rule S S S 2 to produce the desired string x. 5(bonus) (0 points) ead theorem 2.34 from the book (pumping lemma for context-free languages). Then prove that the following language is not context-free. L = {ww w w {0, } } Solution: Toward contradiction, assume that the language L is context-free. Therefore pumping lemma should apply to L. Let p be the pumping length, and choose the string s = (0 p p )(0 p p ) ((0 p p ) = 0 p 2p 0 2p p. Suppose that we have an arbitrary partition s = uvwxy such that. vwx < p 2. uv > 0 We show that there is an i 0 such that uv i wx i y / L. There are a few possible cases to consider. Case. vx has at least a 0. Since we know vwx < p, the substring vwx can not contain 0 s from both sides of 2p. If vwx contains 0 s from the left side, then pick i = 2. This increases the number of 0 s on left side. We show this implies the new string uv 2 wx 2 y / L. Suppose uv 2 wx 2 y = 0 m 2p+k 0 2p p for m > p and k 0. We show this string can not be written in the form ww w. Note that any suitable w must contain the entire substring 0 m and some s. This would require have in total 3m many 0 s in the entire string. But we simply don t have this many 0 s. On the other case, assume that vwx contains some 0 s on the right side of 2p. Again by a similar argument we have uv 2 wx 2 y / L. Case 2. vx has at least a. In this case the argument is similar to the above.