Suppose we have an alphabet of size $S$, a pattern of length $P$ and a text of length $T$. We want to design an algorithm for matching all caesar rotations of the pattern $P$ in the text $T$. The problem can be solved using the following two methods:
- By $\text{KMP/Z}$ against all $S$ rotations of $P$ in time $O(P+ST)$ (we can reuse the $\text{LPS/Z}$ array of the pattern).
- By $\text{Aho-Corasick}$ against all $S$ rotations of $P$ in time $O(SP+T)$ by preinserting all the rotations into an automaton.
Question: Can the problem be solved in $O(P+T)$ time?