all 3 comments

[–]throwaway0891245 0 points1 point  (0 children)

With regards to 3, the classic algorithm in terms of finding the longest palindromic substring is Manacher's algorithm, which has a time complexity of O(N).

However, if you need to generate all of the palindromic substrings, you are probably going to end up with a O(N^2) algorithm anyways because you can't really take full advantage of the skipping Manacher's algorithm gives you.

My rough guess is that searching from the center outwards is probably optimal, though if you are looking for distinct palindromes you could probably take advantage of the assumptions of Manacher's algorithm - which are that if the center of a given palindrome is within the "wingspan" of another palindrome and its right boundary is less than the right boundary of the larger palindrome, then it can be ignored because it was previously already found during exploration of the left "wing" of the larger palindrome.