[Skip to Body]
Primary:
[Front Door]
[Current]
[Glance]

[Honesty]
[On Teaching and Learning]
Groupings:
[EBoards]
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Readings]
[Reference]
Misc:
[SamR]
[Java 1.5 API]
[Espresso]
[TAO of Java]
[CS152 2004F]
Distributed: Friday, May 6, 2005
Due: 11:00 a.m., Friday, May 13, 2005
No extensions.
This page may be found online at
http://www.cs.grinnell.edu/~rebelsky/Courses/CS152/2005S/Exams/exam.03.html
.
Contents
There are four problems on the exam. Some problems may have subproblems. Each problem is worth 25 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, via IM, by posting a please help
message, or in any
other way) to put answers on the Web.
This is a takehome 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.
This exam is likely to take you about six hours, depending on
how well you've learned topics and how fast you work. You should not
work more than eight hours on this exam. Stop at eight hours and write
There's more to life than CS
and you will earn at least 80 points
on this exam. I would appreciate it if you would write down the
amount of time each problem takes. Each person who does so will earn
two points of extra credit. 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 two points of extra credit
to the first two people who honestly report that they've spent at least
five hours on the exam or completed the exam and do so at least two days
before the exam is due. (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. You need not reveal
the particulars of the dishonesty, simply that it happened. Note also that
inappropriate assistance
is assistance from (or to) anyone
other than Professor Rebelsky (that's me).
1. I have neither received nor given inappropriate assistance on this examination.
2. I am not aware of any 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 may not tell other students how long you've spent on the exam.
You must both answer all of your questions electronically and turn in a printed version of your exam. That is, you must write all of your answers on the computer, print them out, number the pages, put your name on every page, and hand me the printed copy. 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. Please write your name at the top of each sheet of the printed copy. If you fail to do so, you will be penalized.
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.
Just as you should be careful and precise when you write code and documentation, so should you be careful and precise when you write prose. Please check your spelling and grammar. Since I should be equally careful, the whole class will receive one point of extra credit for each error in spelling or grammar you identify on this exam. I will limit that form of extra credit.
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.
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 is answerable. 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 (2694410) or at home (2367445).
I will also reserve time at the start of classes next week to discuss any general questions you have on the exam.
Topics: Hash Tables, Arrays, Data Structure Design
Expected time: One hour
The implementation of hash tables that we've used in class has been
what is typically called a bucketstyle hash table. That is,
each element of the array is essentially a bucket
of values.
The primary advantage of these kinds of hash tables is their ease of
implementation. One disadvantage is that they waste a lot of space
(for the nodes in the buckets and for the unused buckets).
An alternative implementation is the socalled linear probe hash table. In this implementation, when you attempt to hash a value to an alreadyfilled cell, you keep trying subsequent cells until you find an empty one.
For example, suppose we're using integers as keys and our hash table has size ten.
0 1 2 3 4 5 6 7 8 9 +++++++++++            +++++++++++
If we hash 5, it goes into cell 5.
0 1 2 3 4 5 6 7 8 9 +++++++++++      05     +++++++++++
If we hash 17, it goes into cell 7 (17 is 7 mod 10).
0 1 2 3 4 5 6 7 8 9 +++++++++++      05 17   +++++++++++
If we now hash 25, we first try to put it into cell 5 (25 is 5 mod 10). That cell is full, so we try cell 6. That cell is empty, so we put it there.
0 1 2 3 4 5 6 7 8 9 +++++++++++      052517   +++++++++++
If we now hash 35, we first try to put it into cell 5 (35 is 5 mod 10). That cell is full, so we try cell 6. That cell is also full, so we try cell 7. That cell is also full, so we try cell 8. That cell is, fortunately, empty, so we put it there.
0 1 2 3 4 5 6 7 8 9 +++++++++++      05251735  +++++++++++
If we hash 49, we first try to put it into cell 9 (49 is 9 mod 10). That cell is empty, so we put it there.
0 1 2 3 4 5 6 7 8 9 +++++++++++      0525173549 +++++++++++
If we hash 53, we first try to put it into cell 3. That cell is empty, so we put it there.
0 1 2 3 4 5 6 7 8 9 +++++++++++    53 0525173549 +++++++++++
Suppose we next try to hash 68. We first try cell 8. That's full with 35.
We next try cell 9. That's full with 49. We must then wrap around
to the beginning (cell 0). That cell is empty, so we put it there.
0 1 2 3 4 5 6 7 8 9 +++++++++++ 68  53 0525173549 +++++++++++
Suppose we next try to hash 70. We first try cell 0. That's full with 68. We next try 1. That's empty, so we put it there.
0 1 2 3 4 5 6 7 8 9 +++++++++++ 6870 53 0525173549 +++++++++++
How do we find something? We start looking at the cell corresponding to the modified hash value and then step through neighboring cells until (a) we find the key, in which case we're done, or (b) we hit an empty space, in which case we report that the key/value pair is not in the hash table.
For example, to find 35, we first look in cell 5. 35 is not there, so we try cell 6. 35 is not there, so we try cell 7. 35 is not there, so we try cell 8. 35 is there, so we're done.
Similarly, to find 100, we first look in cell 0. 100 is not there, so we try cell 1. 100 is not there, so we try cell 2. Cell 2 is empty, so we note that the key of 100 is not in the hash table.
To find 99, we first look in cell 9. 99 is not there, so we wrap around and try cell 0. 99 is not there, so we try cell 1. 99 is not there, so we try cell 2. Cell 2 is empty, so we fail.
Now that you understand the basics of linearprobe hash tables, it's time for you to consider a key issue: removing elements.
Describe in psuedocode how one removes a key/value pair from a linearprobe hash table.
Note: Removal is somewhat complex. Consider what happens if we remove 25, 49, or 35 from the table above.
Warning: It is not acceptable to say rehash everything in the hash table
or a variant thereof.
Warning: You may not change the behavior of insert or find as you implement removal. In particular, you may not use the Tsuvian solution of putting a placeholder there that find says is not a match
and insert says is empty
.
Topics: Arrays, Vectors, Data Structure Implementation
Expected time: Two hours
In many of the problems we've encountered, it would help to have arrays
that automatically expand when we need them to. While Vectors solve that
problem, we don't know how Vectors are implemented (which led some of you
to assume that add
is an O(1) operation when it is likely
to be an O(n) operation). Vectors also have some annoying features.
Hence, it makes sense to design our own variant.
a. Create a DynamicArray
interface that supports the following operations. Your methods should accept all nonnegative positions. (That is,
unlike Vectors, your DynamicArrays should automatically expand with set
.)
Make sure to document each method fully.
void set(int pos, Object newval)
Object get(int pos)
(if no value was previously set at pos, return null)
String toString()
b. Implement DynamicArray
using Java arrays as the underlying
structure. For this implementation, make sure that the pos
for set
and get
is the same as the index in
the array. You will need to expand the array for larger positions in
set
. (For get
, you can simply return some
default values, such as null
.)
Topics: Sorting, Testing
Expected time: Two hours, if Java is nice to you
Useful Files:
OutOfPlaceVectorSorter.java
OOPVSTester.java
InsertionSorter.java
MergeSorter.java
SelectionSorter.java
Quicksorter.java
In the class on Tuesday, 3 May 2005,
we sketched a strategy we could use to test a sorting algorithm. I've
started that implementation in OOPVSTester.java
and some
other related files.
a. Finish implementing the test
method of OOPVSTester
.
b. Test each of the four sorting routines.
Topics: Sorting, Code Reading
Expected time: One hour
Useful Files:
a. Each of the files linked above provides an implementation of an outofplace sorting routine. Determine which of these implementations are stable and which are not. You may do this analysis by whatever means you choose (try lots of examples, study and understand the code, whatever). Explain how you arrived at your results.
b. For those that are not stable, explain how to make the sort stable. If you believe that a sort cannot be made stable, explain why.
These are some of the questions students have asked about the exam and my answers to those questions.
Problem 1: Deletion in LinearProbe Hash Tables
0 1 2 3 4 5 6 7 8 9 +++++++++++  81  14      +++++++++++
0 1 2 3 4 5 6 7 8 9 +++++++++++ 6870 53 0525173549 +++++++++++
live.)
0 1 2 3 4 5 6 7 8 9 +++++++++++ 70  53 2535176849 +++++++++++
0 1 2 3 4 5 6 7 8 9 +++++++++++ 6870 53 0525173546 +++++++++++
0 1 2 3 4 5 6 7 8 9 +++++++++++ 70  53 2535174668 +++++++++++
0 1 2 3 4 5 6 7 8 9 +++++++++++ 70  53 2546173568 +++++++++++
ghostsin the machine?
Problem 2: Dynamic Arrays
set
? Is the same as add
in Vectors?add
, which must shift values.expand the array?
set(16,"hello")
. The primitive array must now grow to a size at least 17.T[] stuff = (T[]) new Object[10];
Problem 3: Testing Sorting
OutOfPlaceVectorSorter
?Problem 4: Stable Sorting
fixan implementation in such a way that I change its asymptotic running time (e.g., from O(log_{2}n) to O(n^{2}))?
I found this Web page that says the sorting routine is inherently unstableas proof?
Here you will find errors of spelling, grammar, and design that students have noted. Remember, each error found corresponds to one point of extra credit for everyone. I limit such extra credit to five points. After the first five points, each five errors correspond to one additional point of extra credit.
middleis ambiguous. [EB, 1 point]
00
instead of 70
in an example. [SS, 1 point]
operation. [EG, 1 point]
Quicksortand not
Quick sort. [RH, 1 point]
Here I record particularly special forms of extra credit.
Late April and Early May 2005 [Samuel A. Rebelsky]
Thursday, 5 May 2005 [Samuel A. Rebelsky]
Friday, 6 May 2005 [Samuel A. Rebelsky]
Monday, 9 May 2005 [Samuel A. Rebelsky]
Tuesday, 10 May 2005 [Samuel A. Rebelsky]
[Skip to Body]
Primary:
[Front Door]
[Current]
[Glance]

[Honesty]
[On Teaching and Learning]
Groupings:
[EBoards]
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Readings]
[Reference]
Misc:
[SamR]
[Java 1.5 API]
[Espresso]
[TAO of Java]
[CS152 2004F]
Disclaimer:
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 Wed May 11 10:55:15 2005.
The source to the document was last modified on Tue May 10 09:51:29 2005.
This document may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CS152/2005S/Exams/exam.03.html
.
You may wish to validate this document's HTML ; ; Check with Bobby
Samuel A. Rebelsky, rebelsky@grinnell.edu