CSci 2101 Lab 15.

Due Friday, May 2.

Work in groups on this lab.

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

Task 1 (25 points)

Finish the unimplemented methods of separate chaining hashtables.

Task 2 (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 3, extra credit (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 the java file(s) with your testing code by e-mail to me. The subject of the message must be 2101 Lab 15. Make sure to CC your group partners.


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.