Hashing

Hashing

Normally you'd have to search through the whole list of words every time you wanted to check if a word is there. That can take a long time if there are lots of words.

With hashing, instead of storing the actual words, you store them based on a "hash code" you calculate from each word. For example, you might take the first letter of each word and convert it to a number:

  • apple → 1
  • banana → 2
  • orange → 3

You store these hash codes in a hash table. To check if a word is there, you just calculate its hash code and see if it's in the table. Way faster than searching through all the words!

Hash function

The hash code is called a "hash function". It's important that it maps words evenly across the hash table, and no two words get the same hash code.
Hash codes aren't usually as simple as taking the first letter. Usually it involves doing some math on the letters of the word to scramble them up into a number. A good hash function should be fast and also distribute the data evenly in memory space we can work with which is called Uniform Hash Function.

Time complexity

if in each cell we have data where is time complexity is , the proof is simple… .