Pattern search
KMP: at a failed character, shift until matching. Easy to see linear time with aaaa…
Boyer-Moore (BM): skip max(bad-char rule, good-suffix rule)
Suffixes
Longest palindrome: Manacher’s algo is like Z algorithm but growing out from centers.
Range queries: for sums, range minimum queries (RMQ), etc.
Prefix array: simple but expensive to update
Segment tree: just the aggregates in a binary tree. Construct in O(n), query/update in O(log n).
Fenwick tree aka binary index tree (BIT): like segment tree but more compact/efficient, using just length N array, by removing redundant info—but assumes aggregate function is invertible (like sum can have subtraction, but not for min/max). Construct in O(n).
Sparse tables
Problems
best(k,i,j) = best path from i to j through k at some point = min( best(k-1,i,j), best(k-1,i,k) + best(k-1,k,j) )
. $O(V^3)$