I'm trying to count the number of probes (or number of indices that must be passed over) when inserting keys into a list using quadratic probing
I have
def hash_quadratic(key, values):
tablesize=len(values)
index=key%tablesize
probes=0
if values[index] is None:
values[index]=key
probes+=1
return probes
else:
while values[index] is not None:
index = (index+1**2)% tablesize
probes+=1
values[index]=key
return probes
I think this just counts every time the index changes but doesn't count the number of indices that it crosses over. How do I count every index that the key passes?
If you would like to implement Quadratic probe on a hash table, you need more than the function you have written. The following class does the job you are looking for: