Section 1 (closed-book) Total points 30

Similar documents
Concordia University Department of Computer Science & Software Engineering

AC68 FINITE AUTOMATA & FORMULA LANGUAGES DEC 2013

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

SFWR ENG 2FA3. Solution to the Assignment #4

CSE 355 Test 2, Fall 2016

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

Foundations of Informatics: a Bridging Course

CS20a: summary (Oct 24, 2002)

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

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Properties of Context-Free Languages

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

Pushdown Automata. Reading: Chapter 6

Computability and Complexity

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

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

CpSc 421 Final Exam December 15, 2006

MTH401A Theory of Computation. Lecture 17

Einführung in die Computerlinguistik

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

MA/CSSE 474 Theory of Computation

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

Introduction to Theory of Computing

Theory of Computation - Module 3

Theory Bridge Exam Example Questions

This lecture covers Chapter 7 of HMU: Properties of CFLs

CS375: Logic and Theory of Computing

Fundamentele Informatica II

THEORY OF COMPUTATION (AUBER) EXAM CRIB SHEET

Properties of Context-free Languages. Reading: Chapter 7

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

CSE 105 THEORY OF COMPUTATION

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

Theory of Computation

Miscellaneous. Closure Properties Decision Properties

V Honors Theory of Computation

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

CS481F01 Prelim 2 Solutions

Automata and Computability. Solutions to Exercises

5 Context-Free Languages

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

NPDA, CFG equivalence

CPS 220 Theory of Computation

Context Free Languages (CFL) Language Recognizer A device that accepts valid strings. The FA are formalized types of language recognizer.

SCHEME FOR INTERNAL ASSESSMENT TEST 3

Automata and Computability. Solutions to Exercises

Languages. Languages. An Example Grammar. Grammars. Suppose we have an alphabet V. Then we can write:

Context Free Language Properties

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

Context-Free Grammars and Languages. Reading: Chapter 5

CS500 Homework #2 Solutions

Context-Free and Noncontext-Free Languages

Properties of Context-Free Languages. Closure Properties Decision Properties

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

Context-Free Languages (Pre Lecture)

CISC4090: Theory of Computation

Theory of Computation Turing Machine and Pushdown Automata

Properties of context-free Languages

AC68 FINITE AUTOMATA & FORMULA LANGUAGES JUNE 2014

CPS 220 Theory of Computation Pushdown Automata (PDA)

CISC 4090 Theory of Computation

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

Computational Models - Lecture 4

CS154 Final Examination

An automaton with a finite number of states is called a Finite Automaton (FA) or Finite State Machine (FSM).

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,

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

MA/CSSE 474 Theory of Computation

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

Context-free Grammars and Languages

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

Testing Emptiness of a CFL. Testing Finiteness of a CFL. Testing Membership in a CFL. CYK Algorithm

Solution Scoring: SD Reg exp.: a(a

Automata Theory CS F-08 Context-Free Grammars

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

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

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

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

COMP-330 Theory of Computation. Fall Prof. Claude Crépeau. Lec. 10 : Context-Free Grammars

(pp ) PDAs and CFGs (Sec. 2.2)

CS154 Final Examination

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

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

Computational Models - Lecture 5 1

FLAC Context-Free Grammars

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

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

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

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

The Pumping Lemma for Context Free Grammars

SYLLABUS. Introduction to Finite Automata, Central Concepts of Automata Theory. CHAPTER - 3 : REGULAR EXPRESSIONS AND LANGUAGES

Homework Assignment 6 Answers

Theory of Computation (Classroom Practice Booklet Solutions)

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

CISC 4090 Theory of Computation

Parsing. Context-Free Grammars (CFG) Laura Kallmeyer. Winter 2017/18. Heinrich-Heine-Universität Düsseldorf 1 / 26

CSE 105 THEORY OF COMPUTATION

Languages, regular languages, finite automata

(pp ) PDAs and CFGs (Sec. 2.2)

Transcription:

CS 454 Theory of Computation Fall 2011 Section 1 (closed-book) Total points 30 1. Which of the following are true? (a) a PDA can always be converted to an equivalent PDA that at each step pops or pushes a single symbol (but not both). (b) a PDA can be converted to an equivalent PDA that always empties its stack before entering an accepting state. (c) a PDA can always be converted to an equivalent PDA that has exactly one accepting state. Choose the correct answer: (1) (a) and (c) (2) (a) and (b) (3) all of them (4) (a) only (5) none of them. 2. Under which operations are context free languages closed? (a) union (b) complement (c) intersection Choose the correct answer: (1) (a) and (c) (2) (a) and (b) (3) all of them (4) (a) only (5) none of them. 3. Let L be a regular language. Which of the following are true? (a) L is context free. (b) there is a regular expression for L. (c) the complement of L is context free. Circle the correct answer: A. (a) and (b) only B. (a) and (c) only C. (b) and (c) only D. All of them are true. E. None of them are true. 4. Complete the following sentences using phrases (1) (4) given below: (a) A sentential form is a string consisting of any sequence of 2 (b) A leftmost derivation involves replacing 4 in a sentential form. (c) A derivation tree has 1 at the root node. (d) there are at least two 3 for some string generated by an ambiguous grammar. (1) start symbol (2) terminals and nonterminals (3) leftmost derivations (4) leftmost nonterminal 5. Let A and B be two languages over {0,1} such that A is a subset of B. Consider the following statements:

(1) If B is finite, then A is finite. (2) If B is regular, then A is regular. (3) If the complement of B is context free, then the complement of A is context free. Which of the above statements is true? Circle the correct option. (A) 1 only (B) 1 and 2 only (C) 1 and 3 only (D) 2 and 3 only (E) all of them are true. 6. Under which of the operations are the regular languages closed? (1) union (2) intersection (3) concatenation (4) complement Circle the correct choice. (A) 1 only (B) 2 and 3 only (C) 1 and 3 only (D) 1 and 2 only (E) all of them are true. 7. Let P be the PDA <Q, Σ, Γ, δ, q0, Z0, F>. Consider the ID (configuration) <q, x, γ> where q is the current state, x is the part of the input not yet read, and γ is the string stored in the stack. Write the condition for the ID to be an accepting ID. <q, x, γ> where q is in F, x = ε 8. Define Chomsky Normal Form. (State the allowed formats of the rules in Chomsky Normal Form). It is a CFG in which all the rules are of the form A BC (where B, C are non-terminals) or A a (a is a terminal). In addition, S e is an allowed rule. (However S e is not allowed for any A!= S.) 9. The significance of a universal Turing machine is that: (a) it gave a precise mathematical definition of an algorithm. (b) it showed a Turing machine to be more powerful than a PDA. (c) it provided a basis for creating a general purpose computer. (d) it was used to show that 1 tape Turing machines are equivalent to 2 tape Turing machines. 10. State the pumping lemma for context free languages. For every CFL L, there is a constant p (that depends only on L) such that for any string s in L of length at least p, there exist strings u, v, w, x and y such that s = uvwxy, vx > 0 (i.e., at least one of v or x is non-null), vwx <= p and for every j, uv j wx j y is L.

CS 454 Theory of Computation Fall 2011 Section 2 (open-book) Total points 70 Answer any FIVE questions. Each question will be weighted 14 points. Provide an informal explanation of answers before a formal construction. 1. Write a context free grammar G for the complement of the language L over {a,b}: L = { a n b n n > 0 } (First describe the complement of L.) Exhibit a leftmost derivation of the string aaabb for G. Solution: L = complement of L = L1 U L2 U L3 U L4 where L1 = { a n b m n > m >= 0 }, L2 = { a n b m 0 <= n < m }, L3 = { w w is not of the form a*b*} and L4 = {ε} CFG for L1 is A aa B, B abb ε CFG for L2 is C Cb B, B abb ε CFG for L3 is D EbaE, E ae be ε CFG for L4 is F ε Finally, CFG for L is the set of all productions above combined with S A C D F Leftmost derivation for aaabb: S => A =>aa =>ab=>aabb=>aaabbb=>aaabb 2. Describe a PDA for the language L = { w w is in {0,1}*, length of w is odd and the middle symbol in w is 1}. Exhibit the sequence of configurations leading to acceptance of the string 10100 in M. Informal solution: as with other PDA s, first add $ to the stack. Then, in state q1, push an A for each 0 and 1 seen until the middle symbol is reached. Then, if a 1 is encountered, then

move to state q2. Now we have to check that the transition made was really on the middle symbol. This is done by counting the number of remaining input symbols and checking that it is equal to the number of symbols on the stack. If successful verification is made, then when all the input symbols have been read, the stack must have only $ symbol left. So at this point, move to the accepting state q3. To accept string 10100: (e stands for null string.) (q0, 10100, e) (q1, 10100, $) (q1, 0100, A$) (q1, 100, AA$) (q2, 00, AA$) (q2, 1, A$) (q2, e, $) (q3, e, e). 3. Prove using pumping lemma that the language L = { a n b m n, m > 0 and m = n 2 } is not context free. Suppose L is context-free. Let p be the pumping constant for L. I choose a string s of length at least p in L, namely s = a p b p^2. Consider an arbitrary partition of s into u, v, w, x and y such that s = uvwxy with the condition that vx > 0 and vwx < p. If either v or x is non-uniform, then pumping twice we give a string that is not of the form a*b*. So, we assume that both v and x are uniform. If both v and x consisted only a s, then pumping twice we increase the number of a s without changing the number of b s so clearly the resulting string is not in L. Similar argument also holds if both v and x consisted of b s. (namely pumping twice, we will increase the number of b s, but the number of a s remains the same.) Also if v or x is null, then pumping twice, the number of a s or b s increases while the other remains unchanged so the resulting string is not in L. So the only case that we have considered is the one in which v consists of a s, and x consists of b s. namely, v = a^t, x = b^s for some t > 0 and s > 0. Note that t + s < p. Pumping twice, we get the string s = a^(p+t) b^(p^2+s). Since t + s < p, it follows that s < p as well. For the resulting string s to be in L, p^2 + s must be equal to (p+t)^2. However, (p+t)^2 >= (p+1)^2, while p^2 + s < p^2 + p < (p+1)^2. This finally shows that L is not contextfree. 4. Shown below is a PDA M. Use the algorithm described in the text (Lemma 2.27) to convert M into an equivalent Context free grammar.

1 Solution: (in this solution e stands for non symbol ε.) For each state pair of states, we have a nonterminal such as [AA], [AB] etc. Rules: (1) [AA] e, [BB] e, [CC] e, [DD] e. (2) [PR] [PQ][QR] for all P, Q, R in {A, B, C, D}. (There are 64 such rules). (3) choose a push move, and a corresponding pop move. There are 8 such pairs. Each one generates a rule: PAIR 1: (e, e $) from A to B and (e, $ e) from B to D This adds the rule [AD] [BB] PAIR 2: (e, e $) from A to B and (e, $ e) from C to D This adds the rule [AD] [BC] PAIR 3: (e, e $) from A to C and (e, $ e) from B to D This adds the rule [AD] [CB] PAIR 4: (e, e $) from A to C and (e, $ e) from C to D This adds the rule [AD] [CC] PAIR 5: (a, e 1) from B to B and (b, 1 e) from B to B This adds the rule [BB] a[bb]b PAIR 6: (a, e 1) from B to B and (a, 1 e) from C to C This adds the rule [BC] a[bc]a PAIR 7: (b, e 1) from C to C and (b, 1 e) from B to B This adds the rule [CB] b[cb]b PAIR 8: (b, e 1) from C to C and (a, 1 e) from C to C This adds the rule [CC] b[cc]a 5. Design a single tape Turing machine for the language L over {a, b, c} defined as follows: L = { a n b m c n+m n, m >= 0 }. First describe your solution informally identifying the role of each state. Also state clearly the tape alphabet used and the role of additional tape symbols used, if any. Then draw the transition diagram. Informal solution 1: The obvious solution will be to first make a sweep making sure that the input is of the form a*b*c* (if not reject), then start replace an a or b with a

1, then move right until it finds a c replace it with 2, sweep back until it finds a 1, move right and repeat the process. While sweeping right looking for a 2, if no c is found, the input is rejected. During the last pass (this happens when it moves right on seeing a 1, looking for an a or b, it finds a 2), if any 2 is encountered the input is rejected. Else the input is accepted. The above solution has complexity O(n 2 ). Solution 2: This one has time complexity O(n log n). Do the same as in the first pass, checking that the input is in the form a*b*c*. Then, mark off every other a and b, and remember the parity of the number of a s + number of b s. Do the same for c s. If the parities don t match, then reject. Else repeat. Since half of the input string gets replaced by 1 s and 2 s each time, the number of passes needed is O(log n) and since each pass involves O(n) moves, the total number of moves is O(n log n). 6. (a) Convert the following CFG G1 into Chomsky Normal Form: S A1B A 0A ε B 0B 1B ε Remove A ε by adding S 1B, A 0. Similarly Remove B ε and add S A1, B 0, B 1. Finally, replace S A1B by S AP, P QB, Q 1. Thus the final grammar is: S AP, P QB, Q 1, S AQ, B 0, B 1 S QB, A 0 A RA, R 0 B RB QB (b) Exhibit three strings that can t be generated using the grammar G1 and three strings that can be generated using G1. Strings that can be generated: 1, 011, 100 Strings not generated: 0, 00, 0000 etc. 7. (a) Shown below is a CFG G over the alphabet {+, *, a, b} : S +SS *SS a b Use the algorithm presented in class for converting CFG to PDA to construct a PDA equivalent to G.

(b) Which of the following strings can be generated using G? (1) ++++aba (2) +*aab+*a (3) **+ab*baa Only (3) can be generated. (c) Exhibit a derivation sequence for the string *+aaa in the PDA you constructed in (a). <q0, *+aaa, e) => <q1, *+aaa, S$> => < q1, *+aaa, *SS$> => <q1, +aaa, SS$> <q1, +aaa, +SSS$> => <q1, aaa, SSS$> => <q1, aaa, ass$> <q1, aa, SS$> => <q1, aa, as$> => <q1, a, S$> => <q1, a, a$> => <q1, e, $> <q2, e, e>