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..
Quadratic probing is an open addressing scheme in computer programming for resolving hash collisions in hash tables. Quadratic probing operates by taking the original hash index and adding successive values of an arbitrary quadratic polynomial until an open slot is found.
Time Complexity: O(N * TS), where N is the length of the key value and TS is the size of the hash table.
One problem with quadratic probing is that probe sequences do not probe all locations in the table.
6. How many constraints are to be met to successfully implement quadratic probing? Explanation: 2 requirements are to be met with respect to table size.
For such problems analyse the growth of i
in two pieces:
First Interval : i
goes from 0
to size-1
In this case, I haven't got the solution for now. Hopefully will update.
Second Interval : i
goes from size
to infinity
In this case i
can be expressed as i = size + k
, then
newKey = (key + i*i) % size
= (key + (size+k)*(size+k)) % size
= (key + size*size + 2*k*size + k*k) % size
= (key + k*k) % size
So it's sure that we will start probing previously probed cells, after i
reaches to size
. So you only need to consider the situation where i
goes from 0 to size-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 most size
times because beyond size
times I started probing the same cells.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With