String matching is a common type of problem in computer science. One string matching problem is as following:
Given a string $s[0 \ldots len-1]$, please calculate the length of the longest common prefix of $s[i \ldots len-1]$ and $s[0 \ldots len-1]$ for each $i > 0$.
I believe everyone can do it by brute force.
The pseudo code of the brute force approach is as the following:
We are wondering, for any given string, what is the number of compare operations invoked if we use the above algorithm. Please tell us the answer before we attempt to run this algorithm.