Data Structures & AlgorithmsVery hardICPC regional · GATE CS
A polynomial rolling hash with a fixed modulus M and random base B is used to compare two different strings of length L. Which statement is correct?
- A. Two different strings collide with probability at most about L/M over a random base, so a large prime M makes collisions rare
- B. Two different strings always have different hashes because the base is random
- C. Collisions only happen when the strings have different lengths, so equal-length strings never collide
- D. Using a larger base B always increases the number of collisions because hashes grow faster
Correct answer: A. Two different strings collide with probability at most about L/M over a random base, so a large prime M makes collisions rare
A nonzero polynomial of degree at most L has at most L roots mod M, so a random base collides with probability at most L/M. Equal-length strings can collide, and a larger base does not by itself create collisions.
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
- What is the length of the longest palindromic substring of "bananaracecarbnn"?
- Apply the reversal of the first 4 elements to the queue 1, 2, 3, 4, 5, 6, 7, 8 (front first). What is the element at position 6 of the…
- For the array [1, 3, 2, 4], take the next strictly greater element of each position (-1 if none) and sum these values, ignoring the -1…
- What is the sum of the minimum of every contiguous window of length 2 in the array [3, 1, 4, 1, 5, 9, 2, 6]?
- A singly linked list contains the people 1 to 12 in a circle. Starting from person 1, every 4th person is removed (the count starts at 1)…
- How many contiguous subarrays of [3, 4, -7, 1, 2, -6] have a sum of exactly zero?