Here is a pseudo code for computing the border array in KMP.
p is the pattern
border[1]:=-1
i:=border[1]
for j=2,...,m
while i >= 0 and p[i+1] != p[j-1] do i = border[i+1]
i++
border[j]:=i
I can execute the following pseudo code to compute the border array but the problem I am having right now is that I don't really understand the border array meaning how to interpret it.
For instance if the pattern does not equal at position (i+1) and (j-1) the variable i is set to border[i+1]. Why is that for example?
I realized the missing understanding when I tried to answer the question that three consecutive entries in a border array cannot differ by one from its predecessor. E.g. border[10]=3, border[11]=2, border[12]=1
I would appreciate a good explanation in order to get a better understanding.