Question: class HashTable: def _ _ init _ _ ( self , m = 1 0 ) : # default initial array length: 1 0 ,

class HashTable:
def __init__(self, m=10):
# default initial array length: 10, threshold: 0.75
self.inArray =[LinkedList() for i in range(m)]
self.size =0
self.threshold =0.75
def add(self, d):
i = self.hash(d)
self.inArray[i].insert(0,d)
self.size +=1
if self.size > self.threshold*len(self.inArray):
self._resizeUp()
def _resizeUp(self):
oldArray = self.inArray
self.inArray =[LinkedList() for i in range(2*len(oldArray))]
for i in range(len(oldArray)):
while oldArray[i].length >0:
d = oldArray[i].remove(0)
self.inArray[self.hash(d)].insert(0,d)
Write a function:
def _resizeUp(self)
that, similarly to the corresponding function for HashTable that we saw in class, doubles the length of the internal linked list and rehashes and reinserts all of the elements.

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 Programming Questions!