Question: Creating a Hash Table using Java What to Do: Use an array for the hash table, starting with a size of 5. Each time the

Creating a Hash Table using Java

What to Do:

Use an array for the hash table, starting with a size of 5. Each time the array gets to 80% capacity, double its size.

Create a class to hold the data, which will be key-value pairs. The class should contain afield for the key and a field for the value. The key will be an integer and the value will be a string.

Use a simple hash function- key % hashTable.length

For collision resolution, use open addressing with linear probing

The program should include:

A class to hold the key-value pairs

A class to hold the array of key-value pairs

A method to insert data into the hash table

o Since the hash function and collision resolution are simple, you could include them in this method, or you could write separate methods for them.

A method to double the size of the array when needed, and a rehash method to go along with it.

You may test your program with a separate class for the driver, or just put a main method in the same class as the array of key-value pairs.

Implement a way to print out the contents of the hash table for testing.

Implementing search and delete methods are not required for this lab.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!