I was doing a program to compare the average and maximum accesses required for linear probing, quadratic probing and separate chaining in hash table.
I had done the element insertion part for 3 cases. While finding the element from hash table, I need to have a limit for ending the searching.
In the case of separate chaining, I can stop when next pointer is null.
For linear probing, I can stop when probed the whole table (ie size of table).
What should I use as limit in quadratic probing? Will table size do?
My quadratic probing function is like this
newKey = (key + i*i) % size;
where i varies from 0 to infinity. Please help me..
For such problems analyse the growth of
iin two pieces:First Interval :
igoes from0tosize-1In this case, I haven’t got the solution for now. Hopefully will update.
Second Interval :
igoes fromsizetoinfinityIn this case
ican be expressed asi = size + k, thenSo it’s sure that we will start probing previously probed cells, after
ireaches tosize. So you only need to consider the situation whereigoes from 0 tosize-1. Because rest is only the same story again and again.What the story tells up to now:A simple analysis showed me that I need to probe at mostsizetimes because beyondsizetimes I started probing the same cells.