Question
Modify the class BasicHashTable with double hashing (hash2(key)=5-key%5) such that it stores a list of probe sequences for inserted keys. The class should have the
Modify the class BasicHashTable with double hashing (hash2(key)=5-key%5) such that it stores a list of probe sequences for inserted keys.
The class should have the following attributes:
class BasicHashTable:
def __init__(self,size=7):
self.size = size
self.slots = [None] * self.size
self.probeSequences = [[]] * self.size
The list probeSequences contains initially an empty list for each slot. If a key is inserted into slots[k] then probeSequences[k] should contain the entire probe sequence produced when inserting that key
Please write the code in python
Test:
hash_t = BasicHashTable() #default table size is 7 hash_t.put(3) hash_t.put(20) hash_t.put(10) print(hash_t.slots) print(hash_t.probeSequences)
Result:
[None, 10, None, 3, None, None, 20] [[], [3, 1], [], [3], [], [], [6]]
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started