Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Fundamentals Of Database Management Systems

Authors: Mark L. Gillenson

3rd Edition

978-1119907466

More Books

Students also viewed these Databases questions