Rolling Hash & Suffix Arrays

Data Structures & Algorithms · Advanced Strings · Master · 35 min

Compare any two substrings in O(1) with prefix hashes (and know when collisions bite), then sort every suffix into a suffix array with an LCP array to find the longest repeated substring.

This lesson is part of TuringPath Pro. See plans.

What you will learn

  • Prefix hashes: any substring's fingerprint in O(1)
  • Collisions: the birthday problem
  • Suffix array: all suffixes in sorted order
  • LCP array and the longest repeated substring
  • Hashing or a suffix array?

More in Advanced Strings

Previous: Z-Function & Manacher's Algorithm