01Borders and the prefix function
A border of a string is a proper prefix that is also a suffix. In ABAB, the string AB is both how it starts and how it ends.
The prefix function stores, for every position i of the pattern, the length of the longest border of P[0..i]:
π[i] = longest proper prefix of P[0..i] that is also its suffix
For ABABC you get π = [0, 0, 1, 2, 0]. Why care? If you matched ABAB and then fail, the last two characters you read (AB) are already the first two characters of the pattern. You can keep them instead of starting over. That one observation drives the whole algorithm.