HW 3 Solutions. Tommy November 27, 2012

Similar documents
Concordia University Department of Computer Science & Software Engineering

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

Theory of Computation - Module 3

Theory of Computation

In English, there are at least three different types of entities: letters, words, sentences.

AC68 FINITE AUTOMATA & FORMULA LANGUAGES JUNE 2014

Chapter 4. Regular Expressions. 4.1 Some Definitions

Author: Vivek Kulkarni ( )

Chapter 6. Properties of Regular Languages

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

Homework 5 - Solution

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.

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

FABER Formal Languages, Automata. Lecture 2. Mälardalen University

CS500 Homework #2 Solutions

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

CS375: Logic and Theory of Computing

EXAMPLE CFG. L = {a 2n : n 1 } L = {a 2n : n 0 } S asa aa. L = {a n b : n 0 } L = {a n b : n 1 } S asb ab S 1S00 S 1S00 100

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

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

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

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

6.8 The Post Correspondence Problem

Automata Theory Final Exam Solution 08:10-10:00 am Friday, June 13, 2008

AC68 FINITE AUTOMATA & FORMULA LANGUAGES DEC 2013

Theory of Computer Science

Before we show how languages can be proven not regular, first, how would we show a language is regular?

1 Alphabets and Languages

Fundamentele Informatica II

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

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

Theory of Computation

download instant at Assume that (w R ) R = w for all strings w Σ of length n or less.

Lecture 11 Context-Free Languages

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

Properties of Context-Free Languages

Section 1 (closed-book) Total points 30

GEETANJALI INSTITUTE OF TECHNICAL STUDIES, UDAIPUR I

Solutions to Problem Set 3

Finite Automata and Regular Languages

Automata Theory CS F-08 Context-Free Grammars

Miscellaneous. Closure Properties Decision Properties

Notes on Pumping Lemma

Context-Free Grammars and Languages. Reading: Chapter 5

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

The Pumping Lemma (cont.) 2IT70 Finite Automata and Process Theory

REGular and Context-Free Grammars

Exam 1 CSU 390 Theory of Computation Fall 2007

Formal Languages, Automata and Models of Computation

Solution Scoring: SD Reg exp.: a(a

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

C1.1 Introduction. Theory of Computer Science. Theory of Computer Science. C1.1 Introduction. C1.2 Alphabets and Formal Languages. C1.

Pushdown Automata. Reading: Chapter 6

Notes for Comp 497 (454) Week 10

1. Induction on Strings

TAFL 1 (ECS-403) Unit- III. 3.1 Definition of CFG (Context Free Grammar) and problems. 3.2 Derivation. 3.3 Ambiguity in Grammar

3515ICT: Theory of Computation. Regular languages

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

Computational Models - Lecture 3 1

CMSC 330: Organization of Programming Languages. Regular Expressions and Finite Automata

CMSC 330: Organization of Programming Languages

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

Part 3 out of 5. Automata & languages. A primer on the Theory of Computation. Last week, we learned about closure and equivalence of regular languages

Comment: The induction is always on some parameter, and the basis case is always an integer or set of integers.

Theory of Computation (Classroom Practice Booklet Solutions)

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

False. They are the same language.

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

Automata: a short introduction

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

Context-free grammars and languages

Intro to Theory of Computation

Computational Theory

Automata Theory - Quiz II (Solutions)

Context-free Languages and Pushdown Automata

Introduction to Theory of Computing

Non-context-Free Languages. CS215, Lecture 5 c

Automata Theory CS F-13 Unrestricted Grammars

CS 154. Finite Automata vs Regular Expressions, Non-Regular Languages

Properties of Context-Free Languages. Closure Properties Decision Properties

The Pumping Lemma for Context Free Grammars

1. (a) Explain the procedure to convert Context Free Grammar to Push Down Automata.

Grade 6 Math Circles October 20/21, Formalism and Languages: Beyond Regular Languages

Harvard CS 121 and CSCI E-207 Lecture 12: General Context-Free Recognition

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

Question Bank UNIT I

CSCI 340: Computational Models. Regular Expressions. Department of Computer Science

SFWR ENG 2FA3. Solution to the Assignment #4

CS 133 : Automata Theory and Computability

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

Lecture 12 Simplification of Context-Free Grammars and Normal Forms

Ogden s Lemma for CFLs

Lecture Notes On THEORY OF COMPUTATION MODULE -1 UNIT - 2

5.A Examples of Context-Free Grammars 3.1 and 3.2 of Du & Ko s book(pp )

COSE212: Programming Languages. Lecture 1 Inductive Definitions (1)

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

TAFL 1 (ECS-403) Unit- II. 2.1 Regular Expression: The Operators of Regular Expressions: Building Regular Expressions

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

Intro to Theory of Computation

10. The GNFA method is used to show that

Transcription:

HW 3 Solutions Tommy November 27, 2012 5.1.1 (a) Online solution: S 0S1 ɛ. (b) Similar to online solution: S AY XC A aa ɛ b ɛ C cc ɛ X axb aa b Y by c b cc (c) S X A A A V AV a V V b V a b X V V X V (d) S 0S01 0S10 1S00 00S1 01S0 10S0 SS ɛ 5.1.3 First, I will show that every regular expression r has an equivalent contextfree grammar. The proof is by induction on the complexity of the expression r. asis Suppose r =. Then an equivalent grammar is S r. Suppose r = ɛ. Then an equivalent grammar is S r ɛ. Suppose r = a for some alphabet symbol a. Then an equivalent grammar is S r a. Induction As our inductive hypothesis, we assume that there are equivalent context-free grammars for all regular expressions that are strictly less complex than r. 1

5.2.1 (a) Suppose r = r 1 r 2 for some regular expressions r 1 and r 2. Then an equivalent grammar for r can be constructed by combining the grammars for r 1 and r 2 with the following extra rule: S r S r1 S r2. Suppose r = r 1 +r 2 for some regular expressions r 1 and r 2. Then an equivalent grammar for r can be constructed by combining the grammars for r 1 and r 2 with the following extra rule: S r S r1 S r2. Suppose r = t for some regular expression t. Then an equivalent grammar for r can be constructed by adding the following extra rule to the grammar for t: S r S t S r ɛ. Since all regular expressions fall into one of the above six cases, we conclude that all regular expressions have equivalent context-free grammars. To see that all regular languages L are context-free, simply take a regular expression for L (guaranteed to exist) and convert it to a context-free grammar. 2

(b) (c) 5.3.1 Let w be a string of balanced parentheses. I will show by induction (on the length of w) that w is generated by the given grammar. asis Suppose w = ɛ. Since the grammar has the rule ɛ, we see that it generates w. Induction Our inductive hypothesis is that the grammar generates all 3

5.4.1 (a) strings of balanced parentheses that are strictly shorter than w. Suppose w is the concatenation of two non-empty strings w 1, w 2 of balanced parentheses. The inductive hypothesis tells us that the grammar generates both w 1 and w 2, so we see that w is generated by the rule. Suppose w = (t) for some string t of balanced parentheses. Since t is shorter than w, our inductive hypothesis tells us that t is generated by the grammar. Therefore, w is generated by the rule (). Since all strings of balanced parentheses fall into one of the above three cases, we conclude that all strings of balanced parentheses are generated by the grammar. (b) (c) and and S asbs aasbs aabs aab S as aasbs aabs aab. S asbs asb aasb aab S as aasbs aasb aab. 6.1.1 (a) Online solution: (q, 01, Z 0 ) (q, 1, XZ 0 ) (q, ɛ, XZ 0 ), (p, 1, Z 0 ) (p, ɛ, Z 0 ), (p, ɛ, ɛ) 4

(b) (q, 0011, Z 0 ) (q, 011, XZ 0 ) (q, 11, XXZ 0 ), (p, 011, Z 0 ) (q, 1, XXZ 0 ), (p, 11, XZ 0 ) (q, ɛ, XXZ 0 ), (p, 1, XZ 0 ), (p, 11, Z 0 ), (p, 1, XXZ 0 ) (p, ɛ, XZ 0 ), (p, ɛ, XXZ 0 ), (p, 1, Z 0 ), (p, 1, ɛ), (p, 1, XZ 0 ), (p, ɛ, XXXZ 0 ) (p, ɛ, Z 0 ), (p, ɛ, ɛ) (c) (q, 010, Z 0 ) (q, 10, XZ 0 ) (q, 0, XZ 0 ), (p, 10, Z 0 ) (q, ɛ, XXZ 0 ), (p, 0, Z 0 ), (p, 0, ɛ) (p, ɛ, XZ 0 ) (p, ɛ, Z 0 ) 6.3.2 The PDA has just one state q and its transition function is given by δ(q, ɛ, S) = {(q, aaa)} δ(q, ɛ, A) = {(q, as), (q, bs), (q, a)} δ(q, a, a) = {(q, ɛ)} δ(q, b, b) = {(q, ɛ)} 6.4.2 (a) (b) 5

(c) 7.1.2 (a) Ṡ AS A A aas a aa SbS A bb bs Sb b (b) Ṡ AS A A aas a aa SbS aas a aa bb bs Sb b (c) All symbols are productive and reachable. (d) Now, we Chomskylize it: Ṡ AZ A A XY a XA SV XY a XA W W W S SW b Z S Y AS X a W b V W S 6

7.1.3 (a) Ṡ 0A0 11 00 11 A C S A C S (b) Ṡ 0S0 1S1 SS 00 11 A 0S0 1S1 SS 00 11 0S0 1S1 SS 00 11 C 0S0 1S1 SS 00 11 (c) Ṡ 0S0 1S1 SS 00 11 (d) Now, we Chomskylize it: Ṡ AC D SS AA A 0 1 C SA D S 7.2.1 (a) We choose a k b k+1 c k+2 to be our string that s in the language. The adversary selects one or two places to pump (if he picks two, they have to be no more than k symbols apart): If the adversary picks... a string containing more than one type of letter, a string containing b, and possibly a string containing a a string containing b, and possibly a string containing c string(s) containing only as string(s) containing only cs pump... times, so that... Example 2 the letters aaabbbbccccc get all mixed aaababbbbccccc up. 2 #(b) #(c) aaabbbbccccc aaaabbbbbccccc 0 #(a) #(b) aaabbbbccccc aaabbb c ccc 2 #(a) #(b) aaabbbbccccc aaaaaabbbbccccc 0 #(b) #(c) aaabbbbccccc aaabbbbc c 7

(b) We choose a k b k c k to be our string that s in the language. The adversary picks one or two places to pump: If he picks a string containing more than one type of letter, we can pump it twice to mix up the order of the letters. E.g., aaabbbccc aaababbbccc. If he picks string(s) containing only cs, we pump it twice to make #(c) > #(b). E.g., aaabbbccc aaabbbccccc. If he picks one string to contain some number of as and the other string to contain an equal number of bs, then we pump zero times to make #(c) > #(b). E.g., aaabbbccc aa b bccc. In any remaining cases, the adversary will have selected a differing number of as and bs, so we pump twice (or any number of times except once) to disequalize the as and bs. E.g., aaabbbccc aaabbbbcccc. (c) For this language, we use the PLL. Since the prime numbers grow weirdly, there are no infinite subsets of this language whose strings are a constant length apart. Therefore, the language is not contextfree. (d) We can use the PLL again. In this language, every string has length equal to i + i 2 for some integer i. Since the squares grow faster than linearly, there is no infinite subset of this language whose strings are a constant length apart. Therefore, the language is not context-free. (e) We choose our string to be a k b k c 2k and repeat the case analysis from part (b). (f) First, please note that every string in this language is divided into three parts: w, w R, and then w again. Notice that each of these three parts must contain exactly the same number of 0s and exactly the same number of 1s as each other. Every string in the language has this property. Now we choose our string t = 0 k 1 2k 0 2k 1 k, which has the form ww R w if we let w = 0 k 1 k. The adversary then selects one or two places to pump. Notice that the adversary cannot select portions from all three parts of t (by three parts, I mean w and w R and w). At best, he can affect only two of them. Assume that the adversary s selection is confined to the first two parts, leaving the third part unaffected. In this case, we pump zero times, creating a new shorter string t. Since t is shorter, each of its three parts must also be shorter. This means that the number of 1s in the last part of t is still exactly k, but the number of 0s in it is now strictly less than k. Now recall the fact that each of the three parts of t must have an equal number of 0s and an equal number of 1s. In order to balance out the numbers of 0s and 1s in all three parts of t, the adversary would have needed to select some 0s in both of the first two parts without selecting any 1s. However, this is impossible because the relevant 0s are too far apart (they are separated by 1 2k ). We win. 8

What if the adversary s selection is confined to the last two parts instead of the first two parts? Don t worry; the situation is completely symmetric. What if neither of the above two cases hold? Don t worry; the adversary can t make a selection that escapes both of the previous cases. 7.2.2 (a) If the adversary picks k > 2, then we cannot pick a long enough string in the language. (b) The adversary can pick k > 2. Then we ll have to pick a string in the language, and it must have the form 0 n 1 n for some n (simply because all strings in the language have this form). Then the adversary can select two places to pump: the first will be a 0, and the second will be a 1 (e.g. 00001111). Then, no matter how many times we pump, the number of 0s will remain equal to the number of 1s and the string will remain in the language. (c) The adversary can pick k > 2. Then we ll have to pick a palindrome w. If w has odd length, then the adversary can simply pick the middle digit; no matter how many times we pump, the string remains a palindrome. If w has even length, then the adversary can pick the two middle digits, which of course must be the same digit if w is a palindrome. Again, no matter how many times we pump, the string remains a palindrome. 7.4.3 Here s the grammar again: S A C A A a CC b C A a (a) Online solution in a different format: (b) Substring a b ab ba aba bab abab baba ababa Symbols A C S A S A C Since the last line contains the letter S, we see that ababa is in the language. 9

(c) Substring a b ba aa ab baa aaa aab baaa aaab baaab Symbols A C S A S A C S C Since the last line contains the letter S, we see that baaab is in the language. Substring a b aa ab ba aab aba bab aaba abab aabab Symbols A C S A S A C Since the last line contains the letter S, we see that aabab is in the language. 10