[Skip to Body]
Primary:
[Front Door]
[Current]
[Glance]
-
[Honesty]
[Links]
[Syllabus]
Groupings:
[EBoards]
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Readings]
[Reference]
Misc:
[SamR]
[Java 1.4.2 API]
[EIJ]
[CS152 2000F]
[CS153 2004S]
Distributed: Wednesday, 1 December 2004
Due: 11:00 a.m., Friday, 10 December 2004
No extensions.
This page may be found online at
http://www.cs.grinnell.edu/~rebelsky/Courses/CS152/2004F/Exams/exam.03.html.
Contents
There are four problems on the exam. Some problems have subproblems. Each problem is worth twenty-five 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 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.
This exam is likely to take you about four to 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, and will
award you two points of extra credit for doing so. 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.
(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.
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 document your code (using Javadoc-style comments for classes, fields, and methods and slash-slash comments for particular algorithm details).
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 (269-4410) or at home (236-7445).
I will also reserve time at the start of classes next week to discuss any general questions you have on the exam.
As you may recall, the Quicksort algorithm is a divide-and-conquer sorting algorithm. To Quicksort a portion of a vector, you:
smalland
largevalues).
To partition the subvector:
A partial implementation of the Quicksort algorithm can be found in
Quicksorter.java.
Unfortunately, that implementation has a stub partition method.
a. Implement and test the partition method. You may find
TestQS.java
helpful for your testing.
b. Extend the code to increment steps by 1+ub-lb each time partition is called.
Using CountQS.java,
generate six sample vectors of each size of five between 5 and 100
(inclusive) which is a multiple of five and determine how many steps
each takes to sort each. Graph the results. What do the results suggest
to you?
Most of the collections we've studied so far are used primarily for
storing elements that we can step through (by iteration in a list;
by repeated deletion in a linear structure; by a traversal algorithm
in a tree). However, other kinds of collections naturally appear in
computation. For example, mathematical sets are a common ADT. A set
is a collection of elements whose primary operation is contains
(belongs to the set). While a value may appear more than once in a list or
queue, it doesn't really make sense for a value to appear more than once
in a set.
As with the more mathematical sets, you might intersect, union, or otherwise combine these sets.
Write a Set interface. Make sure to carefully consider what methods
are appropriate and what form those methods should take. As always,
be careful to document your methods clearly.
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 and Vectors have some annoying features. Hence, it makes sense to design our own variant.
a. Create a DynamicArray interface that supports the following operations. Accept all non-negative positions. 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.
In some situations, we use only a few very different indices in arrays (for example, only indices 1, 10, 423, and 1512235). In such situations, it wastes space to use an underlying Java array, since most of the cells are empty.
a. Implement DynamicArray using java.util.Hashtable.
b. Implement DynamicArray using binary search trees. You should
code these trees yourself (including the related Node class).
Each extra-credit problem is worth up to two units of extra credit on your final grade. (Remember that I cap such extra credit at six units or three points.) Time spent on the extra-credit problems does not count toward the eight hour limit on the exam.
a. The Quicksort algorithm I've implemented has a slight variant from the high-level
overview I gave you. The variant is that after identifying a pivot, I temporarily
put it at the front of the subvector and then put it back in the middle
after partitioning. Explain why.
b. Devise a way to test the memory usage of the three implementations of
DynamicArray and conduct some tests to determine which is
the most space efficient.
These are some of the questions students have asked about the exam and my answers to those questions.
Problem 1: Quicksort
Problem 3: Dynamic Arrays
get(int pos), method if pos is greater than the length of the array do we expand the array or throw an exception?Documentation is in sorting.Sorter?Here you will find errors of spelling, grammar, and design that students have noted. Remember, each error found corresponds to a point of extra credit for everyone. I limit such extra credit to five points.
Tuesday, 30 November 2004 [Samuel A. Rebelsky]
Sunday, 5 December 2004 [Samuel A. Rebelsky]
Friday, 10 December 2004 [Samuel A. Rebelsky]
[Skip to Body]
Primary:
[Front Door]
[Current]
[Glance]
-
[Honesty]
[Links]
[Syllabus]
Groupings:
[EBoards]
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Readings]
[Reference]
Misc:
[SamR]
[Java 1.4.2 API]
[EIJ]
[CS152 2000F]
[CS153 2004S]
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 Fri Dec 10 10:24:41 2004.
The source to the document was last modified on Fri Dec 10 10:24:38 2004.
This document may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CS152/2004F/Exams/exam.03.html.
You may wish to
validate this document's HTML
;
;
Check with Bobby