Question: PYTHON QUESTION : (plz correct where it is wrong) for doublehashing question : class DoubleHashTable: def __init__(self, s=13, h=11): self.size = s self.slots = [None]
PYTHON QUESTION : (plz correct where it is wrong)
for doublehashing question :
class DoubleHashTable: def __init__(self, s=13, h=11): self.size = s self.slots = [None] * self.size self.hash2 = h def put(self, key): index=key%self.size i=0 if self.slots[index]==None: self.slots[index]=key else: new_index=index while self.slots[new_index] is not None: step=self.hash2-(key%self.size) new_index=index+step i+= 1 if i==self.size: break self.slots[new_index]=key def __str__(self): return str(self.slots)
WRONG OUTPUT FOR :
my_hash_table=DoubleHashTable() my_hash_table.put(26) my_hash_table.put(54) my_hash_table.put(94) my_hash_table.put(17) my_hash_table.put(31) my_hash_table.put(77) my_hash_table.put(43) my_hash_table.put(25) print(my_hash_table)
SHOULD BE :
[26, None, 54, 94, 17, 31, 43, 25, None, None, None, None, 77]
BUT GOT :
[26, None, 54, 94, 17, 31, None, None, None, None, None, 25, 77]
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
