University of Virginia Computer Science CS150: Computer Science, Fall 2005 |
Exam 2 |
Out: 11 November 2005 Due: Monday, 14 November, 1:01PM |
Name: _________________________________________________________
Directions
Work alone. You may not discuss these problems or anything related to the material covered by this exam with anyone except for the course staff between receiving this exam and class Wednesday.Open book. You may use any books you want, lecture notes and slides, your notes, and problem sets. If you use anything other than the course books and notes, cite what you used.
No DrScheme. You may not run DrScheme or use any other Scheme interpreter between now and when you turn in this exam.
Answer well. Answer all questions and optionally answer the optional questions. Write your answers on this exam or on separate sheets of paper. You should not need more space than is provided to write good answers, but if you want more space you may attach extra sheets. If you do, make sure the answers are clearly marked.
The questions are not necessarily in order of increasing difficulty, so if you get stuck on one question you should continue on to the next question. There is no time limit on this exam, but it should not take a well-prepared student more than an hour or two to complete.
Full credit depends on the clarity and elegance of your answer, not just correctness. Your answers should be as short and simple as possible, but not simpler.
(table-delete! items 'item-name (make-string-selector item-name))to delete the item named item-name from the items table after it is sold.
Define the table-delete! procedure.
2. What is the complexity of your table-delete! procedure? (Use Θ notation, and be sure to define all variables you use carefully, and state all assumptions you make. For full credit, your answer must include a clear and convincing supporting argument.)
(define (make-police-officer name) (let ((super (make-person name))) (ask super 'make-restless 2) ;;; Police officers are quite restless (lambda (message) ...Suppose we had used this instead:
(define (make-police-officer name) (let ((super (make-person name)) (restlessness 2)) (lambda (message) ...Explain why the new police officer would not be very effective. (You may want to use an environment diagram to make your answer clear.)
For example:
x. Finding a Θ(n243) algorithm that solves the Smiley Puzzle (as defined in Lecture 15)Read the statements very carefully and precisely.Answer. This would prove that P = NP since we have found a polynomial-time solution to an NP-complete problem.
Input: Two programs P and Q and an input I
Output: If executing program P on input I produces the same output as executing program Q on input I output true. Otherwise, output false. Two executions are considered to produce the same outcome if either (1) both executions do not terminate; or (2) both executions terminate with the same output.
b. Is the Identical-Termination problem described below
decidable?
Input: Two programs P and Q and an input I6. Ben Bitdittle claims that the streakability problem (as defined in Problem Set 6 is decidable using this argument:
Output: If both P and Q executing on on input I halt, output true. If both P and Q do not halt on input I, output true. Otherwise (one of the programs halts and the other one does not halt), output false.
The streakability problem involves one student, one police officer, and a finite number of places. Hence, the state of Charlottansville is described by the locations (what place they are at) of the police officer and the student, and the state of undress of the student (if the student's is-dressed variable is #t or #f).Ben's answer differs from the answer given in the PS6 Comments. Explain at least two fundamental flaws in Ben's argument, and what assumptions are needed to make his argument hold.
There are a fininte number of possible states. If the number of places is p, the maximum number of possible states is p * p * 2 (p possible locations for the police officer, p possible locations for the student, and 2 possible undress states for the student).
Since the total number of states is finite, an execution longer than 2p2 steps (clock-ticks) must repeat a previous state.
We can evaluate the streakability problem by setting up the initial state of the world and running clock-ticks until either the streaker is arrested, in which case the output is true, or 2p2 clock ticks have been executed, in which case the output is false since a state repeated without the streaker being arrest and once a state repeats the same sequence of states will be repeated every time.
cons ≡ λ xyz . zxyIf we instead defined:
car ≡ λ p . p T
cdr ≡ λ p . p F
cons ≡ λ xyz . zyxExplain how we should define car and cdr to have the correct meaning and show that car cons M N correctly reduces to M using your definitions. 8. Cy D. Fect proposes the following Churning Machine model of computation as an alternative to the Turing Machine:
The Churning Machine is an infinite tape with one tape head, two finite state machines (we call them the M and N machines), and a churner which selects between the finite state machines. The churner is in one of two possible states: pointing to the M machine or pointing to the N machine.Cy claims his Churning Machine is more powerful than a Turing Machine because it has two FSMs and the churner. Explain how you would prove him wrong. (You do not need to provide a fully details proof, but should provide a convincing argument.)At each step the Churning Machine looks at the churner to decide which FSM to use. Then, it reads one symbol from the tape, and follows the transition rule for the current state of the selected FSM. The transition rule has an output symbol, a next state, and a head direction, just like in a Turing Machine. It also has a churn option, which is either True or False. If the churn option value is True the churner switches to point to the other FSM. Note that when the churner switches, the FSM maintains its current state; when the churner switches back, it will resume from that state.
F1. Do you feel your performance on this exam will fairly reflect your understanding of the course material so far? If not, explain why.
F2. Rank each of these topics (1 is the most perferred, 10 is the
least) according to your interest in them being covered in the remaining
CS150 classes:
_____ Applications of computing to biology
_____ Applications of computing to finding aliens
_____ How Google works
_____ How hardware works
_____ How to implement an interpreter
_____ How to make servers more secure
_____ How to relate languages and complexity
_____ How to test programs
_____ How viruses and worms work
_____ Learn a complex programming language (Java or C#)
_____ Other:
"); print ( $res[$first] ) ; print (" |
CS 150: Computer Science University of Virginia |
evans@virginia.edu Using these Materials |