Junior — Middle
What are the key properties of hash functions?
sobes.tech AI
Answer from AI
Key properties of hash functions:
- Determinism: the same input always produces the same hash.
- Speed of computation: the hash should be computed quickly for any input data.
- Uniform distribution: the hash function should evenly distribute values across the range to minimize collisions.
- Low collision probability: different input data should, with high probability, produce different hashes.
- Pre-image resistance (for cryptographic hashes): it should be infeasible to reconstruct the original data from the hash.
Example of usage in Python:
# Using the built-in hash function for strings
s = "example"
h = hash(s)
print(h)
In the context of dictionaries and sets, hash functions allow for quick element lookup by key.