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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started