Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Task 1 [7 marks] Implement a complete version of a hash table using Linear Probing to resolve collisions. Include implementations for the following 4 functions:
Task 1 [7 marks]
Implement a complete version of a hash table using Linear Probing to resolve collisions. Include implementations for the following 4 functions:
__getitem__(self, key): Returns the value corresponding to key in the hash table. Raises a KeyError if key does not exist in the hash table. Called by table[key]
__setitem__(self, key, value): Sets the value corresponding to key in the hash table to be value. Raise an exception if the hash
fit1008 intro to computer science assessed prac 3 weeks 11 and 12 2
table is full and the key does not exist in the table yet. Called by table[key] = value
__contains__(self, key): Returns True if key is in the table and False otherwise.
hash(self, key): Calculates the hash value for the given key. Use the hash function given below.
def hash_value(self, key):
a = 101
h=0
for c in key:
h = (h * a + ord(c)) % self.table_size
return h
Task 1 used as reference. Need help with Task 3. Thank you :)
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