Zfunctions
Z-functions, or Z-arrays, are a family of arrays used in string algorithms to describe how a string relates to its own prefix. For a string s of length n over some alphabet, the Z-function Z[0..n-1] assigns to each position i the length of the longest substring starting at i that matches a prefix of s. By convention, Z[0] is often set to n, reflecting that the whole string matches itself, although some definitions use Z[0] = 0.
Z-values can be computed in linear time using the Z-algorithm. It maintains a window [l, r], the
Z-functions have several uses. They locate all occurrences of a pattern within a text by computing Z
Variants include generalized Z-functions for different alphabets or multiple strings, as well as adaptations for circular