Question: [Python] Hi, I wrote a program to record collisions for inserting into a quadratic probing hash table in python. How would I change it for
[Python]
Hi,
I wrote a program to record collisions for inserting into a quadratic probing hash table in python. How would I change it for just linear probing and double hashing table? Here's what I have. This program runs and works.
f = open("in.txt","r") lines = f.read().splitlines() keys = [] totalcollisions= 0 ourfile = open('increaseRandom.txt','r') for line in ourfile: for i in line.split(): keys.append(int(i)) ourfile.close() HashTable = dict() size = 191#size that was specified for i in range(0,size): HashTable[i] = None collisions = []#records collisions for each key for key in keys: temp = key collision = 0 while(True): if HashTable[temp % size] == None: collisions.append(collision) HashTable[temp % size] = key break else: totalcollisions+=1 collision = collision + 1 temp = ( temp % size ) + collision * collision print ("Collisions record table:") print (collisions) print ("Total Collisions recorded for quadratic probing: {}".format(totalcollisions))
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
