Computer Science EngineeringHard

The worst-case running time of the Rabin-Karp string matching algorithm (text length n, pattern length m) is

  1. A. O(n + m)
  2. B. O(nm)
  3. C. O(n log m)
  4. D. O(m^2)

Correct answer: B. O(nm)

If many spurious hash hits occur, each needs an O(m) comparison, giving O(nm).

More Algorithms, Data Structures & Programming (ISRO CS) questions

Exams that ask this topic