CMSC 420 Section 0401 - Programming Assignment 1, Part C
Due March 22, 11:45PM
Part C - Brent Variation on Double Hashing
In part C, you will extend the work you did in parts A and B.
- You need to update your implementation of
HashTable.java to be BrentHashTable.java in order to
support the Brent variation
- You also need to provide a driver class
BrentHashTablePlotData.java, which will generate gnuplot
data to empirically prove that the programming is worth the benefit,
specifically with reference to successful search.
- Optional Extra credit: let B(m) be the length of longest successful
probe sequence of a full loaded table, where m is the table
size/capacity.
Come up with a big Oh expression B(m) for large m
consistent with your experimental result. Similarly, come up with a
big-Oh expression for the cost of successful search.
Recall that in parts A and B, you wrote HashTable.java.
In part C, you need to implement the class
AbstractBrentHashTable
which extends AbstractHashTable.
Note that the AbstractHashTable.java here is the same as it in
part B.
Your implementation should be named BrentHashTable as shown below:
public class BrentHashTable extends AbstractBrentHashTable {
// Methods in Part B
public BrentHashTable (int tableSize);
private BrentHashTable ();
public int getSize ();
// hashValue(String key) and probleHashValue(String key)
// are inherited from AbstractHashTable.
public int hashValue (String key);
public int probeHashValue (String key);
public int probeCount; // doesn't need to declare, inherited from AbstractHashTable.
public boolean put (String key, Object value);
public boolean containsKey (String key);
public boolean remove (String key);
public Object get (String key);
// You may need to modify longestProbe() for BrentPut()
public int longestProbe ();
// New method in Part C
public boolean brentPut (String key, Object value);
}
If you note carefully, you will find that in Part C, a new method
is defined:
- public boolean brentPut (String key, Object value):
Maps the specified key to the specified value
in this BrentHashTable by Brent's variation of double hashing.
Note that you do NOT need to increase probeCount for each probe
in brentPut as in other methods.
note that your longestProbe() need not take O(1) constant
time when your brentPut is introduced. But it is possible and
will be considered for extra credit.
As in part B, you may need an array for updating the length of longest
probe.
- [3/18/02 added by TA:] For grading purpose,
your implementation of brentPut must follow zig-zag probing order
shown in the lecture slides.
Next the driver. The driver class BrentHashTablePlotData will
output a gnuplot data file which in turn will generate a PostScript file
like
success.ps and
longest.ps.
The goal is to produce charts of average cost(probes) of successful
search with collisions handled by Brent's variation of double hashing.
How do we produce these files?
- Your program will be executed as "java BrentHashTablePlotData putfile
", where putfile are text
files containing items (keys and elements).
- As in part B, the putfile contains key-value pairs (i.e.,
items with keys
and elements) to be inserted in the table.
Each line in this file contains the a key and its mapped element
(values are separated by spaces in our sample input. You may
assume the leading character of each line is not
a space.)
For full credit, search cost of duplicate keys should
not be counted in average search cost.
- The output, consisting of multiple data records, is printed to
the standard
output stream (System.out in Java).
Each line contains a record corresponding to a table size/capacity
from 2, 3, 5, to the largest prime less than or equal to the number
of distinct keys in putfile.
Note that the loading factor is 100%, i.e. full loaded.
You may use standard error stream (System.err in Java) for
debugging purpose.
[3/18/02 added by TA:] The hash tables for
plotting data are all
full loaded. For table size m, put the first m keys in
putfile into the table by brentPut.
- Each record has three fields separated
by spaces in sequence:
(1) table size/capacity,
(2) average successful search cost of double hashing, and
(3) length of longest successful probe sequence.
Use HashTable.probeCount wisely to implement
BrentHashTablePlotData.
That basically finishes your programming task. Here is some post
processing. Visualization is accomplished with gnuplot. You can
figure out how this works by the examples provided below.
- The driver is run using
"java BrentHashTablePlotData put199 > plot199" with putfile
put199. Here 199 means the number
of items in the putfile.
- The type of output we are looking for is here: plot199.
- Using the shell command "gnuplot plotps1" with the script file
plotps1,
you get the file success.ps.
- Here is, finally, one of the files we actually want
success.ps.
Note that you need to put required files in the current directory.
- Likewise, you may get the chart of the length of the longest probe
sequence longest.ps by
"gnuplot plotps2" with
plotps2.
- You may assume the
putfile always with name putxxx, where xxx is the number
of (possibly duplicate) keys in the file.
Grading:
- The maximum points of part C is 100.
- Grading will focus on the the new method of BrentHashTable, the
class BrentHashTablePlotData and your prediction of theoretical
B(m). However, bugs in part A and/or part B
may break the functionality required in this part.
- The public drivers for grading will be posted soon.
- [3/15/02 added by TA:] Public driver
BrentHashTableDriver1.java
is now available. Max points are 20.
- [3/17/02 added by TA:] "java
BrentHashTablePlotData put199 > myplot" with putfile
put199 and your
BrentHashTablePlotData.java.
And "java ColumnCompare plot199 myplot 5 15 5"
with plot199 and
ColumnCompare.java to see your
scores. Max points are 25.
- [3/17/02 added by TA:] "java
BrentHashTablePlotData put7 > myplot" with putfile
put7 and your
BrentHashTablePlotData.java.
And "java -Dall=true ColumnCompare plot5 myplot 5"
with plot5 and
ColumnCompare.java to see your
scores. Max points are 5.
- [4/11/02 added by TA:] All the grading drivers
are in this file: p1c_drivers.tar.gz.
Submission:
- Tar and gzip your *.java, readme and ps files,
and submit.
- The readme file should describe your prediction of theorectical
B(m) with a ps file generated by gnuplot to support your
prediction. You may also include the relevant data or script files.
- Submission is handled using the submit program with submission index 3.
Ex: "~sc42002/bin/submit 3 foo.tar.gz".
- I(TA) reserve the right to deduct up to 10 points if you don't follow
the submission procedure.
Web Accessibility