adidas official website Linear Probing Hash Tables

Data can be added to the table by calculating the hash code from the key of the data that is being stored, and then placing the data in the corresponding hash element.

However, there are many more possible search keys than there are hash elements. It is inevitable that some keys will resolve to the same hash code. This is known as a hash collision, and it must be handled.

Hash collisions will always occur, but they can be avoided.

This traversal is known as probing the table; and as it goes by one element at a time, it is linear probing.

There are other kinds of probing; for example quadratic probing is where the traversal skips one element, then two, then four, etc. until a free space is found.

Consider the situation mentioned above where data ‘F’ has the same hash code as data ‘D’. In order to resolve the collision, the add algorithm will need to probe the table in order to find the first free space (after ‘C’).

Consider the situation mentioned above where data ‘F’ has the same hash code as data ‘D’. In order to resolve the collision, the add algorithm will need to probe the table in order to find the first free space (after ‘C’).

If the probe loops back, and finally reaches the same element that it started at, it means that the hash table is full, and can no longer hold any more data. From this key, we can calculate the hash code. This tells us where in the data array we need to start searching.

Because of the collision resolution of the add operation, the target data might reside at a location other than the element referred to by the hash code.

Therefore, it is necessary to probe the hash table until an empty hash element is found, and for an exact match between each data item and the given key. (The probing stops at an empty element, since it signals the end of where potential data might have been stored.)