3 ms·
The implementation of a hash table uses a hash table, which feels like cheating to me. Also I suspect that adding together the ascii values of the characters i
by cabalamat 8y ago
The implementation of a hash table uses a hash table, which feels like cheating to me.
Also I suspect that adding together the ascii values of the characters in the key is not necessarily the best hash function.
- uncletaco 8y agothe keywords "ill" and "duh" will cause collision. I know this because I ran into this issue trying to be clever on leetcode's anagram grouping problem.
- austincheney 8y agoUsing what hash mechanism? I tested with SHA512 and got different results: * ill - 2ae60a99f87408af77066079879865d907201ff44e7b1f26d911afcd1097c4c32162b97546c404d3a305396698ea530d3c3690adb7dcbc91ec685837f895a37b * duh - e44e6d93cd165ec8cdeaa632abe1c35d9a71533cc68072e100c5307ea3be17bc4f10e258785bef77d31664be0f1c3f427528c7450d52082a90c4ee86c7012184
- jovial_cavalier 8y agoAdding their ASCII together, they both yield 321.
- uncletaco 8y agoWhat jovial said. Adding ascii yields the same integer for ill and duh.
- throwaway080383 8y agoYeah, there are 26^n length n strings of lowercase alphabetical characters, but only ~26*n different hashes with that function.
- paidleaf 8y ago> Also I suspect that adding together the ascii values of the characters in the key is not necessarily the best hash function. Still better than using the length of the string as your hash value. Not my proudest moment but sometimes, you want to see the world burn. That and I forgot to do my hw and class was in a few minutes.