Concepts2
⚙️AlgorithmIntermediate
Z-Function
The Z-function of a string S computes for each position i the length of the longest substring starting at i that matches the prefix of S.
#z-function#z algorithm#string matching+12
⚙️AlgorithmIntermediate
String Hashing (Polynomial Hash)
Polynomial string hashing encodes a string as a base-p number modulo a large prime, letting us compare substrings in O(1) after O(n) preprocessing.
#string hashing#polynomial hash#rolling hash+12