5 popular hash functions ..?

I appear for an interview on Google within a week. I understand that hash tables, hash maps, hash functions are very useful and convenient in many interview questions, such as a dictionary, sorting in the form of a basket, to check duplication of one whole document, URL duplication, etc., be it on lines or be on integers. I am wondering which of the popular hash functions are used for both integers and strings.

I can think of h (n) = n for integers, where they say that we want to rank students according to their grades, that is, a very limited range of values.

Please help with more popular esp choices for strings, documents.

Thanks,

+7
source share
1 answer

For strings, you can use the string cryptographic hash as the key for the hash table. This usually results in an even distribution of the hash keys, which is a good hash table property.

If you want to narrow the key size (for example, only 32 bits), you can still choose a cryptographic hash function like SHA-256 and use the lower 32 bits.

You can also represent the number as a string or as binary data and calculate a cryptographic hash to ensure uniform distribution of keys.

Once your keys are evenly distributed, you do not need to use a complex hash function - you can simply map the range of keys into cells with the same size.

To better prepare for the interview, you can read this one .

+9
source

All Articles