Concepts3
⚙️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
Tree DP - Rerooting Technique
Rerooting (a.k.a. 换根 DP) computes a per-node answer as if each node were the root, in total O(n) time on trees.
#rerooting#tree dp#prefix suffix+11
⚙️AlgorithmIntermediate
DP on Trees
DP on trees is a technique that computes answers for each node by combining results from its children using a post-order DFS.
#tree dp#post-order dfs#rerooting+12