Short answer: Counting sort histograms keys that lie in 0, 1, …, k−1, turns the histogram into prefix totals, and writes each record into the slot those totals name. The time and the extra memory are Θ(n+k). Writing from the end of the input and decrementing the total makes…
Author: HoHo Zhao
How Cooley-Tukey splits a discrete Fourier transform
Short answer: The Cooley-Tukey FFT computes a discrete Fourier transform of length n = 2^m by splitting it into the even indices and the odd indices, each a transform of length n/2, then combining them with twiddle factors ω^k. The recurrence T(n) = 2T(n/2) + O(n) solves to O(n…
How consistent hashing places keys on a ring
Short answer: Consistent hashing maps keys and nodes onto a circle by a hash. A key is stored on the first node at or clockwise from the key’s point. Adding or removing a node moves only the keys that walk past that node, about 1/n of the keys when…
How conjugate gradient solves a symmetric positive system
Short answer: Conjugate gradient solves Ax = b when A is symmetric positive definite. It builds A-orthogonal search directions so that each new direction does not undo the minimization along earlier ones. In exact arithmetic it reaches the solution in at most n steps for an n by n…
How Cohen-Sutherland clips a segment with outcodes
Short answer: The Cohen-Sutherland algorithm clips a line segment to an axis-aligned rectangle by assigning each endpoint a 4-bit outcode. The bits say above, below, left, and right. If both codes are zero, the segment is inside. If the bitwise AND of the codes is nonzero, both endpoints share…
How Christofides approximates a metric tour
Short answer: Christofides’ algorithm builds a traveling-salesman tour that is at most 3/2 times optimal when the distances are symmetric and obey the triangle inequality. It computes a minimum spanning tree, finds a minimum-cost perfect matching on the vertices of odd degree, and shortcuts an Eulerian circuit of the…
How Chan’s algorithm hulls in n log h time
Short answer: Chan’s algorithm computes a planar convex hull in O(n log h) time, where h is the number of hull vertices. It guesses a parameter m, splits the points into groups of size m, and hulls each group with a standard O(m log m) hull. Gift wrapping then…
How bucket sort uses a uniform spread
Short answer: Bucket sort drops keys from a known numeric range into n buckets, sorts each bucket, and concatenates them. When keys are independent and uniform, the buckets stay small and the average time is Θ(n). One bucket that receives every key falls back to the inner sort, which…
How bubble sort finishes one suffix item per pass
Short answer: Bubble sort swaps every adjacent inversion and then shortens the unsorted prefix. After pass i the last i items are in their final places. A pass that swaps nothing means the prefix is sorted too, so the scan stops. The worst case remains Θ(n²) comparisons. It is…
How Bron-Kerbosch lists maximal cliques
Short answer: The Bron-Kerbosch algorithm lists every maximal clique of an undirected graph. It keeps a current clique R, a set P of candidates that can still extend R, and a set X of vertices already excluded. A pivot taken from P ∪ X limits the branches to candidates…
How Bresenham rasters a line with integer steps
Short answer: Bresenham’s line algorithm chooses the pixel sequence from (x0, y0) to (x1, y1) using only integer additions. It walks the major axis one pixel at a time and keeps an error term that decides when the minor axis steps. Starting from zero and adding twice the minor…
How Brent’s cycle search resets on powers of two
Short answer: Brent’s cycle algorithm finds a cycle in a sequence x, f(x), f(f(x)), … with constant memory. A hare walks alone. Whenever the distance since the last reset is a power of two, the tortoise jumps to the hare and the search length doubles. When the hare lands…
How breadth-first search measures unweighted distance
Short answer: Breadth-first search expands a graph level by level from a source, using a queue. The first time a vertex is reached, the path that reached it is a shortest path in an unweighted graph, or in a graph whose edges all have the same positive cost. The…
How Brandes accumulates betweenness
Short answer: Brandes’ algorithm computes betweenness centrality. For every source it builds a shortest-path DAG, counts the number of shortest paths σ through each vertex, and walks that DAG backward to add dependencies. One source costs a BFS, or a Dijkstra run when weights are nonnegative. All sources cost…
How Boyer-Moore skips with the bad-character rule
Short answer: Boyer-Moore aligns the pattern with the text and compares from the right end of the pattern. The bad-character rule shifts so that the mismatched text character lines up with its rightmost occurrence in the pattern, or shifts past the pattern if the character does not occur. The…
How Boruvka merges components by their cheapest edge
Short answer: Borůvka’s algorithm contracts many pieces of a minimum spanning tree at once. In each round every component marks a cheapest edge that leaves it, and all of those edges are added together. The number of components at least halves, so there are O(log V) rounds and the…
How bitap matches a pattern with word shifts
Short answer: Bitap, or the Shift-Or algorithm, matches a pattern by keeping a bitset of the pattern prefixes that match the text so far. Each text character shifts the set and masks it with the character’s precomputed bit mask. A match is the bit at the pattern’s last position.…
How binary search maintains a half-open range
Short answer: Binary search keeps the invariant that a missing or matching key, if it is present, lies in a half-open index range [lo, hi). The midpoint is lo + (hi−lo)//2, which does not overflow when lo and hi are large. The loop that sets hi = mid when…
