University of Virginia, Department of Computer Science
CS150: Computer Science, Fall 2005
24 December, 2024
cs150-staff@cs.virginia.edu
Final Out: 26 April 2004
Due: Friday, 30 April 2004, 4:55PM

Name: _________________________________________________________

Directions

Work alone. You may not discuss these problems or anything else related to this course with anyone except for the course staff between receiving this exam and Tuesday, 4 May 2004.

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.

Open computer. You may use a computer and any programming languages and environments you want for this exam. You are not required to use a computer (other than your own brain if you think it is one) to do well on this exam. You will not lose points on the programming questions for minor syntactic problems (e.g., missing parentheses).

Answer well. Answer all 10 questions. Write your answers on this exam. 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 more than a few hours 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.

Turn your exam in to the folder outside my office (Olsson 236A) before Friday, 30 April 4:55pm. If the scheduled due date (Friday, 30 April at 4:55pm) will prevent you from doing your best on this exam, you may be able to negotiate a later due date by requesting it before Wednesday, 28 April.

Procedures

For each of the following questions you are asked to write a procedure that solves the described problem. You may write your procedure using any programming language you want (although we expect it will be easiest to answer these questions well using Scheme). If you use a language other than Scheme, PHP, SQL, Ada, Algol, BASIC, C, C++, C#, CLU, FL, Fortran, Haskell, Java, ML, Pascal, Python or Smalltalk for your answer, include a URL to a reference manual for the language you use in your answer.

1. Combine Lists

Input: Two equal length lists of numbers.
Output: A list containing elements that are pairs of the corresponding elements in the input lists.
For example, (combine-lists (list 1 2 3) (list 4 5 6)) should evaluate to ((1 . 4) (2 . 5) (3 . 6)).























2. Count Matches
Input: Two (possibly non-equal length) lists of numbers, a comparison function
Output: A count of the number of elements for which the comparison function applied to the corresponding elements in the two input lists evaluates to true. If the is no corresponding element (one list is shorter), the element should not be counted.
For example:
> (count-matches (list 1 2 3) (list 2 4 6) =)
0
> (count-matches (list 1 2 3) (list 0 2 4 6 8 10) =)
1
> (count-matches (list 1 2 3 4) (list 0 1 4) >)
2































3. Disjunct
Input: Two procedures, p and q
Output: A procedure that takes two parameters and evaluates to true only if applying p to both parameters evaluates to true or applying q to both parameters evaluates to true.
For example, ((disjunct > =) 3 4) should evaluate to false and ((disjunct < =) 3 3) should evaluate to true.



























Complexity and Computability

4. Describe the complexity of the map2d procedire (defined in Problem Set 1):
  (define (map2d f ll)
     (map (lambda (inner-list) (map f inner-list)) ll))
Express your answer using Θ notation. Be sure to justify it with an explanation and to fully describe what any variables you use in your answer mean, and any assumptions you need to make.



























5, 6 and 7. (Counts as 3 questions) How would a theoretician order the problems below from least difficult to most difficult? Justify your answer by explaining how much work each problem involves using Θ notation (or explaining why the problem is undecidable). Be careful to fully describe what any variables you use in your answer mean, and any assumptions you need to make.
Ali G Problem
Input: Two long d-digit numbers (mostly nines)
Output: The product of the two input numbers
Chess Problem
Input: A chess position (a list of pieces on a 64 square board)

Output: If there is winning strategy for white (moves first), output true (that is, a way of moving for white that guarantees a win no matter what the adversary does). Otherwise, output false.

Genome Assembly Problem
Input: A set of genome reads (sequences of base pairs)

Output: The smallest possible genome that includes each read.

Procedure Equivalence Problem
Input: Two procedures, P and Q, each taking one input that can be any value. You may assume both procedures are guaranteed to always terminate.

Output: true is P is functionally equivalent to Q; false otherwise. Two procedures are functionally equivalent if for every input the produce the same output.

Answer space on next page.


Hardest: __________________________
Why?












Second Hardest: __________________________
Why?







Third Hardest: __________________________
Why?







Easiest: __________________________
Why?







8-9. (counts as 2 questions) How would a pragmatist order the same problems? If the amount of work is different for the pragmatist, explain clearly why. You should assume your pragmatist cares about getting a reasonably good answer to the problem today. State any assumptions you make about what the actual input size is, and how good and answer is "good enough".

Hardest: __________________________
Why?









Second Hardest: __________________________
Why?








Third Hardest: __________________________
Why?








Easiest: __________________________
Why?








Models of Computation

10. Draw a Turing Machine that never halts but also never repeats a machine configuration (repeats-configuration as defined in Exam 2, Question 4 is false). Use as few states and transistions as possible.

11. The goal of this course is to teach students to think like computer scientists, and the goal of this exam is to measure how well you have done that so I can fairly determine your final grade. If you feel your answers on this exam will not adequately demonstrate what you have learned, or that I should take other things into account in determining your final grade, use this space to explain why.

































End of Exam
Enjoy your Summer!

"); print ( $res[$first] ) ; print (""); ?>
CS 150: Computer Science
University of Virginia
evans@virginia.edu
Using these Materials