Hashing Algorithm, its uses?

There are a lot of hashing algorithms, but the basic idea is to quickly and (nearly) uniquely come up with an identifier for a piece of data. This can then be used as an index into a table so that data can be quickly looked up. Most hash algorithms have collisions, where two pieces of data will hash to the same value, but this is extremely rare for the best algorithms.

For an example of why this might be useful, let's say I hashed the entire phone book for my city. Now instead of doing a binary search when I want to look up someone's number all I have to do is run their name through the hashing algorithm then go directly to that index in my table.


Assuming you're asking someone to basically explain a use for hashing think of an array. Now imagine a huge array where you want to find a specific piece of data that is only in one array slot. Instead of iterating through the array, you can take input data, and use that to calculate the index. Using the same formula that you used to store the data in the array, you can just jump to the location of the data you want instead of looping.


Hashing algorithms try to make comparing of large data easier. Instead of comparing data to equality it is enough to compare the hash values.

There are a lot of different hashing algorithms, some of there are cryptographic hashing algorithms like MD5, SHA1, SHA256 etc. It you have two equal hash values you can be sure, that the data also the same.

Tags:

Algorithm

Hash