Notes on Suffix Array and Manacher Algorithm
Recently I am working on some data structure questions, and I kind of dive into the “Longest Palindromic Substring” problem, master(do I?) the Suffix Array and Manacher algorithm. I found that they are impressively amazing and have something in common.
What is Suffix Array?
A suffix array is a sorted array of all suffixes of a string. For example, “abracadabra”:
How to compute suffix array efficiently?
Manber and Myers invented a algorithm with runtime complexity \(O(n log^{2} n)\). The basic idea is doubling. Start with the character at each location, we first compute the orders of substrings with length 2 at each location, then use the results to compute the orders of substrings with length 4. The assessed prefix length doubles in each iteration of the algorithm until a prefix is unique (or length >= n) and provides the rank of the associated suffix.
What is Manacher Algorithm?