Answered step by step
Verified Expert Solution
Question
1 Approved Answer
irected Lab Work A hash table class with linear collision resolution has already been implemented in the HashedDictionaryOpenAddressingLinear class. You will implement three new classes
irected Lab Work
A hash table class with linear collision resolution has already been implemented in the
HashedDictionaryOpenAddressingLinear class. You will implement three new classes
HashedDictionaryOpenAddressingLinearInstrumented
HashedDictionaryOpenAddressingDoubleInstrumented and
HashedDictionaryOpenAddressingPerfectInstrumented based on that class. They will allow you to
gather statistics about the number of probes made to insert values. The HashPerformance class will generate
random arrays of keys, insert the keys in the various kinds of hash tables, and then display the averages.
Implementing Double Hashing
Step If you have not done so look at the implementation of a hash table with linear probing in
HashedDictionaryOpenAddressingLinear.java Look at the code in CheckSearchHashTable.java
Compile the classes CheckSearchHashTable and HashedDictionaryOpenAddressingLinear Run the
main method in CheckSearchHashTable
Checkpoint: The program will ask you for the number of trials, the number of data values, and a seed. Enter
and respectively. An array of random values between and should be generated. The
first of those values will be inserted into a hash table. The code will check that searches work correctly.
The first values in the array will then be removed from the hash table. Again searches will be checked.
Finally, the last values in the array will be added into the hash table. Again searches will be checked.
Verify that the code passed each of the three tests.
The first goal is to create the class for double hashing and verify that it works.
Step Copy HashedDictionaryOpenAddressingLinear.java into a new file
HashedDictionaryOpenAddressingDoubleInstrumented.java
Step Create a new private method getSecondHashIndexObject key which computes a second
hash function. Refer to the formula created in the prelab exercises.
Step Refer to the prelab exercises and modify the locate and probe methods to use double
hashing instead of linear hashing.
Step Change the code in CheckSearchHashTable so that it creates a new object of type
HashedDictionaryOpenAddressingDoubleInstrumented
Run the main method in CheckSearchHashTable
Lab Hash Table Implementation
Checkpoint: Use and for the input values.
Verify that the code passed each of the three tests. If not, debug the code and retest.
The next goal is to create the class for perfect hashing and verify that it works.
Implementing Perfect Hashing
Step Copy HashedDictionaryOpenAddressingLinear.java into a new file
HashedDictionaryOpenAddressingPerfectInstrumented.java
Step Create a new private method getHashGeneratorObject key which will create and return a
random number generator that will be used to generate the sequence of probes. Refer to your answer from the
prelab exercise.
Step Again, refer to the prelab exercises and modify the locate and probe methods to use
perfect hashing instead of linear hashing. Remember to change the first argument to be a random number
generator instead of an integer.
Step Find all places where the locate and probe methods are called and change it so that
getHashGenerator is called invoked instead of getHashIndex Once you are finished, there should no
longer be any calls to getHashIndex Remove the getHashIndex method.
Step Change the code in CheckSearchHashTable so that it creates a new object of type
HashedDictionaryOpenAddressingPerfectInstrumented
Run the main method in CheckSearchHashTable
Checkpoint: Use and for the input values.
Verify that the code still passes each of the three tests. If not, debug the code and retest.
Adding Statistics
Step Copy HashedDictionaryOpenAddressingLinear.java into a new file
HashedDictionaryOpenAddressingLinearInstrumented.java
Step Refer to the prelab exercises and add in code to the locate and probe methods that will
count the number of probes.
Step Change the code in CheckSearchHashTable so that it creates a new object of type
HashedDictionaryOpenAddressingLinearInstrumented
Run the main method in CheckSearchHashTable
Checkpoint: Use and for the input values.
Verify that the code still passes each of the three tests. If not, debug the code and retest.
Step Make similar changes in HashedDictionaryOpenAddressingDoubleInstrumented and
HashedDictionaryOpenAddressingPerfectInstrumented
Step Change the code in CheckSearchHashTable so that it creates a new object of type
HashedDictionaryOpenAddressingDoubleInstrumented Run the main method in
CheckSearchHashTable
Checkpoint: Use and for the input values.
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