Compute the prefix function
$\pi$ for the pattern$\text{ababbabbabbababbabb}$ .
Give an upper bound on the size of
$\pi^*[q]$ as a function of$q$ . Give an example to show that your bound is tight.
Explain how to determine the occurrences of pattern
$P$ in the text$T$ by examining the$\pi$ function for the string$PT$ (the string of length$m+n$ that is the concatenation of$P$ and$T$ ).
Use an aggregate analysis to show that the running time of KMP-MATCHER is
$\Theta$ .
The number of
Use a potential function to show that the running time of KMP-MATCHER is
$\Theta(n)$ .
Show how to improve KMP-MATCHER by replacing the occurrence of
$\pi$ in line 7 (but not line 12) by$\pi'$ , where$\pi'$ is defined recursively for$q = 1, 2, \dots, m - 1$ by the equation
$\displaystyle \pi'[q] = \left \{ \begin{array}{ll} 0 & \text{if}~ \pi[q] = 0, \\ \pi'[\pi[q]] & \text{if}~ \pi[q] \ne 0 ~\text{and}~ P[\pi[q] + 1] = P[q + 1] \\ \pi[q] & \text{if}~ \pi[q] \ne 0 ~\text{and}~ P[\pi[q] + 1] \ne P[q + 1] \\ \end{array} \right . $$
Explain why the modified algorithm is correct, and explain in what sense this change constitutes an improvement.
If
Give a linear-time algorithm to determine whether a text
$T$ is a cyclic rotation of another string$T'$ . For example,$\text{arc}$ and$\text{car}$ are cyclic rotations of each other.
Find
Give an
$O(m|\Sigma|)$ -time algorithm for computing the transition function$\delta$ for the string-matching automaton corresponding to a given pattern$P$ . (Hint: Prove that$\delta(q, a) = \delta(\pi[q], a)$ if$q = m$ or$P[q + 1] \ne a$ .)
Compute the prefix function