next up previous
Next: Up: Previous:

Pseudocode

Compute-Good-Suffix(P, m)
$\;\;\;\;\;$$\pi$ = Prefix(P)
$\;\;\;\;\;$P' = reverse(P)
$\;\;\;\;\;$$\pi$' = Prefix(P')
$\;\;\;\;\;$for j = 0 to m $\;\;\;\;\;$ $\;\;\;\;\;$ $\;\;\;\;\;$; O(m)
$\;\;\;\;\;$ $\;\;\;\;\;$$\gamma$[j] = m - $\pi$[m]
$\;\;\;\;\;$for l = 1 to m
$\;\;\;\;\;$ $\;\;\;\;\;$j = m - $\pi$'[l]
$\;\;\;\;\;$ $\;\;\;\;\;$if $\gamma$[j] > l - $\pi$'[l]
$\;\;\;\;\;$ $\;\;\;\;\;$then $\gamma$[j] = l - $\pi$'[l]
$\;\;\;\;\;$return $\gamma$



Example

m = 4
P = yoyo, $\pi$ = 0012
P' = oyoy, $\pi$' = 0012
$\gamma$ = 22222
$\gamma$ = 22221


next up previous
Next: Up: Previous: