Name: CS 341 Practice Final Exam. 1 a 20 b 20 c 20 d 20 e 20 f 20 g Total 207

Similar documents
Recursively Enumerable Languages, Turing Machines, and Decidability

CS21 Decidability and Tractability

Theory of Computation Dr. Weiss Extra Practice Exam Solutions

Theory of Computations Spring 2016 Practice Final Exam Solutions

The Big Picture. Chapter 3

Final Exam 2, CS154. April 25, 2010

Turing Machines. A transducer is a finite state machine (FST) whose output is a string and not just accept or reject.

CS 44 Exam #2 February 14, 2001

Theory of Computation, Homework 3 Sample Solution

Final Exam 1, CS154. April 21, 2010

We show that the composite function h, h(x) = g(f(x)) is a reduction h: A m C.

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

Outline. Language Hierarchy

CSE 105 THEORY OF COMPUTATION

Introduction to Computers & Programming

1. Draw the state graphs for the finite automata which accept sets of strings composed of zeros and ones which:

CSC-461 Exam #2 April 16, 2014

Theory of Languages and Automata

Final Course Review. Reading: Chapters 1-9

CS6160 Theory of Computation Problem Set 2 Department of Computer Science, University of Virginia

Theory of Computations Spring 2016 Practice Final

1 Parsing (25 pts, 5 each)

The Turing Machine. Unsolvable Problems. Undecidability. The Church-Turing Thesis (1936) Decision Problem. Decision Problems

CpSc 421 Final Solutions

Lecture 7: Primitive Recursion is Turing Computable. Michael Beeson

Turing Machine Languages

Closure Properties of CFLs; Introducing TMs. CS154 Chris Pollett Apr 9, 2007.

ECS 120 Lesson 16 Turing Machines, Pt. 2

CSE 120. Computer Science Principles

6.045J/18.400J: Automata, Computability and Complexity. Practice Quiz 2

Material from Recitation 1

Enumerations and Turing Machines

Limitations of Algorithmic Solvability In this Chapter we investigate the power of algorithms to solve problems Some can be solved algorithmically and

Theory Bridge Exam Example Questions Version of June 6, 2008

Variants of Turing Machines

University of Nevada, Las Vegas Computer Science 456/656 Fall 2016

From Theorem 8.5, page 223, we have that the intersection of a context-free language with a regular language is context-free. Therefore, the language

CSE 105 THEORY OF COMPUTATION

CS 531: Notes II. January 31, 2014

6. Advanced Topics in Computability

We can create PDAs with multiple stacks. At each step we look at the current state, the current input symbol, and the top of each stack.

Final Exam May 8, 2018

Midterm Exam II CIS 341: Foundations of Computer Science II Spring 2006, day section Prof. Marvin K. Nakayama

14.1 Encoding for different models of computation

Actually talking about Turing machines this time

Multiple Choice Questions

Theory of Programming Languages COMP360

Regular Languages (14 points) Solution: Problem 1 (6 points) Minimize the following automaton M. Show that the resulting DFA is minimal.

R10 SET a) Construct a DFA that accepts an identifier of a C programming language. b) Differentiate between NFA and DFA?

CS402 - Theory of Automata Glossary By

Equivalence of NTMs and TMs

1. [5 points each] True or False. If the question is currently open, write O or Open.

TAFL 1 (ECS-403) Unit- V. 5.1 Turing Machine. 5.2 TM as computer of Integer Function

pp Variants of Turing Machines (Sec. 3.2)

Lec-5-HW-1, TM basics

Turing Machines, continued

CISC 4090 Theory of Computation

CS143 Final Fall 2009

Chapter 3. Set Theory. 3.1 What is a Set?

CS5371 Theory of Computation. Lecture 8: Automata Theory VI (PDA, PDA = CFG)

Infinity and Uncountability. Countable Countably infinite. Enumeration

Examples of P vs NP: More Problems

UNIT I PART A PART B

Exercises Computational Complexity

CS164: Midterm I. Fall 2003

Definition: A context-free grammar (CFG) is a 4- tuple. variables = nonterminals, terminals, rules = productions,,

CS103 Handout 50 Fall 2018 November 30, 2018 Problem Set 9

Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science Algorithms For Inference Fall 2014

Rice s Theorem and Enumeration

6.045J/18.400J: Automata, Computability and Complexity Final Exam. There are two sheets of scratch paper at the end of this exam.


CS 125 Section #10 Midterm 2 Review 11/5/14

(Refer Slide Time: 0:19)

CS210 THEORY OF COMPUTATION QUESTION BANK PART -A UNIT- I

CPSC 121 Some Sample Questions for the Final Exam Tuesday, April 15, 2014, 8:30AM

Skyup's Media. PART-B 2) Construct a Mealy machine which is equivalent to the Moore machine given in table.

1.7 Limit of a Function

Universal Turing Machine Chomsky Hierarchy Decidability Reducibility Uncomputable Functions Rice s Theorem Decidability Continued

(Refer Slide Time 3:31)

Lecture 2 Finite Automata

CS154 Midterm Examination. May 4, 2010, 2:15-3:30PM

Log-Space. A log-space Turing Machine is comprised of two tapes: the input tape of size n which is cannot be written on, and the work tape of size.

Decision Properties for Context-free Languages

6.045 Final Exam. Name: Please write your name on each page. This exam is open book, open notes.

How convincing is our Halting Problem proof? Lecture 36: Modeling Computing. Solutions. DrScheme. What is a model? Modeling Computation

Chapter 14: Pushdown Automata

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2016

Problem One: A Quick Algebra Review

More Simulations. CS154 Chris Pollett Apr 25, 2007.

(a) R=01[((10)*+111)*+0]*1 (b) ((01+10)*00)*. [8+8] 4. (a) Find the left most and right most derivations for the word abba in the grammar

SECTION A (40 marks)

MITOCW watch?v=zm5mw5nkzjg

THEORY OF COMPUTATION

2.2 Set Operations. Introduction DEFINITION 1. EXAMPLE 1 The union of the sets {1, 3, 5} and {1, 2, 3} is the set {1, 2, 3, 5}; that is, EXAMPLE 2

CSE 105 THEORY OF COMPUTATION

Succinctness counts. You may receive as little as 0 points for an answer that, even

Automata & languages. A primer on the Theory of Computation. The imitation game (2014) Benedict Cumberbatch Alan Turing ( ) Laurent Vanbever

Recursive and Recursively Enumerable Languages

CS 512, Spring 2017: Take-Home End-of-Term Examination

CS 341 Homework 1 Basic Techniques

Transcription:

Name: 1 a 20 b 20 c 20 d 20 e 20 f 20 g 20 2 10 3 30 4 12 5 15 Total 207 CS 341 Practice Final Exam 1. Please write neatly. You will lose points if we cannot figure out what you are saying. 2. Whenever you answer a question with a machine or a grammar, add comments to help us figure out what you are trying to do. 3. DO NOT WRITE JUNK and hope for partial credit. If you are trying to prove something and you know that you haven t got it right, say so. That may get you partial credit. But if you give the impression that you think that junk is nonjunk, you won t get points.

(1) For each of the following languages: (i.) (4 points) Determine the appropriate category, as listed below. (ii.) (8 points) Prove that the language is in the category you have specified, except as noted below, in which case these points will be assigned to part iii. You can do this part by writing an appropriate grammar (or regular expression), exhibiting an appropriate recognizing machine, using closure properties, or by showing that the language is finite. What I mean by exhibit a recognizing machine is: For an FSM: Draw it. For a PDA: Draw it, but if it is very complicated, also provide a description of how it works. We will give partial credit for the description even if the details of the machine are missing or wrong. For a Turing machine: Describe an algorithm in clear English. It need not be specifically a Turing Machine program. Any clear algorithm is acceptable. (iii.) (8 points) Prove that the language is not in the next most restricted category, except as noted below, in which case these points will be assigned to part ii. Assume the following language categories: A. L is regular. (In this case, you can skip part iii.) B. L is not regular but is context free C. L is not context free but is decidable (In this case, if L is a set of strings that include descriptions of machines (FSMs, PDAs or TMs), you do not need to prove that it is not context free.) D. L is not in D but is in SD. E. L is not in SD. (In this case, you can of course skip part ii.) You may take as theorems that the following languages are not decidable: H = {<M, w> : TM M halts on input string w} H = {<M> : TM M halts on the empty tape} H ANY = {<M> : there is any string on which TM M halts} The corresponding languages A, A, and A ANY. You may take as theorems that the following languages are not semidecidable: H = {<M, w> : TM M does not halt on input string w} H ANY = {<M> : there does not exist any string on which M halts} H ALL = {<M> : TM M halts on all inputs} EqTMs = {<M a, M b > : L(M a ) = L(M b )} The corresponding languages A, A ANY and A ALL. You may not use Rice s Theorem for these problems. To get full credit for any reduction proof, you must justify, in detail, why the reduction is correct. So purely copying and pasting a standard reduction will not get full credit even if it happens to work. Remember that: If S is a set, S is the cardinality of S. If w is a string, w is the length of w. # a (w) is the number of a s in the string w.

(a) L = {<M, w> : M moves right exactly twice while operating on w} D. If it can move right only twice, then M can read only the first two input characters. More generally, at any point in its computation, the only things that can affect its future behavior are: The contents of the two tape squares to the right of the read/write head, which may contain any element of. The contents of the square under the read/right head, which may also contain any element of. The contents of the two tape squares to the left of the read/write head, which may contain any element of. The rest of the tape to the left, but every one of these squares must contain a blank, so there s no information here. The state of M. So the number of distinct configurations of M is maxconfigs = 5 K. If M ever enters a configuration a second time, it will do the same thing that it did the first time. So the following algorithm decides L: 1. Run M on w for maxconfigs + 1 steps or until it halts or moves right three times. Keep track of how many times it moves right. Note that if it didn t naturally halt, it is in an infinite loop. 2. If it halted and moved right exactly twice, accept. 3. If it halted and moved right some other number of times, reject. 4. If it moved right three times, reject. 5. If it didn t move right at all, reject. It is in a loop and will never move right. 6. If it moved right exactly once, reject. Either that one move is outside the loop, in which case there won t be any more, or it s inside the loop and there will be an infinite number of additional ones. 7. If it moved right twice, we need to find out whether those moves were inside the loop or preceded entry into the loop. So continue running M for another maxconfigs steps. 8. If the total number of rightward moves is still two, accept. 9. Otherwise reject. (b) L = {wx : w = 2 x w a + b + x a + b + } Context-free, not regular. L can be accepted by a PDA M that pushes one character for each a and b in w and then pops two characters for each a and b in x. L is not regular, which we show by pumping. Note that the boundary between the w region and the x region is fixed; it s immediately after the last b in the first group. Choose to pump the string w = a 2k b 2k a k b k. y = a p, for some nonzero p. Pump in or out. The length of w changes but the length of x does not. So the resulting string is not in L.

(c) L = {<M a, M b > : if M a does not accept then M b rejects } SD/D: Note that L is equivalent to {<M a, M b > : M a accepts or M b rejects }. The following algorithm semidecides L: Run both machines on in parallel. If either M a accepts or M b rejects, halt and accept. Proof not in D: R is a reduction from H = {<M, w> : TM M halts on w} to L, defined as follows: R(<M, w>) = 1. Construct the description of M#(x) that, on any input, immediately accepts. 2. Construct the description of M##(x) that operates as follows: 2.1 Erase the tape. 2.2 Write w on the tape. 2.3 Run M on w. 2.4 Accept. 3. Return <M##, M#>. If Oracle exists and decides L, then C = Oracle(R(<M, w>)) decides H. R can be implemented as a Turing machine. And C is correct. Note that M# rejects nothing. M## accepts everything or nothing, depending on whether M halts on w. So: <M, w> H: M halts on w so M## accepts everything, including. So Oracle accepts. <M, w> H: M doesn t halt on w so M## accepts nothing, including. M# rejects nothing. So Oracle rejects. But no machine to decide H can exist, so neither does Oracle. (d) L = {<M> : M rejects at least two even length strings} SD/D: The following algorithm semidecides L: Run M on the even length strings in * in lexicographic order, interleaving the computations. As soon as two such computations have rejected, halt. Proof not in D: R is a reduction from H = {<M, w> : TM M halts on w} to L, defined as follows: R(<M, w>) = 1. Construct the description of M#(x) that, on input x, operates as follows: 1.1. Erase the tape. 1.2. Write w on the tape. 1.3. Run M. 1.4. Reject. 2. Return <M#>. If Oracle exists and decides L, then C = Oracle(R(<M, w>)) decides H: <M, w> H: M halts on w so M# rejects everything and thus rejects at least two even length strings, so Oracle accepts. <M, w> H: M doesn t halt on w so M# doesn t halt and thus rejects nothing and so does not reject at least even length two strings. Oracle rejects. But no machine to decide H can exist, so neither does Oracle. (e) L = {w = xyx R : x {0, 1} +, y {0, 1}*} Regular. There is no reason to let x be more than one character. So all that is required is that the string have at least two characters and the first and last must be the same. L = (0 (0 1)* 0) (1 (0 1)* 1).

(f) L = {<M> : L(M) is not regular} SD: R is a reduction from H = {<M, w> : TM M does not halt on w} to L, defined as follows: R(<M, w>) = 1. Construct the description of M#(x) that operates as follows: 1.1. Save its input x on a second tape. 1.2. Erase the tape. 1.3. Write w. 1.4. Run M on w for x steps or until it halts. 1.5. If M would have halted, then loop. 1.6. Else: if x a n b n, accept. Otherwise reject. 2. Return <M#>. If Oracle exists and semidecides L, then C = Oracle(R(<M, w>)) semidecides H: <M, w> H: M does not halt on w, so M# always gets to step 1.6. So L(M#) = a n b n, which isn t regular. Oracle accepts. <M, w> H: M halts on w. Suppose it does so in k steps. Then, for all strings of length k or more, M# loops at step 1.5. So L(M#) is finite and thus regular. So Oracle does not accept. But no machine to semidecide H can exist, so neither does Oracle. (g) L = {wxw : w = 2 x, w {a, b}*, x {c}*} Not context-free. We prove it using the Pumping Theorem. Let w = a 2k c k a 2k. (2) Consider the following Turing Machine M, described in our macro language: Give a short English description of what M does. Don t describe how it operates. Describe its result. Shift the input string one character to the right and replace each b with an a and each a with a b.

(3) Give an example that proves each of the following: (a) It is possible, given two languages L 1 and L 2, both in SD/D, that L 1 L 2 is in D. PCP H =, which is regular and thus in D. (b) It is possible that, if L 1 and L 2 are context free, L 1 L 2 is not context free. Let L 1 be {a n b n c m : n, m 0}, which is context-free. Let L 2 be {a m b n c n : n, m 0}, which is also context-free. L 1 L 2 = A n B n C n, which is not context-free. (c) The SD languages are not closed under complement. H is in SD. But H is not. (d) Let L A be the set of all languages defined over some alphabet A. Then let md: L A L A be a function that maps from one language to another, defined as follows: md(l) = {x : w L (w = sxt, s *, x *, t *)} If L is context free but not regular, md(l) may be regular. Let: Then: L = A n B n, which is context-free but not regular. md(l) = {a i b j : i, j 0}, which is regular. (e) It is possible that, if L 1 L 2 and L 2 SD then L 1 D. Let L 1 = {a} and let L 2 = H. {a} H. But {a} is in D. (f) There exists a language L that is Turing enumerable but not lexicographically Turing enumerable. Any language that is in SD/D will serve. So let L = H. (4) Let M be an arbitrary Turing machine. Suppose that timereq(m) = 3n 3 (n+5)(n-4). Circle all of the following statements that are true: a) timereq(m) O(n). False b) timereq(m) O(n 6 ). True c) timereq(m) O(n 5 /50). True d) timereq(m) (n 6 ). False

(5) Show that SUBSET-SUM = {<S, k> : S is a multiset (i.e., duplicates are allowed) of integers, k is an integer, and there exists some subset of S whose elements sum to k} is in NP. A deterministic, polynomial-time verifier V operates as follows: 1. It checks the length of a proposed certificate c. If it is longer than S, it rejects. Otherwise it continues. 2. For each element e of c, it walks through S looking for an unused element that matches e. If it finds one, it marks it as used. If it fails to find one, it immediately rejects. 3. It sums the elements of c. If the sum is equal to k it accepts, otherwise it rejects. V runs in polynomial time because: 1. Step 1, checking, the length of c, takes O( S ) time. 2. Step 2, checking that all the elements in c are in S, can be done in O( S 2 ) time. 3. Step 3, checking the sum: V can sum the elements of c in O( c ) time (assuming constant cost per addition). And it can compare that sum to k in O(k) time. So timereq(v) O( <S, k> 2 ).