Definition
Prefix Function
Given a string of length , the prefix function maps each index to the length of the longest prefix of that is a suffix of and strictly shorter than .
Equivalently, is the length of the maximal non-trivial border of the prefix . For , we have (the only non-trivial border of a single character is ).
Examples
0 a0 1 ab0 2 aba1 3 abab2 4 ababa3 5 ababac0 6 ababaca1 For , the prefix equals the suffix ; they may overlap.
0 a0 1 aa1 2 aaa2 3 aaaa3
0 a0 1 ab0 2 abc0 3 abca1 4 abcab2