Dsa 1
Dsa 1
DIV :- B
TITLE :- Consider a telephone book database of N clients. Make use of a hash table
implementation to quickly look up client‗s telephone number. Make use of two collision
handling techniques and compare them using number of comparisons required to find a set of
telephone numbers (Python).
class hashtable:
def __init__(self):
self.m = int(input("Enter size of hash table: "))
self.hashTable = [None] * self.m
self.elecount = 0
self.comparisms = 0
print(self.hashTable)
def isfull(self):
if self.elecount == self.m:
return True
else:
return False
def menu():
obj = hashtable()
ch = 0
while ch != 3:
print("*****************************")
print("1. Linear Probe *")
print("2. Quadratic Probe *")
print("3.Exit")
print("*****************************")
ch= int(input("Enter Choice: "))
if ch == 1:
ch2 = 0
while ch2 != 3:
print("** Insert **")
print("** Search **")
print("** Exit **")
ch2 = int(input("Enter your choice: "))
if ch2 == 1:
a=int(input("Enter phone number: "))
b=str(input("Enter name: "))
obj.insertvialinear(a, b)
elif ch2 == 2:
k = int(input("Enter key to be searched: "))
b = str(input("Enter name: "))
f = obj.getlinear(k, b)
if f == None:
print("Key not found")
else:
print("key found at", f)
elif ch == 2:
ch2 = 0
obj1 = hashtable()
while ch2 != 3:
print("** Insert **")
print("** Search **")
print("** Exit **")
ch2 = int(input("Enter your choice: "))
if ch2 == 1:
a = int(input("Enter phone number: "))
b = str(input("Enter name: "))
obj1.insertviaQuadratic(a, b)
elif ch2 == 2:
k = int(input("Enter key to be searched: "))
b = str(input("Enter name: "))
f = obj1.getQuadratic(k, b)
if f == None:
print("Key not found")
else:
print("key found at", f)
menu()
OUTPUT :-