Data Structures & AlgorithmsModerateGATE CS · TCS NQT

Which algorithm finds all occurrences of a pattern in a text in expected linear time using a rolling hash of each window?

  1. A. Dijkstra
  2. B. Rabin-Karp
  3. C. Kruskal
  4. D. Bellman-Ford

Correct answer: B. Rabin-Karp

Rabin-Karp compares hash values of windows of the text with the pattern's hash, verifying only on matches; the rolling update makes each window O(1) to hash.

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

Exams that ask this topic