5.11 Rolling Hashes
Compute hash values for sliding windows over a sequence in constant time by incrementally updating rather than recomputing.
27 notes
Compute hash values for sliding windows over a sequence in constant time by incrementally updating rather than recomputing.
Boundary conditions define the valid domain of indices, ranges, and states in an algorithm.
Array and string problems often look different on the surface, but many reduce to a small number of reusable patterns.
Flood fill explores a connected region in a grid starting from a seed cell and marks or transforms all cells that belong to the same region.
Spiral traversal visits a matrix layer by layer, moving right across the top row, down the right column, left across the bottom row, and up the left column,...
Matrix traversal processes a two-dimensional array in a defined order.
A trie is a tree structure for storing a set of strings so that common prefixes are shared.
Parsing expressions converts a sequence of tokens into a structured form that reflects operator precedence and associativity.
String comparison determines the ordering or equality of two strings.
Rolling hashes assign numeric fingerprints to substrings so that many substring comparisons can be done quickly.
Run-Length Encoding (RLE) compresses sequences by replacing consecutive equal values with a pair `(value, count)`.
A frequency table records how many times each value appears in an array, string, or stream.
Anagrams are strings or sequences that contain the same elements with the same multiplicities, possibly in different order.
A palindrome is a sequence that reads the same forward and backward.
Substring search locates occurrences of a pattern `p` inside a text `s`.
Tokenization converts a string into a sequence of meaningful units called tokens.
String scanning is the basic operation behind parsing, tokenization, validation, search, and text normalization.
Deduplication removes repeated values while preserving a chosen notion of identity and, optionally, order.
In-place modification changes an array without allocating another array of the same size.
Array rotation moves elements by a fixed offset while preserving their relative circular order.
Partitioning rearranges an array so that elements are grouped by a predicate.
Sliding windows maintain a contiguous subarray `[l, r)` while both endpoints move forward.
The two pointers technique uses two indices that move through an array or string in a controlled way.
A difference array is the inverse pattern of a prefix sum.
Prefix sums are a preprocessing technique for answering repeated range sum queries on an array.
Array traversal is the base operation for all algorithms over linear data.
This chapter studies linear data as the primary substrate for algorithm design.