ZJ(P) is length of the longest substring S of P that starts at position J and matches a prefix of P Z1(P)=undefined n Initialize all sp’s to zero n Calculate I’s for every J starting from higher to lower I=J+ ZJ(P)-1 n spI’(P) = ZJ(P) 1 How to calculate Z2(P)? J 1 2 3 4 5 6 P a a a a a a S a a a a a a Z2(P)=5 1 How to calculate Z3(P)? J 1 2 3 4 5 6 P a a a a a a S a a a a a a Z3(P)=4 1 How to calculate Z4(P)? J 1 2 3 4 5 6 P a a a a a a S a a a a a a Z4(P)=3 1 How to calculate Z5(P)? J 1 2 3 4 5 6 P a a a a a a S a a a a a a Z5(P)=2 1 How to calculate Z6(P)? J 1 2 3 4 5 6 P a a a a a a S a a a a a a Z6(P)=1 2 Initialize sp’(P) for all I’s 1 <= I <= cardinality(P) cardinality(P)=6 “I” is between 1 and 6 I 1 2 3 4 5 6 spI 0 0 0 0 0 0 Calculate I’s for every J=6 and spI’(P) I/J 1 2 3 4 5 6 spI’(P) 0 0 0 0 0 1 ZI(P) 0 5 4 3 2 1 I = 6 + Z6(P) - 1 I=6+1-1=6 sp6’(P) = Z6(P) = 1 Calculate I’s for every J=5 and spI’(P) I/J 1 2 3 4 5 6 spI’(P) 0 0 0 0 0 2 ZI(P) 0 5 4 3 2 1 I = 5 + Z5(P) - 1 I = 5 + 2 - 1=6 sp5’(P) = Z5(P) = 2 Calculate I’s for every J=4 and spI’(P) I/J 1 2 3 4 5 6 spI’(P) 0 0 0 0 0 3 ZI(P) 0 5 4 3 2 1 I = 4 + Z4(P) - 1 I=4+3-1=6 sp4’(P) = Z4(P) = 3 Calculate I’s for every J=3 and spI’(P) I/J 1 2 3 4 5 6 spI’(P) 0 0 0 0 0 4 ZI(P) 0 5 4 3 2 1 I = 3 + Z3(P) - 1 I=3+4-1=6 sp3’(P) = Z3(P) = 4 Calculate I’s for every J=2 and spI’(P) I/J 1 2 3 4 5 6 spI’(P) 0 0 0 0 0 5 ZI(P) 0 5 4 3 2 1 I = 2 + Z2(P) - 1 I=2+5-1=6 sp2’(P) = Z2(P) = 5 Final Answer I/J 1 2 3 4 5 6 spI’(P) 0 0 0 0 0 5 ZI(P) 0 5 4 3 2 1