Tuesday, October 27, 2009

[SPOJ] EPALIN

Consider the longest border (LB) problem:

Input: string s[1..n] of length n
Output: LB(s) = max{ i | i < n AND s[1..i] = s[n-i+1..n] }

LB(s) can be computed in O(n) (this problem was introduced in the KMP algorithm)

EPALIN is essentially to find the longest palindrome suffix:
LS(s) = min{i | s[i..n] is a palindrome}

We reduce LS to LB. Consider the string:
$s^\prime = s_ns_{n-1}...s_1 \alpha\beta s_1s_2...s_n$ in which $\alpha \neq \beta$

It is easy to prove that LS(s') = LB(s)

Note: palindromic property can sometimes be handled by consider the string $SS^R$

No comments:

Post a Comment