You are provided with a C++ program that does closed hashing. It
generates keys (strings) at random, within certain length constraints.
You are provided with a makefile. You can compile the code with the command make closedhash.
The executable is called closedhash.
You will also answer some questions, below. Put the answers in your README file.
Your first task is to explore the closed hashing program, as described
below.
Your second task is to convert the hashtable implementation so that it
uses open hashing (separate chaining) instead of closed hashing.
Your third task is to collect and report statistics
on the list lengths in the hash table.
1. Compile and test the program given. Try it on table size 853 , with load factors of 0.5, 0.6, 0.7, 0.8, and 0.9. What number of collisions do you report? (Number of entries is 426, 512, 597, 682, 768.)
Report the average number of collisions per key inserted -- that is,
divide the total number of collisions by either 426, 512, etc., however
many keys are inserted (not the number of slots). Also report the longest probe sequence that you encounter in each run. Reprort these values in your README.
Debug the program so it correctly reports the number of entries.
2. Convert the hashtable program so that it uses Open Hashing (Separate Chaining), instead. Copy it first to a file you will call openhash.cpp. Then
edit this file. Use the provided makefile to make an executable called
openhash. This can be acheived using the command "make openhash" -- cat
the makefile to see that it can make two different executables.
3.
Have your program keep statistics on the list lengths. Change the
programso that it reports the total number
of lists of each length, from 0 to the longest list length in the
table. For example, your output should read something like this:
"The number of lists of a given length are as follow:
0: 3
1: 108
2: 35
3: 17
4: 0
5: 4
6: 2
Longest list length is 6"
In the README, report on the longest list length for an 853-slot table
when the load factor is 0.5, 0.6, 0.7, 0.8, and 0.9.
Test your code thoroughly.
Again test it on the load factors in Part 1, in a 853-size table. What are the results?
Your code should be demonstrably correct. Your code must be your own
(except that you can use the code provided as a basis).
Comment your code -- not verbosely, but just with the important design
decisions identified. Comment as if you thought you might have to reuse this
code in a year or so, and might forget why you did things in this particular
way.