CSci 2101 Problem set 5: hash tables

Due Thursday, May 5 at 11:59pm (by e-mail)

Your goal is experiment with different implementations of hashtables. The starting code is here.

Task 1 (30 points). Implementing open addressing hash tables.

Implement three open addressing hash table classes. Note that most of the code in the three tables is the same. The only difference is the collision resolution mechanism. Therefore it makes sense to implement most of the functionality in an abstract class that provides code for all methods except getNextIndex method that provides the next index given the key and the probe number. The getNextIndex method should be declared abstract and overwritten in the subclasses.

The class structure should be as follows:

Test your classes well. You might want to write a method that returns the contents of the array (as an array or array list). Note that some elements are null and should be printed in the output since they indicate an empty slot.

The easiest way to test hash tables is by using Integer for both the key and the value.

Task 2 (12 points). Comparing open addressing hash tables.

You need to compare the number of collisions when putting randomly generated keys (and the corresponding values) into the three hash tables. In order to measure collisions you need to add a counter to each class that counts the number of times the method getNextIndex is called in that class. At the end the counters are printed and compared.

Specifically you need to do the following:

How to submit

Submit your Java file(s) to me by e-mail. The subject must be Problem Set N, where N is the problem set number. If working in a group, CC your group partner.

CSci 2101 course web site.

The views and opinions expressed in this page are strictly those of the page author. The contents of this page have not been reviewed or approved by the University of Minnesota.