Solution Scoring: SD Reg exp.: a(a

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

THEORY OF COMPUTATION (AUBER) EXAM CRIB SHEET

CSE 355 Test 2, Fall 2016

CISC4090: Theory of Computation

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

MA/CSSE 474 Theory of Computation

Functions on languages:

Introduction to Theory of Computing

SCHEME FOR INTERNAL ASSESSMENT TEST 3

MA/CSSE 474 Theory of Computation

AC68 FINITE AUTOMATA & FORMULA LANGUAGES DEC 2013

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

V Honors Theory of Computation

Section 1 (closed-book) Total points 30

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

Undecidable Problems and Reducibility

Pushdown Automata (Pre Lecture)

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

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

The Pumping Lemma for Context Free Grammars

Context-Free and Noncontext-Free Languages

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

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

CpSc 421 Final Exam December 15, 2006

Computational Models - Lecture 4

Finite Automata Theory and Formal Languages TMV026/TMV027/DIT321 Responsible: Ana Bove

Equivalence of CFG s and PDA s

CS154 Final Examination

CISC 4090 Theory of Computation

Midterm Exam 2 CS 341: Foundations of Computer Science II Fall 2018, face-to-face day section Prof. Marvin K. Nakayama

CPSC 421: Tutorial #1

DM17. Beregnelighed. Jacob Aae Mikkelsen

Theory of Computation

10. The GNFA method is used to show that

Theory of Computation (IV) Yijia Chen Fudan University

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

Pumping Lemma for CFLs

Computational Models - Lecture 4 1

Theory of Computation Turing Machine and Pushdown Automata

Context-Free Languages (Pre Lecture)

CS154 Final Examination

Midterm Exam 2 CS 341: Foundations of Computer Science II Fall 2016, face-to-face day section Prof. Marvin K. Nakayama

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

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

The View Over The Horizon

Theory of Computation (Classroom Practice Booklet Solutions)

Lecture 17: Language Recognition

Context Free Languages: Decidability of a CFL

Theory Bridge Exam Example Questions

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

5 Context-Free Languages

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

Foundations of Informatics: a Bridging Course

CSE 105 THEORY OF COMPUTATION

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

Homework 5 - Solution

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

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

Fundamentele Informatica II

Pushdown Automata. Chapter 12

Harvard CS 121 and CSCI E-207 Lecture 10: Ambiguity, Pushdown Automata

The Unsolvability of the Halting Problem. Chapter 19

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

Part I: Definitions and Properties

Notes for Comp 497 (454) Week 10

Automata Theory - Quiz II (Solutions)

Final exam study sheet for CS3719 Turing machines and decidability.

Properties of Context-Free Languages

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 (PDA)

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

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

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

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

Automata Theory (2A) Young Won Lim 5/31/18

UNIT-VI PUSHDOWN AUTOMATA

Accept or reject. Stack

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

CS5371 Theory of Computation. Lecture 14: Computability V (Prove by Reduction)

CISC 4090 Theory of Computation

DD2371 Automata Theory

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

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

Turing machines Finite automaton no storage Pushdown automaton storage is a stack What if we give the automaton a more flexible storage?

INSTITUTE OF AERONAUTICAL ENGINEERING

Computability and Complexity

CPS 220 Theory of Computation

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

Automata and Computability. Solutions to Exercises

Miscellaneous. Closure Properties Decision Properties

Pushdown Automata. Reading: Chapter 6

Equivalent Variations of Turing Machines

Introduction to Languages and Computation

FORMAL LANGUAGES, AUTOMATA AND COMPUTATION

Einführung in die Computerlinguistik

CS481F01 Prelim 2 Solutions

Automata and Computability. Solutions to Exercises

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

THEORY OF COMPUTATION

Computational Models - Lecture 5 1

Transcription:

MA/CSSE 474 Exam 3 Winter 2013-14 Name Solution_with explanations Section: 02(3 rd ) 03(4 th ) 1. (28 points) For each of the following statements, circle T or F to indicate whether it is True or False. If it is sometimes False, you should choose False. You do not have to give proofs or counterexamples. For each part, you get 2 points for circling IDK (I don't know), 4 for circling the correct answer, 0 for leaving it blank, and -1for circling the incorrect answer. In order to be lazy in writing this solution, I am using Theorem numbers from the textbook. Of course I did not expect you to know them by number. a) T F IDK Some languages are not decidable, but every language is semi-decidable. H is in SD but not in D. If H were in SD also, then we could simultaneously run TMs for H and H. If H machine halts and accepts, accept; if H machine halts and accepts, reject. One or the other must halt and accept. Thus H would be decidable. But it's not! b) T F IDK If R is regular and R L is not context-free, then L is not context-free. This is the contrapositive of Theorem 13.7 c) T F IDK The complement of every context-free language is non-context-free. Σ* and are both CF. d) T F IDK Every context-free language is decidable. Theorem 14.1 e) T F IDK The set of decidable languages is closed under complement. If L is decidable, there is a TM M that always halts and ends up in stare y or n. Make a TM M' that is identical to M except reverse the positions of y and n. M' decides L. f) T F IDK The set of semidecidable languages is closed under complement. See part a. g) T F IDK The set of non-semidecidable languages is closed under complement. Consider H, as in part a. 2. (30 points) For each of the following languages, circle R if the language is Regular, CF if it is Context-free but not Regular, D if it is Decidable but not Context-free SD if it is Semidecidable but not Decidable SD if it is not Semidecidable IDK if you don't know. Scoring: Correct answer 3, IDK 1, incorrect answer 0. a) R CF D SD SD IDK WW R = {ww R : w {a,b}*}. Example 11.3 b) R CF D SD SD IDK { <M> : where M is a TM with 5 states, and tape alphabet {, a}}. It's finite. c) R CF D SD SD IDK {a n : n 0}. a* is a reg. exp. For it. d) R CF D SD SD IDK {a n b n : n 0}. Examples 8.8, 11.2 e) R CF D SD SD IDK {a n b n b n : n 0}. S ε asbb. Easy to use Pumping Theorem to show non-regular. f) R CF D SD SD IDK {<M, w> : TM halts when started with input w}. Theorems 19.1, 19.2 g) R CF D SD SD IDK {<M, w> : TM does not halt when started with input w}. See problem 1, part a h) R CF D SD SD IDK {wxw R : w,x {a,b}+}. Reg exp.: a(a b)a b(a b)b i) R CF D SD SD IDK L(G), where G = {S TSb S Tb, T Ta, T }. It's {a}* j) R CF D SD SD IDK {x#y#z : x, y, z {a, b}+ and ( x - y = 2 or y - z = 2}. S A # X X # B A C A C /* x - y = 2 A C C C # C B C B C /* y - z = 2 B C C C # C C a b X C X X C C L is not regular, which we show by pumping. Let w = a k+2 #a k #a k+2. y must occur in the first a region and must be a p for some nonzero p. Pump in. The three regions of the resulting string are now of the following lengths: x: k + 2 + p y: k z: k + 2 So neither of the required conditions is met and the resulting string is not in L.

3. (20 points) Let G be the grammar S SS (S) ε. L(G) is the language Bal of all strings of balanced parentheses; that is, those strings that could appear in a wellformed arithmetic expression. We may want to show that L(G) = Bal, which requires two inductive proofs: If w is in L(G), then w is in Bal. If w is in Bal, then w is in L(G). We shall here prove only the first part. You will see below the sequence of steps in the proof, each with the reason for its validity omitted. These reasons belong to one of three classes. You do not have to write out reasons; just correctly choose and write A, B, or C in each blank. There are ten such blanks. A) Use of the inductive hypothesis. B) Reasoning about properties of grammars, e.g., that every derivation has at least one step. C) Reasoning about properties of strings, e.g., that every string is longer than any of its proper substrings. The proof is by induction on the number of steps in the derivation of w. Basis: One step. The only 1-step derivation of a terminal string is S => ε because (B) this production is the only one with only terminals in the body. ε is in Bal because (C) the empty string trivially has only balanced parenthesis. It is, for example, the "parentheses" in an expression like x that has no parentheses. Induction: An n-step derivation for some n>1. The derivation S => n w is either of the form (a) S => SS => n-1 w or of the form (b) S => (S) => n-1 w because _ (B) these are the only productions that allow further steps, i.e., they have at least one nonterminal in the body. Case (a): w = xy, for some strings x and y such that S => p x and S => q y, where p<n and q<n because (B) two adjacent nonterminals in a sentential form generate adjacent terminal strings and share the steps between them in some order. x is in Bal because (A) the inductive hypothesis. y is in Bal because (A) the inductive hypothesis w is in Bal because (C) the concatenation of strings with balanced parentheses also has balanced parentheses. Case (b): w = (z) for some string z such that S => n-1 z because (B) a nonterminal generates a terminal string that sits between whatever comes from the symbols to the left and right of that nonerminal. z is in Bal because (A) the inductive hypothesis w is in Bal because (C) a pair of parentheses surrounding a string with balanced parentheses is itself balanced. 4. (10 points) What are the two ways that a nonterminal symbol in a CFG can be useless? a) Unreachabe from the start symbol b) Can not generate any strings of only terminal symbols

5. (10 points) Here is a context-free grammar G: S AB CD A BG 0 B (B ε), D (D BB), G (G BD), A (A BG), S(S AB) B AD ε C CD 1 D BB E E AF B1 F EG 0C G AG BD In the list below, Circle each nullable symbol of G and do not circle non-nullable symbols. S A B C D E F G 0 1 6. (15 points) Here are eight simple grammars, each of which generates an infinite language of strings. These strings tend to look like alternating a's and b's, although there are some exceptions, and not all of the grammars generate all such strings. a) S abs ab (ab)* b) S SS ab (ab)* c) S ab; B bs a a(ba)*a d) S ab; B bs b (ab)* e) S ab; B bs ab a(ba)*ab f) S ab b; B bs (ab)*b g) S ab a; B bs (ab)*a h) S ab ab; B bs (ab)* For each of the following grammar pairs, circle Y if those two grammars generate the same language, and N if they do not. a and f a and b c and f d and g (I intended to write "d and h" and have the answer be y, so if there is a bit of a mess on your paper ) e and h

7. (15 points) The language L = {ss s is a string of a's and b's} is not a context-free language. In order to prove this, we need to show that for every integer k, there is some string w in L, of length at least k, such that no matter how we break w up as w=uvxyz, subject to the constraints vxy k and vy > 0, there is some q 0 such that uv q xy q zis not in L. Let us focus on a particular k=7 and w=aabaaaba. It turns out that this is not a good choice of w for k= 7, since there are some ways to break w up for which we can find the desired q, and other ways of breaking it up for which we cannot. Identify from the list below the choices of u,v,x,y,z for which there is an q that makes uv q xy q z not be in L. We show the breakup of aabaaaba by placing four 's among the a's and b's. The resulting five pieces (some of which may be empty) are the five strings. For instance, aa b aaaba means u=aa, v=b, x=ε, y=aaaba, and z=ε. For each way of breaking up the string, circle Y if this way of breaking up the string allows pumping to take us outside of L, and N if every choice of q keeps the pumped string in L. aab a aab a aa ba aa ba aa b aa aba aab a a a ba pump out (q=0) to get aababa a abaa a ba 8. (8 points) Consider the pushdown automaton with the following transition rules: 1. δ(q, ε, ε) = {(q, Z 0)} 2. δ(q,0,z 0) = {(q,xz 0)} 3. δ(q,0,x) = {(q,xx)} 4. δ(q,1,x) = {(q,x)} 5. δ(q,ε,x) = {(p,ε)} 6. δ(p,ε,x) = {(p,ε)} 7. δ(p,1,x) = {(p,xx)} 8. δ(p,1,z 0) = {(p,ε)} The start state is q. For which of the following inputs can the PDA enter state p for the first time with the input empty and the stack containing XXZ 0 [i.e., the configuration (p,ε,xxz 0)]? Mark the correct such input. Only one is correct. 0101010 _ X 011011011 011001101 1001101 When in state q, the PDA adds an X to the stack whenever it consumes a 0. The PDA may consume a 1 with no change to the stack, but only if the stack has top symbol X. That is, on inputs beginning with 1 the PDA has no choice of move and can never enter state p. Since entering state p pops an X from the stack, there must be exactly three 0's in the consumed inputs, and any number of 1's. In addition, the first input symbol must be 0.

9. (7 points) Start with the grammar G: See top of p 262. S AS A A 0A 1B 1 B 0B 0 If we use the nondeterministic top-down parsing algorithm from class (and the textbook) to convert this grammar to a PDA, which of the following transitions are part of the PDA? Circle Y if the given transition is part of the PDS, and N if it is not. p is the start sate, q is the accepting state (don't forget that in order to accept a string w, the stack must also be empty after reading w). ((p, ε, ε),(q, S)) ((p, ε, S), (q, ε)) ((q, ε, S), (q, AS)) ((q, ε, A), (q, A0)) ((q, ε, A), (q, 1)) ((q, 1, 1), (q, ε)) ((q, 1, ε), (q, 1))

10. (20) Consider the following TM M. Try to figure out what M does when started with a string of a's and b's (you do not have to describe what it does in general, but understanding that will help you answer the questions. For each of the two inputs below, if M is started with that input on its tape, show the tape contents after M halts. Recall that a TM always starts with its read/write head at the last blank square before the input string. The machine "blanks out" a's and b's, but whenever it finds a substring ab, it goes all the way right and adds a 1 at then end of the string. When it halts, the tape contains a 1 for every ab substring in the original input. Input: baabaaabaaaab Output: 1 1 1 Each a and b gets erased when it is encountered. Every time there is an ab in the input, we move right and write a 1. So the machine counts (in unary) the number of times that ab occurs in the input string. Input: abbabbbabbbba Output: 111 11. (7 points) Where does the "k" in the statement of the Pumping Theorem for context-free languages come from? [Hint: for a regular language, k is the number of states in a DFSM that recognizes the language.] A brief answer (two or three sentences) is probably sufficient to let me know you have the idea.. Let G, a grammar for L, have N nonterminals and branching factor b. If a string in L(G) is longer than b N, there must be at least one path from the root of the parse tree that has a repeated nonterminal; subtrees of these nonterminals is the basis for the parts that get pumped.