Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

From Herds To Insights Harnessing Data Analytics For Sustainable Livestock Farming

Authors: Prof Suresh Neethirajan

1st Edition

B0CFD6K6KK, 979-8857075487

More Books

Students also viewed these Databases questions