Manacher's Algorithm
Manacher's Algorithm
Topic/Course
• Manacher's algorithm is used to find the longest palindromic substring in any given string.
This algorithm is faster than the brute force approach, as it exploits the idea of a
palindrome happening inside another palindrome.
• Manacher's algorithm is designed to find the palindromic substrings with odd lengths only.
To use it for even lengths also, we tweak the input string by inserting the character "#" at
the beginning and each alternate position after that (changing "abcaac" to
"#a#b#c#a#a#c#").
• In the case of an odd length palindrome, the middle character will be a character of the
original string, surrounded by "#".
Steps of the Manacher's algorithm are as follows: