Properties of a good hash function


Now that we know what a hash function is, it should be clear that not all hash functions are the same. A good hash function for a specific type of input data (domain set) may perform poorly for other data types. How do we decide if a hash function is good or bad? A few properties of a hash function decide if it is good or bad. Some of them are given below.

Uniformity

A good hash function maps elements in the domain set (keys) to elements in the co-domain set (hash values) as uniformly as possible. Some hash functions, like the mod function (computing key % m for a fixed m, which we will see in the next lesson), are uniform. In a perfectly uniform function, every element in the co-domain set should be mapped to the same number of elements in the domain set (for example, if the domain has 100 keys and the codomain has 10 hash values, every hash value receives exactly 10 keys).

Liking the course? Check our discounted plans to continue learning.