Data Structures & AlgorithmsVery hard

Two different strings produced equal rolling-hash values. What does this tell you?

  1. A. The strings must be equal, since hashes never collide.
  2. B. The hash function is a collision: unequal strings can share a value, so a match must be verified by comparing the strings.
  3. C. The hash function is the same as the string length.
  4. D. The strings are anagrams of each other.

Correct answer: B. The hash function is a collision: unequal strings can share a value, so a match must be verified by comparing the strings.

Hash values are a fixed-size summary of arbitrarily many strings, so distinct strings can share a value. Equal hashes are a candidate match only and must be confirmed character by character.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic