ComputeMPNext(p) {m = |p|}
begin
j ← MPnext[1] ← 0
for i ← 1 to m do
while j > 0 and p[i] ≠ p[j] do j ← MPnext[j]
j ← j + 1
MPnext[i + 1] ← j
od
end