Data Structures & AlgorithmsModerateICPC regional · string round

Problem: What is the time complexity of computing the KMP prefix function of a pattern of length m?

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

Correct answer: C. O(m)

Amortised pointer movement along the failure chain is bounded by the number of characters processed.

More Coding Interview Problems questions

Exams that ask this topic