This question comes in varieties:

  • Longest palindromic substring
  • All palindromic substring
  • Palindromic decomposition

alg. palindromic substring search.1

  • Double Loop, on :
  • DP:
  • Manacher’s algorithm2

alg. Smallest Palindromic Decomposition. Homework Link

  1. run substring search (by any of above)
  2. run DP to get smallest decomposition

alg. Palindromic Subsequence search.3 Complicated much more by the fact that it’s a subsequence.

  • A variant of Dynamic Programming
  • Idea 1: run for every char
  • Idea 2: ¶bccab, we see is a subseq. We then consider the inner b + {inner} + b and count the inner subseq.

Footnotes

  1. Longest Palindromic Substring, CS330

  2. Longest Palindromic Substring Manacher’s Algorithm - YouTube

  3. Count Different Palindromic Subsequences - LeetCode