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.

Programming with Mutation

1. The end-auction! procedure from Problem Set 5 (PS5 Comments) did not remove sold items from the item table. To remove an item we need a table-delete! procedure. It takes a table, a field, and a procedure. It mutates the value of the table to remove all entries for which the procedure applied to the value of the field evaluates to true. For example, in end-auction! we would do
   (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.)

Programming with Objects

3. The make-police-officer procedure defined in Problem Set 6 Comments (Question 6) starts like this:
(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.)

Complexity and Computability

4. For each of the following statements, explain what the impact of the described event would be.

For example:

x. Finding a Θ(n243) algorithm that solves the Smiley Puzzle (as defined in Lecture 15)

Answer. This would prove that P = NP since we have found a polynomial-time solution to an NP-complete problem.

Read the statements very carefully and precisely.
  1. Finding a Θ(2n) algorithm that solves the Smiley Puzzle.








  2. Finding a proof that the fastest possible algorithm that can solve the 3SAT problem is Θ(3.3n).







  3. Finding a Θ(n5) algorithm that solves a problem in NP.


  4. Finding a polynomial-time reduction from the Sorting Problem to the Smiley Puzzle








  5. Finding a polynomial-time reduction from the Traveling Salesperson Problem (defined in Lecture 16) to the Halting Problem








  6. Finding a polynomial-time reduction from the Halting Problem to the Smiley Puzzle








Computability

5.
a. Is the Identical-Outcomes problem described below decidable?
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 I

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.

6. Ben Bitdittle claims that the streakability problem (as defined in Problem Set 6 is decidable using this argument:
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).

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.

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.

Models of Computation

7. In Lecture 32 we defined:
cons ≡ λ xyz . zxy
car ≡ λ p . p T
cdr ≡ λ p . p F
If we instead defined:
cons ≡ λ xyz . zyx
Explain 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.

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.

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.)

Feedback

These two questions are optional and worth no credit, but we appreciate your answers.

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