Lukas' Notes

computation

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

0a0
1ab0
2aba1
3abab2
4ababa3
5ababac0
6ababaca1

For , the prefix equals the suffix ; they may overlap.

0a0
1aa1
2aaa2
3aaaa3

0a0
1ab0
2abc0
3abca1
4abcab2