Data Structures & AlgorithmsVery hard
Two different strings produced equal rolling-hash values. What does this tell you?
- A. The strings must be equal, since hashes never collide.
- B. The hash function is a collision: unequal strings can share a value, so a match must be verified by comparing the strings.
- C. The hash function is the same as the string length.
- 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.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- In iterative reversal of a singly linked list, which pointer must be saved BEFORE the current node's next pointer is changed?
- For sorted positive integers, the smallest value that cannot be formed as a subset sum equals R+1, where R is the reach. Why does a value…
- Items (weight, value) are [(5, 60), (4, 40), (6, 50), (3, 30), (2, 15), (7, 70)]. Each item can be taken at most once, and the total…
- A shop has these items as (weight, value, number available): [(2, 10, 2), (3, 14, 3), (5, 30, 1)]. You may take at most the listed number…
- How many subsets of [2, 3, 5, 7, 4, 1, 6, 8] (chosen by position, the empty set excluded) have a sum of exactly 10?
- The numbers [31, 26, 33, 21, 40] are split into two groups (every number goes to exactly one group). What is the smallest possible…