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

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

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

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

Intro to Theory of Computation

Context-Free Languages (Pre Lecture)

Context-Free Languages

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

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

PUSHDOWN AUTOMATA (PDA)

CSE 355 Test 2, Fall 2016

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

SCHEME FOR INTERNAL ASSESSMENT TEST 3

THEORY OF COMPUTATION (AUBER) EXAM CRIB SHEET

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

Introduction to Theory of Computing

Context-Free and Noncontext-Free Languages

Computational Models - Lecture 5 1

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

CISC 4090 Theory of Computation

The Pumping Lemma for Context Free Grammars

Chapter 16: Non-Context-Free Languages

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

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

Pumping Lemma for CFLs

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

CpSc 421 Final Exam December 15, 2006

MA/CSSE 474 Theory of Computation

CISC4090: Theory of Computation

Theory of Computation

Theory of Computation (IV) Yijia Chen Fudan University

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

Lecture 17: Language Recognition

Solution Scoring: SD Reg exp.: a(a

CISC 4090 Theory of Computation

Fundamentele Informatica II

(pp ) PDAs and CFGs (Sec. 2.2)

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

Properties of Context-Free Languages. Closure Properties Decision Properties

Computational Models - Lecture 4

DM17. Beregnelighed. Jacob Aae Mikkelsen

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

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

SFWR ENG 2FA3. Solution to the Assignment #4

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

(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},

Concordia University Department of Computer Science & Software Engineering

CS500 Homework #2 Solutions

UNIT-VI PUSHDOWN AUTOMATA

(pp ) PDAs and CFGs (Sec. 2.2)

Computational Models: Class 5

CS481F01 Prelim 2 Solutions

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

NPDA, CFG equivalence

Ogden s Lemma for CFLs

Context Free Languages: Decidability of a CFL

Outline 1 PCP. 2 Decision problems about CFGs. M.Mitra (ISI) Post s Correspondence Problem 1 / 10

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

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

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

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

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

Problem Session 5 (CFGs) Talk about the building blocks of CFGs: S 0S 1S ε - everything. S 0S0 1S1 A - waw R. S 0S0 0S1 1S0 1S1 A - xay, where x = y.

CS481F01 Solutions 6 PDAS

Computational Models - Lecture 4 1

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

Computational Models - Lecture 5 1

Properties of Context-free Languages. Reading: Chapter 7

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

Intro to Theory of Computation

CSE 468, Fall 2006 Homework solutions 1

10. The GNFA method is used to show that

Section 1 (closed-book) Total points 30

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

Chapter 6. Properties of Regular Languages

Automata and Computability. Solutions to Exercises

CSE 105 THEORY OF COMPUTATION. Spring 2018 review class

Introduction to computability Tutorial 7

Homework 5 - Solution

Automata and Computability. Solutions to Exercises

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

Theory of Computation (VI) Yijia Chen Fudan University

3130CIT Theory of Computation

Plan for 2 nd half. Just when you thought it was safe. Just when you thought it was safe. Theory Hall of Fame. Chomsky Normal Form

AC68 FINITE AUTOMATA & FORMULA LANGUAGES DEC 2013

CS154 Final Examination

CPSC 421: Tutorial #1

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

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

CSE 105 THEORY OF COMPUTATION

Sample Midterm. Understanding the questions is part of the exam; you are not allowed to ask questions during the exam.

Chapter 2 The Pumping Lemma

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

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.

CSE 105 THEORY OF COMPUTATION

5 Context-Free Languages

Theory of Computation - Module 3

Notes for Comp 497 (Comp 454) Week 5 2/22/05. Today we will look at some of the rest of the material in Part 1 of the book.

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

CSE 105 THEORY OF COMPUTATION

Transcription:

Problem 2.6(d) [4 pts] S X T#X X#T T#X#T X axa bxb #T# # T at bt #T ε Problem 2.12 [3pts] Original CFG: R XRX S S atb bta T XTX X ε X a b q start ε, ε $ ε, R X ε, ε R ε, ε X ε, R S ε, T X ε, T ε ε, X a ε, X b a, a ε b, b ε ε, ε R ε, $ ε q loop ε, S b ε, ε T ε, ε a ε, S a ε, ε T ε, ε b ε, T X ε, ε T ε, ε X qq accept start

Problem 2.13 [4 pts] (a) There are 2 cases: Case 1: The string contains exactly two # symbols. In this case, the string produced can have any number of zeros with the two # symbols. Case 2: The string contains exactly one # symbol. The string produced will have twice the amount of 0 s to the right of the # as to the left of the #. (b) Prove L(G) is not regular. We assume L(G) is a regular language, so there exists a pumping length p. We choose the string s to be 0 p #0 2p, which is in L(G) and the length of the string is 3p + 1 p. Thus, s can be divided into 3 pieces xyz satisfying the 3 conditions of the pumping lemma. Because xy p, then xy only contains 0 s to the left of the #. Since y > 0, it is safe to claim that y = 0 k, k > 0. xy 2 z = 0 p+k #0 2p which is not in the language L(G) since 2(p + k) > 2p. This contradicts the assumption that L(G) is a regular language. Therefore, we conclude that L(G) is not a regular language. Problem 2.14 [3 pts] Initial. A BAB B ε ε Step 1. Add new start symbol A BAB B ε ε Step 2. Remove ε rules Remove B ε A BAB BA AB A B ε Remove A ε A BAB BA AB A B BB Step 3. Remove unit rule Remove A A ε A BAB BA AB B BB Remove A B S 0 BAB BA AB 00 BB ε A BAB BA AB 00 BB

Step 4. Convert rules to proper form Replace terminal 0 with variable U S 0 BAB BA AB UU BB ε A BAB BA AB UU BB B UU U 0 Shorten length 3 rules. S 0 BAB replaced with S 0 BA 1 and A 1 AB And A BAB replaced with A BA 2 and A 2 AB S 0 BA 1 BA AB UU BB ε A BA 2 BA AB UU BB B UU U 0 A 1 AB A 2 AB Problem 2.25 [4 pts] Note: Either method is acceptable. Proof: Method 1: Construct a PDA that accepts the suffixes of A. Because A is context-free, there must be a PDA accepting A, call it M1. Then, do the following: (1) Make a copy of M1, and call it M2. M2 has exactly the same states, stack, and transitions as M1. Together M1 and M2 form the whole PDA M. (2) Change the input part of transitions in M2 from what it was to ε, while keeping the stack the same. (i.e. if the original transition was a, b ε, we change it to ε, b ε. (3) For each state in M2, add a transition ε, ε ε to the corresponding state in M1. (4) Let the start of M2 be the start state of PDA M. M will construct the stack appropriately and ignore the input. At some point of time, M nondeterministically transitions from the state in M2 to the corresponding state in M1, then starts to take the first character of the suffix as the input, and makes transition in M1 from then on. Therefore, all the suffixes of the string belonging to A will be accepted by M. Problem 2.30(a,d) [4 pts each] Proof of part (a). Assume A is a context-free language. So it must satisfy the pumping lemma for CFLs. Let p be the pumping length. Consider the string s = 0 p 1 p 0 p 1 p, where p A and s > p. According to the pumping lemma, s may be divided into 5 pieces, s = uvxyz, and the division satisfies the three constraints of the pumping lemma. Since vxy p and vy > 0, vxy may not contain two sets of 0 or 1 symbols.

Case 1: v and y only contain one symbol, i.e. vxy = 0 l, vxy = 1 l, where 0 < l p. If vxy = 0 l, then for i = 2, uv 2 xy 2 z = 0 p+l 1 p 0 p 1 p A or uv 2 xy 2 z = 0 p 1 p 0 p+l 1 p A. Therefore, vxy 0 l. Similarly, we can prove vxy 1 l. Case 2: v and y contain two symbols, i.e. vxy = 0 l 1 r or vxy = 1 r 0 l, where 0 < l + r p. If vxy = 0 l 1 r, then for i = 2, uv 2 xy 2 z = 0 p+l 1 p+r 0 p 1 p A or uv 2 xy 2 z = 0 p 1 p 0 p+l 1 p+r A. So, vxy 0 l 1 r. Similarly, vxy 1 r 0 l. Case 3: v or y contains both 0 and 1, i.e. v = 0 l 1 r and y = 1 k ; or v = 1 r 0 l and y = 0 k, where 0 < l + r p. If v = 0 l 1 r, then for i = 0, uv 0 xy 0 z = 0 p l 1 p r k 0 p 1 p A or uv 0 xy 0 z = 0 p 1 p 0 p l 1 p r k A. Similarly, v 1 r 0 l. In all possible cases, there is a violation of the pumping lemma. Thus, the original assumption of A being context-free is incorrect. Therefore, A is not a context-free language. Proof of part (d). Assume A is a context-free language. So it must satisfy the pumping lemma for CFLs. Let p be the pumping length. Consider the string s = a p b p #a p b p, where s A and s > p. According to the pumping lemma, s may be divided into 5 pieces, s = uvxyz, and the division satisfies the three constraints of the pumping lemma. Case 1: vxy is in either a p b p part of s. In this case, consider uv i xy i z for i = 0 or i > 0, the number of a s and b s will be unbalanced on both sides of s separated by the #, violating the pumping lemma. Case 2: vxy contains the # part of s. Subcase a: x contains the #. In this case, consider uv i xy i z for i = 0 or i > 0, v consists of b s and y contains only a s. However the number of a s and b s will be unequal on either side of s separated by the #, violating the pumping lemma. Subcase b: v or y contains the #. Suppose v contains the #. In this case, consider uv 0 xy 0 z this resulting string does not contain a # so s A. Similarly, when y contains the #. In all possible cases, there is a violation of the pumping lemma. Thus, the original assumption of A being context-free is incorrect. Therefore, A is not a context-free language. Problem 2.31 [4 pts] Assume B is a context-free language. So it must satisfy the pumping lemma for CFLs. Let p be the pumping length. Consider the string s = 0 p 1 2p 0 p, where p A and s > p. According to the pumping lemma, s may be divided into 5 pieces, s = uvxyz, and the division satisfies the three constraints of the pumping lemma.

Case 1: vxy contains only 1 s. In this case, consider uv 2 xy 2 z B, since it will no longer have the same number of 0s and 1s. Case 2: vxy contains at least one 0. Consider uv 2 xy 2 z B, because it will no longer be a palindrome since xvy can only symbols from the starting 0s or the final 0s, but not both. Hence, after pumping s will no longer have the same number of 0s before and after the 1s. In both possible cases, the pumping lemma is violated. Therefore, the original assumption of B being a context-free language is contradicted. Therefore, B is not a CFL.