Manacher's algorithm finds the longest palindromic substring of a string in linear time by processing the string from left to right while maintaining the boundaries of the rightmost palindrome found so far, and using the already-known palindrome lengths of positions mirrored within that rightmost palindrome to avoid recomputing information a previous step has already established, only extending a palindrome check character by character when the mirrored information runs out. This improves on the naive approach of checking every possible center for a palindrome, which takes O(n squared) time in the worst case. Glenn Manacher published the technique in 1975.
Facts
Time Complexity Sources
1. Longest palindromic substring, Wikipedia
Manacher's algorithm, Runtime subsection
The algorithm runs in linear time.
Manacher's algorithm, opening sentence
Manacher (1975) invented an O(n)-time algorithm for listing all the palindromes that appear at the start of a given string of length n.
View the SourceReader Challenges (0)
No disputes yet. Spotted an error or a better source? Open the first one.
Sign in to dispute this or suggest a correction.