Algorithms and Data Structures · Senior · Question 70 of 75
Why does a good hash function for strings process every character?
- ✓Correct answer: Hashing only a prefix makes keys with a shared prefix collide
- 2Hashing every character is required to be stable
- 3Short hashes can't be stored in JavaScript numbers
Explanation
Early Java versions hashed only some characters of long strings, and URLs with the same start collided heavily. The cost of reading the whole key is the price of an even spread.