Question: Programming Language: Python Class: Test Code: Example of Code Running: In Lectures 26 and 27 we discussed the implementation of a hash table that used
Programming Language: Python

Class:




Test Code:

Example of Code Running:

In Lectures 26 and 27 we discussed the implementation of a hash table that used linear probing for collision resolution. In this exercise you will modify this hash table class so that it uses double hashing for collision resolution. The hash table will also increase its size whenever its load factor is 0.75 or more. The hash table will contain key-data pairs. You can assume that keys will be integer values and data strings Your hash table class will be called HashTable. The constructor for this class has no parameter. Five instance variables will be initialized: size -the size of the hash table count - the number of items in the hash table slots - a python list with size number of elements. data - a python list with size number of elements deleted- a string consisting of the null character"\0" You will need to modify the put () and delete () functions discussed in class You will also need to implement a number of your own functions. This should be done in steps as listed below: 1. Modify the put () and delete () functions so that the variable count is appropriated whenever a key-data pair is added to or deleted from the altered hash table. Change the__len__() function so that it returns this count. 2. Your hash table will use the remainder method as discussed in lectures: key % size. For collision resolution you will need to implement a second hash function: size-(key 96 (size-1)+1). You will need to alter the implementation of the rehash () function to use this second hash function. You will need to implement a function that calculates the load factor of the hash table. Remember that the load factor is calculated using the formula: = count / size 3. 4. To increase the size of the hash table you want to find a prime number that approximately doubles its current size. For example if your hash table has a size of 7, you will be looking at increasing the size of the table to 13. You will need to implement a function that finds the largest prime number in the range n +1 to 2n You will need to implement aresize () function that increases the size of the hash table appropriately a appropriate slots in the larger hash table. You will need to modify the put () function to use this resize () function appropriately 5. nd rehashes all existing key-data pairs into the
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
