Skip to content
UPEEC

String and Math Algorithms

Pattern matching, hashing, number theory, combinatorics and computational geometry.

Advanced
Comments 0

This is an overview — pick a sub-topic below.

Sub-topics (18)

KMP Algorithm

Knuth-Morris-Pratt pattern search in $O(n + m)$ using a prefix (failure) function.

Advanced♥ 0🔖 0💬 0

Rabin-Karp Algorithm

Pattern search using rolling hashes; compare strings only when hashes match.

Intermediate♥ 0🔖 0💬 0

Z Algorithm

Computes for each position the length of the longest substring matching a prefix, in $O(n)$.

Advanced♥ 0🔖 0💬 0

Boyer-Moore Algorithm

Pattern search scanning from the pattern's end and skipping ahead using bad-character and good-suffix rules.

Advanced♥ 0🔖 0💬 0

Rolling Hash

Update a substring's hash in $O(1)$ when the window slides.

Intermediate♥ 0🔖 0💬 0

Suffix Automaton

The smallest automaton accepting all substrings of a string, built in $O(n)$.

Expert♥ 0🔖 0💬 0

GCD and LCM

Greatest common divisor via Euclid's algorithm; $\text{lcm}(a,b) = a/\gcd(a,b)\cdot b$.

Beginner♥ 0🔖 0💬 0

Sieve of Eratosthenes

Find all primes up to $n$ by crossing out multiples — $O(n\log\log n)$.

Easy♥ 0🔖 0💬 0

Prime Factorization

Break a number into prime factors by trial division up to $\sqrt n$, or using a smallest-prime-factor sieve.

Easy♥ 0🔖 0💬 0

Modular Arithmetic

Arithmetic with remainders: $(a+b)\bmod m$, $(a\cdot b)\bmod m$, and modular inverses.

Intermediate♥ 0🔖 0💬 0

Combinatorics

Counting arrangements and selections.

Intermediate♥ 0🔖 0💬 0

Matrix Exponentiation

Raise a matrix to a power in $O(k^3\log n)$ to solve linear recurrences fast.

Advanced♥ 0🔖 0💬 0

Geometry Algorithms

Points, vectors, lines and polygons computed with cross products.

Advanced♥ 0🔖 0💬 0

Convex Hull

The smallest convex polygon containing all points.

Advanced♥ 0🔖 0💬 0

Line Sweep

Process geometric events sorted along one axis while maintaining an active set.

Advanced♥ 0🔖 0💬 0

Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.

Discussion (0)

Sign in or join free to ask questions and discuss this topic.