Distributed: Wednesday, December 4, 2002
Due: Wednesday, December 11, 2002
This page may be found online at
There are five problems on the exam. Some problems have subproblems. Each full problem is worth twenty points. The point value associated with a problem does not necessarily correspond to the complexity of the problem or the time required to solve the problem.
This examination is open book, open notes, open mind, open computer, open Web. However, it is closed person. That means you should not talk to other people about the exam. Other than that limitation, you should feel free to use all reasonable resources available to you. As always, you are expected to turn in your own work. If you find ideas in a book or on the Web, be sure to cite them appropriately.
Although you may use the Web for this exam, you may not post your answers
to this examination on the Web (at least not until after I return exams
to you). And, in case it's not clear, you may not ask others (in person,
via email, by posting a
please help message, or by any other
means) to put answers on the Web.
This is a take-home examination. You may use any time or times you deem appropriate to complete the exam, provided you return it to me by the due date. It is likely to take you about five to ten hours, depending on how well you've learned topics and how fast you work. You must write down the amount of time each problem takes you. I expect that someone who has mastered the material and works at a moderate rate should have little trouble completing the exam in a reasonable amount of time. Since I worry about the amount of time my exams take, I will give three points of extra credit to the first two people who honestly report that they've spent at least eight hours on the exam or who note that they've completed the exam in under eight hours. (At that point, I may then change the exam.)
You must include both of the following statements on the cover sheet of the
examination. Please sign and date each statement. Note that the
statements must be true; if you are unable to sign either statement,
please talk to me at your earliest convenience. Note also that
inappropriate assistance is assistance from (or to) anyone
other than myself or our teaching assistant.
1. I have neither received nor given inappropriate assistance on this examination.
2. I am aware of no other students who have given or received inappropriate assistance on this examination.
Because different students may be taking the exam at different times,
you are not permitted to discuss the exam with anyone until after I
have returned it. If you must say something about the exam, you are
allowed to say
This is among the hardest exams I have ever
taken. If you don't start it early, you will have no chance of
finishing the exam. You may also summarize these policies.
You may not tell other students which problems you've finished.
You must both answer all of your questions electronically and turn them in hardcopy. That is, you must enter all of your answers on the computer, print them out, and hand me the printed copy. You must write your name on the top of every page of the printed exam. You must also email me a copy of your exam by copying your exam and pasting it into an email message. Put your answers in the same order as the problems. Make sure that your solution confirms to the format for laboratory writeups
In many problems, I ask you to write code. Unless I specify otherwise in a problem, you should write working code and include examples that show that you've tested the code.
Unless I specify otherwise, you should fully document all of the primary procedures (including parameters, purpose, value produced, preconditions, and postconditions). If you write helper procedures (and you may certainly write helper procedures) you should document those, too, although you may opt to write less documentation. When appropriate, you should include short comments within your code. You should also take care to format your code carefully.
Just as you should be careful and precise when you write code, so should you be careful and precise when you write prose. Please check your spelling and grammar. I am likely to penalize you for bad spelling and grammar.
I will give partial credit for partially correct answers. You ensure the best possible grade for yourself by emphasizing your answer and including a clear set of work that you used to derive the answer.
Although the problems are numbered from 1 to 5, you need not do them in order. In fact, experience shows that students tend to do better if they are willing to put aside problems that give them difficulty, work on other problems, and then come back to the difficult problems later.
I may not be available at the time you take the exam. If you feel that a question is badly worded or impossible to answer, note the problem you have observed and attempt to reword the question in such a way that it can be answered. If it's a reasonable hour (before 10 p.m. and after 8 a.m.), feel free to try to call me in the office (269-4410) or at home (236-7445). You can also send me electronic mail.
I will also reserve time at the start of classes this week and next to discuss any general questions you have on the exam.
Your old pals, Sarah and Steven Schemer, are upset that they have to
keep rewriting similar
may-precede? predicates (e.g.,
they must remember to use
string-ci<=? for strings,
<= for numbers,
(lambda (x y) (string-ci<=? (car
x) (car y))) for lists whose car is their key, and so on
and so forth). They've decided that someone should write a general
less-than? predicate that can compare any
pairs of values.
What do they think is reasonable?
string-ci<=?to compare the two parameters.
char-ci<=?to compare the two parameters.
<=to compare the two parameters.
smalleror (2) the given element of one list is smaller than the corresponding element of the other list, in which case the list with the smaller element is smaller.
Of course, Sarah and Steven are much better at deciding what they'd
like to do than at actually doing it. Hence, they've asked you to
less-than? they've described for them.
Your sentient and malicious instructor agrees, although he
is willing to let you forgo the careful documentation that he
usually requires. Implement
Theodore and Thelma Theoretician take one look at Sarah and Steven's suggestions and start to chuckle. They say
One of the key characteristics of the standard
may-precede?parameter to sorting and searching algorithms is that it is transitive. That is, if a may precede b and b may precede c, then a may precede c. Unfortunately, there are values for which
less-than?is not transitive.
Find three values, a, b, and c, such that
> (less-than? a b) #t > (less-than? b c) #t > (less-than? a c) #f
Note that you don't need to implement
answer this question, you just need to look at the guidelines for
Hint: Consider cases in which you need to modify one or both of the parameters.
An and Al Abbrev object to
the overly-long procedure names that
Sam likes to use. Hence, they tend to choose one-character
names. They also avoid the sixP Ps that I like. Here's a procedure
they've recently written.
(define r (lambda (l p?) (letrec ((c (lambda (p v) (let ((x (if (p? v) 1 0))) (cons (+ (car p) x) (+ (cdr p) (- 1 x)))))) (r (lambda (q m) (if (null? m) (/ (car q) (cdr q)) (r (c q (car m)) (cdr m)))))) (r (cons 0 0) l))))
Document the procedure
r. If you'd like,
you can change the names used within
r) to something more readable.
After your terrifying encounters with Theodore and Thelma and An and Al, you're almost happy to hear that Sarah and Steven Schemer want to work with you again. They've started a project to implement as many sorting algorithms as they can think of. Their current project is selection sort, the algorithm that works by repeatedly selecting the smallest remaining value.
Believe it or not, they've written most of a selection sort procedure for lists.
(define selection-sort (lambda (lst may-precede?) (if (null? lst) null (let ((small (smallest lst may-precede?))) (cons small (selection-sort (remove small lst) may-precede?))))))
a. Finish this implementation of selection sort. You
will need to implement or find
remove. You may need to modify their code.
selection-sort so that it is tail
You do not need to document anything. However, you should show appropriate tests.
Sarah and Steven Schemer have started to implement a new online student information system for the registrar. For each student, they'd like to store the following information:
make-student procedure that builds
a record or object to store information on students. You should
also provide related procedures (or methods) to support extracting
each field, changing major, adding new courses, and deleting courses.
You should also provide a predicate that checks whether a student took
a particular course.
I've added a new paragraph to the preliminaries. Summarize that paragraph. [2 points]
Identify problems of grammar or spelling in the main body of the exam (not including the preliminaries). [1 point each given to the whole class; 5 points max]
abbreviation[6 Dec 2002; Stephane]
char-ci<=?[8 Dec 2002; Davis]
forgois spelled correctly; it means
to give up the enjoyment or advantage of; do without(from WWWebster) [NO POINTS!]
Tuesday, 3 December 2002 [Samuel A. Rebelsky]
Wednesday, 4 December 2002 [Samuel A. Rebelsky]
Thursday, 5 December 2002 [Samuel A. Rebelsky]
Friday, 6 December 2002 [Samuel A. Rebelsky]
I usually create these pages
on the fly, which means that I rarely
proofread them and they may contain bad grammar and incorrect details.
It also means that I tend to update them regularly (see the history for
more details). Feel free to contact me with any suggestions for changes.
This document was generated by
Siteweaver on Sun Dec 8 22:31:05 2002.
The source to the document was last modified on Sun Dec 8 22:31:01 2002.
This document may be found at