



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Exam; Professor: Torng; Class: Computability and Languages; Subject: Computer Science & Engineering; University: Michigan State University; Term: Fall 2001;
Typology: Exams
1 / 7
This page cannot be seen from the preview
Don't miss anything!




The total points are as follows: The basic points on this exam sum to 46. The advanced points on this exam sum to 12. There are also 3 extra credit advanced points on the exam.
bool main(int n) { int k=0; if ( n < 0 ) return(no); while ( k*k != n ) k++; return(yes); }
(a) What is Y (P )? [2, basic] The set of integers that are perfect squares. (b) What is N (P )? [2, basic] The set of negative integers. (c) What is I(P )? [2, basic] The set of positive integers that are not perfect squares. (d) What is C(P )? [2, basic] The empty set. (e) Does P solve Y (P )? Explain why or why not. [2, basic] No it does not since it loops on some inputs. In order to solve a problem P must halt on all legal inputs. (f) Is Y (P ) solvable? Explain why or why not. [2, basic] Yes it is. Even though P does not solve the set of integers that are perfect squares, we can easily create a different program that does solve Y (P ). For example bool main(int n) { int k=0; while ( kk < n ) k++; if ( kk == n ) return (yes); else return(no); }
Assume PF is a program that solves F AIL. Consider the following table that describes the behavior of some programs on some inputs.
P0 Crash Accept Loop Crash P1 Reject Reject Reject Reject P2 Loop Accept Loop Loop P3 Accept Reject Accept Accept
(a) Based on the above table, fill in the following table with the value that PF would give to the corresponding input. For example, the upper left entry of your answer should reflect what PF would return on the input (P0,0). [3, basic]
(b) Consider the following incomplete program D. bool main(unsigned int y) { program P = generate(y); if (PF (P, y)) Action A; else Action B; } program generate(unsigned int y); bool PF (program P, unsigned int y); In order to complete program D, what actions would be appropriate? Circle all that apply. [2, advanced] Action A: Accept, Reject, Loop, Crash Correct choices are Accept, Reject Action B: Accept, Reject, Loop, Crash Correct choices are Loop, Crash
(c) Explain your answer to part (b). [3, advanced] If we end up at Action A, this means that PF (P, y) evaluated to true. That means that P fails on y which means that P either loops or crashes on y. In order to guarantee that D behaves differently on y, we can make D accept or reject y. Thus, these are the only
program main(program P, unsigned int y) Note the return type program should be one that takes as input a string whereas the input parameter program type should be one that takes as input an unsigned int. If you specify that difference, that is good, but not required.
(a) Specify Y (Q 3 ) as precisely as you can. [2, basic] If Q 1 halts on inputx, then Y (Q 3 ) = {a, ab}. Otherwise, if Q 1 loops on inputx, then Y (Q 3 ) = {}. (b) This program P 3 computes an answer-preserving input transformation from the halting problem to some of the following problems. Identify all such problems, and for those which this does not apply, state whether or not there is a Yes→No violation or a No→Yes violation. [4, advanced] i. Input: A program P that takes as input a string over {a, b} Yes/No Question: Is Y (P ) infinite? This does not work. There is a Yes→No violation.
ii. Input: A program P that takes as input a string over {a, b} Yes/No Question: Is Y (P ) finite? This does not work. There is a No→Yes violation.
iii. Input: A program P that takes as input a string over {a, b} Yes/No Question: Is ab ∈ Y (P )? This does work. iv. Input: A program P that takes as input a string over {a, b} Yes/No Question: Is Y (P ) = {a}? This does not work. There is a Yes→No violation.
Set of problems/languages over {a,b} Set of strings over {a,b}
(a) Place the following items into both diagrams if appropriate. Note, some items may only fit in one diagram. If so, state this next to the item below. [5, basic]
i. RE: only in left diagram ii. REC: only in left diagram iii. aba: only in right diagram iv. {a}∗ v. S = the set of all even length strings over alphabet {a, b}. (b) Place H and Hc^ into the left diagram where H denotes the Halting problem. [2,basic] See corresponding powerpoint presentation for diagrams with all items above in proper relation to each other.
(a) Give the 3 SHORTEST strings that are in S. [1,basic] a, ab, ba
(b) Give 3 strings that are not in S. [1,basic] λ, b, bb, aa, bbb, aaa, aba is a list of more than 3
(c) Suppose we list the strings in S in alphabetical order. Which of the following strings appear in a finite position on this list? Circle all that apply. [2, basic] a, ba, abbb, bbba, bbabb, bbbbabbbb The only correct choices are those that begin with a. In this list, that would be a and abbb. (d) Above, we have observed that when we list all the strings in S in alphabetical order, some strings do not appear in a finite position on this list. Does this prove that S is uncountably infinite? Why or why not? [2, basic] No it does not. It merely shows that this ordering does not prove that S is countably infinite. However, we only need one ordering to work in order for S to be countably infinite. An ordering that does work is to list the elements of S by order of their length. For strings of the same length, order them alphabetically (i.e. by the position of the one
Answer 2: You could also prove this by representing the majority operation as a combination of other set operations such as set union and set intersection. Since RE is closed under both of these operations, this would imply RE is also closed under the majority operation.
(a) If I implement a testing approach, do I need the source code for P or will an executable version of P be sufficient? Briefly explain your answer. [2, basic] In this case, I do not need the source code as all I will do is run P on some inputs and see what P produces as output. I do not examine how P performs its job or do any analysis of its operation or logic.
(b) If I implement an analysis approach, do I need the source code for P or will an executable version of P be sufficient? Briefly explain your answer. [2, basic] In this case, I do need the source code of P as I will be performing an analysis of P to derive some overall assessment of the program. I will probably be analyzing how it works and the logic behind the program, so an executable version is not sufficient.
What does it mean for a string x to be in L 1 L 2? Contrary to many suggested answers, this does not necessarily mean that x ∈ L 1 or x ∈ L 2. Rather, it means that some prefix of x is in L 1 and the corresponding suffix of x is in L 2.
Where does this prefix begin and end? We don’t know, so we have to test all possible starting and ending locations. Specifically, suppose x has length n. Then for 0 ≤ i ≤ n, P ′^ will test the prefix consisting of the first i characters of x by running P 1 on that prefix and the corresponding suffix consisting of the remaining n − i characters by running P 2 on that suffix. If both say yes for any value of i, then P ′^ returns yes. Otherwise, if at least one fails for all values of i, then P ′^ returns no.