Question
Java Programming Exercise Exercise:Write a program that creates a hash table of various sizes and various numbers of keys and collect statistics on the load
Java Programming Exercise
Exercise:Write a program that creates a hash table of various sizes and various numbers of keys and collect statistics on the load factor, number of collisions and the longest list length. Follow these steps. 1. Get the user to enter the table_size. 2. Declare an arraylist of linked lists of that size. Assume that the linked list store integer objects. 3. Get the user to enter the number of keys to be hashed. Generate that many random keys in the range 1 to 10000. You dont need to check for duplicate keys. 4. For each key generated, determine where it should be mapped (pos = key%table_size). 5. Go to the arraylist index pos and add the key into the linked list in that position. 6. After all the keys have been added, enumerate all the linked lists, find the number of collisions and the longest list length. 7. Run the program a number of times, experimenting with different number of keys (10, 20, 30, 40, , 100). Keep the table size as 10.
A sample run of the program will be as follows: Enter the size of the hash table: 10 Enter the number of keys to be hashed: 20 Hash Table created: -->8180-->6490 -->empty -->3802-->3272 -->9563-->9493 -->324-->3004-->3714 -->2375-->635-->2595-->4655-->2045 -->876 -->497-->3427 -->2258 -->529-->3419 Statistics: Table size: 10 Number of keys: 20 Load factor: 2 Number of collisions: 11 Longest list: 5
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