Hashing data is a form of organizing and sorting data to fit your needs. There are 2 parts to any hashing:
Smokey is the hash function;
Buckets are the place holders for the data.
Hashing
In general, a hash table is a way to store data and it is also good for searching data.
An "ideal" has function:
If there are B buckets and N items to put in them, it should be closed to N/B items.
A "bad" has function:
If there are B buckets and N items to put in them, the most items are assigned to very few buckets.
Open Hashing
Hashing looks very similar to the radix sort we have seen before. Below is how a hash table may look:
Real Hashing
Consider the following:
Therefore:
where x is in S and b is the number of buckets you have.
Let's see an example of this using a trivial case:
Evaluating each of the Hash functions below:
Another example may be the following:
Using the following definition of a Hash function:
Evaluate each of these:
To put it simply, hashing keeps the data organized by making use of the mod function.