Short answer: Edmonds’ blossom algorithm finds a maximum matching in a general undirected graph. It searches for an alternating path and, when that search closes an odd cycle, shrinks the cycle into a blossom. The shrunken graph has an augmenting path exactly when the original graph has one. Expanding…
Category: Algorithms
How the banker’s algorithm tests a safe state
Short answer: The banker’s algorithm avoids deadlock by refusing a resource request that would leave the system in an unsafe state. A state is safe when there exists an order of the processes such that each one can obtain its declared maximum with the resources free at its turn,…
How the AKS test proves primality in polynomial time
Short answer: The AKS primality test decides whether an integer n is prime in time polynomial in the number of bits of n. It generalizes the observation that n is prime exactly when (x−1)^n ≡ x^n − 1 (mod n) as a polynomial, and it checks a related congruence…
How ternary search narrows a unimodal function
Short answer: Ternary search finds the minimum of a unimodal function by comparing the function at the one-third and two-third points and discarding the third that cannot hold the minimum. Each step keeps 2/3 of the interval, so the number of evaluations is Θ(log n), with two evaluations per…
How Tarjan finds strongly connected components
Short answer: Tarjan’s strongly connected components algorithm is one depth-first search. Each vertex carries a discovery index and a low-link, the smallest index reachable from its subtree by tree edges and at most one back edge. Vertices sit on a stack until their component is emitted. When a vertex’s…
How Tarjan finds bridges and articulation points
Short answer: A bridge of an undirected graph is an edge whose removal increases the number of connected components. An articulation point is a vertex with the same effect. One depth-first search computes a discovery time and a low value, the oldest discovery time reachable from the subtree by…
How Tarjan answers LCA queries offline
Short answer: Tarjan’s offline LCA answers a batch of lowest-common-ancestor queries during one depth-first search, using union-find. When the search finishes a node, the node is united with its parent and the parent’s set is labeled with the parent. A query between the finished node and a node already…
How successive shortest paths price a min-cost flow
Short answer: Successive shortest paths compute a minimum-cost maximum flow, or a flow of a demanded value. Each augmentation is a cheapest path in the residual graph under edge costs, with backward edges carrying the negated cost. Potentials from those distances reprice the edges so the next search sees…
How Strassen multiplies matrices with seven products
Short answer: Strassen’s algorithm multiplies two n by n matrices with seven recursive multiplications of n/2 by n/2 matrices instead of eight. A constant number of additions recombines those seven products into the four blocks of the result. The recurrence solves to O(n^{log₂ 7}), about O(n^2.807), against the classical…
How Stoer-Wagner finds a global min-cut
Short answer: Stoer-Wagner computes a global minimum cut of an undirected weighted graph deterministically. Each phase grows a set like Prim, always adding the vertex most tightly connected to the set. The cut that separates the last vertex of the phase from the rest is a candidate. The phase…
How square-root decomposition sums a range by blocks
Short answer: Square-root decomposition breaks an array into contiguous blocks of length about √n. Each block stores the sum of its cells. A point update changes one cell and one block sum. A range sum adds the complete blocks in the middle and walks the loose cells at each…
How SPFA queues Bellman-Ford relaxations
Short answer: SPFA is the queue form of Bellman-Ford. A vertex enters the queue when its distance improves, and it relaxes its outgoing edges when it leaves. A vertex already in the queue is not inserted twice. The worst case is still Θ(VE), and there are families of graphs…
How smoothsort adapts a heap to sorted input
Short answer: Smoothsort keeps the unsorted prefix as a forest of implicit heaps whose sizes are Leonardo numbers, then peels maxima from the right. Sorted input costs Θ(n). Every input costs O(n log n). The sort is in place and unstable. Dijkstra designed it so a heap sort would…
How Smith-Waterman aligns two sequences locally
Short answer: Smith-Waterman finds the best local alignment: the highest-scoring pair of substrings under a substitution matrix and a gap penalty. The recurrence is Needleman-Wunsch with one extra choice. A cell may be 0, which means “start a new alignment here.” The answer is the maximum cell anywhere in…
How simulated annealing accepts an uphill move
Short answer: Simulated annealing searches a rough cost surface by proposing a neighbor of the current state and accepting it when the cost falls. When the cost rises by Δ, the move is accepted with probability e^{−Δ/T}. The temperature T decreases on a schedule. High T accepts uphill moves…
How Shellsort chooses a gap sequence
Short answer: Shellsort insertion-sorts the array at a descending sequence of gaps and finishes with gap 1. An h-sorted array stays h-sorted when a later pass uses a smaller gap. The worst-case bound is a property of the gap sequence: Shell’s original halving sequence is Θ(n²), Hibbard’s 2^k−1 sequence…
How Shannon-Fano splits symbols by weight
Short answer: Shannon-Fano coding builds a prefix code by sorting symbols by probability and splitting the list into two groups whose total probabilities are as equal as possible. One group gets a leading 0 and the other a leading 1. Each group is split the same way until every…
How selection sort bounds the number of writes
Short answer: Selection sort scans the unsorted suffix for its minimum and swaps that minimum into the next output slot. The comparison count is always Θ(n²). The write count is Θ(n) swaps, one per output slot. Use it when each write is expensive and the array is short enough…
