Why it matters

Z algorithm is simpler alternative to KMP. Popular in competitive programming.

Advertisement

The architecture

Compute Z array with Z-box.

Concat pattern#text.

Search matches.

Z algorithm string matchingCompute Z arraywith Z-boxConcatpattern#textMatchat Z[i] = |pattern|Gusfield 1997; simpler than KMP; competitive programming favorite
Z algorithm string matching.
Advertisement

How it works end to end

Gusfield 1997.

Z-box trick.

Concat trick.