Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

Here is the implementation of the resizeUp function for the HashTable class that doubles the length ... 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

Income Tax Fundamentals 2013

Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill

31st Edition

1111972516, 978-1285586618, 1285586611, 978-1285613109, 978-1111972516

More Books

Students also viewed these Programming questions