Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Limit for quadratic probing a hash table

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..

like image 698
Arun Babu Avatar asked Aug 25 '12 10:08

Arun Babu


People also ask

What is quadratic probing in a hash table?

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.

What is the time complexity of quadratic probing?

Time Complexity: O(N * TS), where N is the length of the key value and TS is the size of the hash table.

What is the disadvantage with quadratic probing?

One problem with quadratic probing is that probe sequences do not probe all locations in the table.

How many constraints are met to successfully implement quadratic probing?

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.


1 Answers

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.

like image 108
Seçkin Savaşçı Avatar answered Oct 11 '22 17:10

Seçkin Savaşçı