Data Structures & AlgorithmsVery hardGATE CS · ICPC regional

What is the smallest period of the string "abaababaab"? The smallest period p is the least p > 0 such that s[i] = s[i + p] for every valid i (p may equal the length).

  1. A. 6
  2. B. 9
  3. C. 4
  4. D. 5

Correct answer: D. 5

The smallest period is n − π[n−1], where π is the KMP prefix function, because the longest proper border gives the largest shift that still matches. Using the longest border of a proper prefix (instead of the whole string) gives a different value.

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

Exams that ask this topic