University of Virginia Computer ScienceCS150: Computer Science, Fall 2005 |

Exam 2 |
Out: 11 November 2005Due: 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

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:

Read the statements very carefully and precisely.x.Finding a Θ(n^{243}) 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.

- Finding a Θ(2
^{n}) algorithm that solves the Smiley Puzzle.

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

- Finding a Θ(
*n*^{5}) algorithm that solves a problem in NP.

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

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

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

Input:Two programsPandQand an inputI

Output:If executing programPon inputIproduces the same output as executing programQon inputIoutputtrue. Otherwise, outputfalse. 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 programsPandQand an inputI

Output:If bothPandQexecuting on on inputIhalt, outputtrue. If bothPandQdo not halt on inputI, outputtrue. Otherwise (one of the programs halts and the other one does not halt), outputfalse.

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'sBen'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.is-dressedvariable is#tor#f).

There are a fininte number of possible states. If the number of places is

p, the maximum number of possible states isp*p* 2 (ppossible locations for the police officer,ppossible locations for the student, and 2 possible undress states for the student).Since the total number of states is finite, an execution longer than 2

p^{2}steps (clock-ticks) must repeat a previous state.We can evaluate the

streakabilityproblem by setting up the initial state of the world and running clock-ticks until either the streaker is arrested, in which case the output istrue, or 2p^{2}clock ticks have been executed, in which case the output isfalsesince a state repeated without the streaker being arrest and once a state repeats the same sequence of states will be repeated every time.

If we instead defined:cons≡ λxyz.zxy

car≡ λp.pT

cdr≡ λp.pF

Explain how we should definecons≡ λxyz.zyx

The Churning Machine is an infinite tape with one tape head, two finite state machines (we call them theCy 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.)MandNmachines), and a churner which selects between the finite state machines. The churner is in one of two possible states: pointing to theMmachine or pointing to theNmachine.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

TrueorFalse. If the churn option value isTruethe 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: