Computing Atlas

How Computing Was Built
Sign In
Text size
100%
Theme
Algorithm

Manacher's Algorithm

String Algorithm

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
Linear time 1
Credited To
Manacher, 1975 1
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 Source
Comments (0)
No comments yet. Be the first to share a thought.
Reader Challenges (0)
No disputes yet. Spotted an error or a better source? Open the first one.