Z algorithm


Definition
Given the sequence S and the index i, let i-th Z value of S be the length of the longest subsequence of S that starts at i and matches the prefix of S.

Example
Here is an example for string "abababaca":
i:012345678
S:abababaca
Z:905030101


Summary
The z-algorithm vocabulary implements algorithm for finding all Z values for sequence S in linear time. In contrast to naive approach which takes Θ(n^2) time.