$(\sa{cbcba})^3\sa{cbc} = \MS(\sa{aba}(\sa{cbcba})^3\sa{cbc})$. A next letter is to be compared to the letter following prefix $\sa{cbc}$ of the maximal suffix.
The pictures display the three possibilities corresponding to the execution of instructions at lines 4, 6 and 8 respectively.
Problem 40: Maximal Suffix and Its Period |
The maximal suffix of a word is its alphabetically greatest suffix. The problem follows Problem 38 and presents another pseudo-code for computing a maximal suffix. As the other it processes its input in linear time using only constant extra space.
\begin{algorithmic} \STATE $(ms,j,p,k)\leftarrow (0,1,1,0)$ \WHILE{$j+k \lt |x|$} \IF{$x[j+k] \gt x[ms+k]$} \STATE $(ms,j,p,k)\leftarrow (j,j+1,1,0)$ \ELSEIF{$x[j+k] \lt x[ms+k]$} \STATE $(j,p,k)\leftarrow (j+k+1,j-ms,0)$ \ELSEIF{$k = p-1$} \STATE $(j,k)\leftarrow (j+k+1,0)$ \ELSE \STATE $\leftarrow k+1$ \ENDIF \ENDWHILE \RETURN{$(ms,p)$} \end{algorithmic}