Uploaded by clique116fan

Open Addressing Hash Experiment

advertisement
COSC2203 Data Structures
Open Addressing Hash Experiment
Introduction
This is an exercise in designing and implementing an open addressing hash table, and then using the
hash table to empirically evaluate the performance of the linear and quadratic probing techniques under
a series of load percentages. (it’s also implicitly an evaluation of your ability to follow directions and ask
questions.)
The load, l, of an open addressing hash table is determined by the number of elements, n, to be inserted
and the total number of spaces, b. l = n/b. For example, 25 elements inserted into an array of size 100
would have a load value of 25%. Table size should be the next prime number greater than the target
table size based on the load value.
The experiment involves the insertion of 45,403 words from the file named “dictionary.txt” found with
the assignment. Use a series of loads ranging from 50%-100% in 5% increments. Vary the load by
varying the available table size. Implement the table as an array to ensure static table sizes.
Results
The product of this exercise will be an experimental report, submitted as a pdf file, containing the
following
1. A brief introduction
2. A table of numeric results containing five columns
a. the load value
b. the number of items inserted without collision and the total number of collisions for
the linear probe (single-step)
c. the number of items inserted without collision and the total number of collisions for
the quadratic probe
3. A line graph comparing the number of collisions for both techniques
4. A line graph comparing the number of items inserted without collision for both techniques
5. A brief narrative analysis of the results.
6. A listing of the documented source code (remember to include authorship documentation)
Notes
Use the built-in String hashcode() method to hash the words, or write a better one. Remember that the
quadratic probe involves a squaring of the probe size for each successive collision, starting with 1 and
then proceeding as collisions occur with probe sizes of 1, 4, 9, 16, 25, … plus the number of probes so
far. For example, if the first hash code results in a collision, the next probe would be a step size of 2
from the current location. If a second collision occurs, the step size would be 6 and then 11, 20,
30, 42 and so on.
Remember
•
•
The probe size is reset at the beginning of each word insertion.
Make sure the value returned from hashcode() is positive.
Example of Graphed Results
Download