Question: 2 . Using the Linear Probing code in tpython as a base, write insert, search and delete functions for: a . A hashtable that implements

2. Using the Linear Probing code in tpython as a base, write insert, search and delete functions for:
a. A hashtable that implements Quadrating Probing
b. Implements Double hashing, where the secondary hash function is an argument to Hashtable
constructor
class linearprobing:
def __init__(self, n):
self.table =[None]* n
self.n = n
def insert(self, key, value):
i = hash(key)% self.n
misses =0
new_i =(i + misses)% self.n
while self.table[new_i] is not None:
k, v = self.table[new_i]
if k == key:
break
misses +=1
new_i =(i + misses)% self.n
self.table[new_i]=(key, value)
def search(self, key):
i = hash(key)% self.n
misses =0
new_i =(i + misses)% self.n
while self.table[new_i] is not None:
k, v = self.table[new_i]
if k == key:
return v
misses +=1
new_i =(i + misses)% self.n
return None
def delete(self, key):
i = hash(key)% self.n
misses =0
new_i =(i + misses)% self.n
while self.table[new_i] is not None:
k, v = self.table[new_i]
if key == k:
self.table[new_i]= None
prev = new_i
curr = misses +1
new_i =(i + curr)% self.n
while self.table[new_i] is not None:
self.table[prev]= self.table[new_i]
prev = new_i
curr +=1
new_i =(i + curr)% self.n
retur
misses +=1
new_i =(i + misses)% self.n

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!