Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

modify the HashTable class below in python Modify the Python hash table implementation with chaining (HashTable.py) so that it doubles the size of the array

modify the HashTable class below
in python
image text in transcribed
image text in transcribed
image text in transcribed
Modify the Python hash table implementation with chaining (HashTable.py) so that it doubles the size of the array whenever the number of items in the hash table reaches 70% of the array size. The hash function should be rewritten. Make the list of coefficients self.coeff longer to include 10 or more primes, perhaps starting with a larger prime than 2. Add an additional member variable self.numcoeff that records the number of coefficients from the array self.coeff and number of characters of the word used in computing the hash function. This variable will replace the number 6 in the hash function You should also write a function resize to resize your array. That function should create a new temp list for the table with double the space of the existing self.table. The function should increase self.numcoeffs by 1 . You will need to copy all of the items in the original array into the new array, using the new hash function to compute the index of each item in the new array. Once everything is copied into the temp list, assign that list to the member variable self,table and update the other member variables as needed. Finally, modify the __setitem_ function so that it checks the resizing condition after inserting a new element. If the number of items is 70% or more of the array size after the new element has been inserted, resize the array. The file test_HashTable.py is a test for this improved class. \# HashTable.py class HashTable(object): \#- def __init__(self, size=11): ''post: hash table is created'" self.array_size = size \#size of the list/array to store pairs self.table =[] \#the array for i in range(self. array_size): self. table. append ( [ ] ) stored self.size =0 \#number of pairs that are self, coef = [self, array_size, 2, 3, 7, 5,11,13] \#computing hash function \#- def _hash(self, key): pos =0 for i in range (min (len(key),6)) : pos + = self. coef [i] ord (key[i]) return pos \% self.array_size \#- def __setitem__(self, key, value): $h[s]=i "'post: value for specified key is inserted into hash table': pos = self._hash(key) for i,(k,v) in enumerate(self,table[pos]): if key =k : self, table[pos] [i]=(key, value) return self, table[pos], append((key, value)) \#chaining self.size +=1

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

Practical Database Programming With Visual C# .NET

Authors: Ying Bai

1st Edition

0470467274, 978-0470467275

More Books

Students also viewed these Databases questions

Question

What are the classes of humansystem interfaces?

Answered: 1 week ago