Блог пользователя Tariqul

Автор Tariqul, 12 лет назад, По-английски

In some contest, there is some string related problem. Many authors use hashing algorithm to make the solution faster. When string length is so small that hash value does not overflow, then I have no question. But when string length is too big to hash value is over flow, then how solution gives guarantee that there is no hash value of two different string is unique.

Can anyone clarify it please?

Thanks.

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

»
12 лет назад, # |
Rev. 2   Проголосовать: нравится +5 Проголосовать: не нравится

There is no guarantee that hash values are unique, but the probability of a collision is very low.

»
12 лет назад, # |
  Проголосовать: нравится +32 Проголосовать: не нравится

You rather beat tourist than hashing gives a collision.

»
12 лет назад, # |
Rev. 2   Проголосовать: нравится +16 Проголосовать: не нравится

There is no guarantee that the hash of 2 different strings are unique. When using hash value to compare strings, there are always some (small) probability that your code will give incorrect answer for an input. It is up to the programmer to decide whether it is safe enough or not to use hash.

Edit: sorry for same answers as above. When I started typing, there was no comment :(