Question: PYTHON 3 PLEASE FOLLOW INSTRUCTIONS COMPLETE CODE Problem : One of the ways a HashTable deals with collisions is by growing the internal array used

PYTHON 3 PLEASE FOLLOW INSTRUCTIONS

COMPLETE CODE

Problem :

One of the ways a HashTable deals with collisions is by growing the internal array used to store the data whenever the number of items in the table exceeds a certain threshold.

The typical mechanism for growing the HashTable involves creating a new internal array that is twice the size of the original array, updating the hashing function to now use the new array size, and rehashing all the keys of elements already in the table to map to new locations in the new array.

Your job is to complete the function rehash_everything(), which takes in the new array size, creates a new internal array with the given size, and moves all the things from the previous internal array to the new one.

PYTHON 3 PLEASE FOLLOW INSTRUCTIONS COMPLETE CODE Problem : One of the

Code :

class Node: def __init__(self, key, value): self.key = key self.value = value self.next = None

class HashTable: def __init__(self): self.array = [] self.internal_array_size = 50 for i in range(self.internal_array_size): self.array.append(None) def rehash_everything(self, new_size): # TODO # make a new array and populate it with empty entries # go through the elements of the old array for list in self.array: if list is not None: # list now contains the list of nodes that were hashed to # this location in the array # we need to map them to new locations in the new array # make self.array the new array

1. class Node: def _init_(self, key, value): self.key = key self.value = value self.next = None class HashTable: def _init_(self): self.array = [] self.internal_array_size = 50 for i in range(self.internal_array_size): self.array.append(None) 14- def rehash_everything(self, new_size): # TODO # make a new array and populate it with empty entries # go through the elements of the old array for list in self.array: if list is not None: # list now contains the list of nodes that were hashed to # this location in the array # we need to map them to new locations in the new array # make self.array the new array

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!