Short answer: Interpolation search probes a sorted numeric array at the index the target would occupy if the keys between the ends were evenly spaced. Under independent uniform keys the expected number of probes is O(log log n). On a skewed distribution the same formula walks the array almost…
Category: Algorithms
How insertion sort charges one move per inversion
Short answer: Insertion sort grows a sorted prefix by sliding the next item left until it sits in order. Each slide removes one inversion, so the number of moves equals the inversion count. Sorted input is Θ(n). Reversed input is Θ(n²). The sort is stable and in place, and…
How IDA* deepens an f-cost bound
Short answer: IDA* applies iterative deepening to A*. Each pass is a depth-first search that refuses to step onto a vertex whose f = g + h exceeds the current bound. The next bound is the smallest f that was blocked. With an admissible heuristic, the first time the…
How HyperLogLog estimates a cardinality
Short answer: HyperLogLog estimates the number of distinct items in a stream from the position of the first 1-bit in each item’s hash. Items are bucketed by the first p bits of the hash, into m = 2^p registers. Each register stores the maximum number of leading zeros, plus…
How Huffman coding merges the two lightest trees
Short answer: Huffman coding builds a prefix-free binary code by repeatedly merging the two lowest-frequency symbols, or trees, into a parent whose frequency is their sum. One child edge is bit 0 and the other is bit 1. The code for a symbol is the path from the root.…
How Hopcroft-Karp phases bipartite matching
Short answer: Hopcroft-Karp computes a maximum matching in a bipartite graph in phases. Each phase breadth-first searches for the shortest augmenting paths and then depth-first searches a maximal set of vertex-disjoint paths of that length. The matching grows by all of them at once. There are O(√V) phases and…
How HITS scores hubs and authorities
Short answer: HITS gives every page two scores. The authority score is the sum of the hub scores of pages that link to it. The hub score is the sum of the authority scores of pages it links to. Iterating those two sums and normalizing is power iteration on…
How Hierholzer builds an Eulerian circuit
Short answer: Hierholzer’s algorithm builds a closed walk that uses every edge exactly once. An undirected graph has such a circuit when it is connected aside from isolated vertices and every degree is even. The algorithm walks unused edges until it returns, then splices in a side tour at…
How Held-Karp holds one subset per tour
Short answer: The Held-Karp algorithm solves the traveling salesman problem on n cities by dynamic programming over subsets. The cell dp[S][v] is the minimum cost of a path that starts at city 0, visits each city in the subset S exactly once, and ends at v. Each cell tries…
How heapsort sorts in place in n log n
Short answer: Heapsort turns the array into a binary max-heap, then repeatedly swaps the root with the last unsorted item and sifts the hole down. Building the heap is Θ(n). The n extractions are Θ(n log n) in the worst case. Extra memory is a few indices. The sort…
How gradient descent steps against the gradient
Short answer: Gradient descent minimizes a differentiable function by repeating x ← x − η∇f(x). The gradient is the direction of steepest increase, so the minus sign descends. A step size η that is too large diverges. A step size that is too small crawls. On a convex function…
How GJK tests two convex shapes for overlap
Short answer: The Gilbert-Johnson-Keerthi algorithm decides whether two convex sets intersect by chasing a simplex inside their Minkowski difference. The difference contains the origin exactly when the shapes touch or overlap. Each iteration asks a support function for the farthest point in a chosen direction, adds that point to…
How Gaussian elimination reaches row echelon form
Short answer: Gaussian elimination reduces a matrix to row echelon form by clearing each column under a pivot. Partial pivoting swaps into the pivot row the remaining row with the largest absolute value in that column. With that swap, the algorithm is the standard numerically stable solver for a…
How Gale-Shapley builds a stable matching
Short answer: The Gale-Shapley deferred-acceptance algorithm builds a stable matching of two sides that have ranked each other. One side proposes, in preference order, and the other side keeps the better proposal so far and rejects the rest. A rejected proposer asks the next choice. The result is a…
How fractional knapsack packs by value density
Short answer: The fractional knapsack problem allows any fraction of an item. Sort by value per unit weight and take items from the densest until the next item does not fit. Fill the remaining capacity with a fraction of that item. The greedy choice is optimal for the fractional…
How Fortune’s algorithm sweeps a Voronoi diagram
Short answer: Fortune’s algorithm computes the Voronoi diagram of a planar point set by sweeping a horizontal line downward and maintaining a beach line of parabolic arcs. Each site above the sweep line owns the points closer to it than to the sweep line, and the boundary of those…
How Ford-Fulkerson augments residual paths
Short answer: Ford-Fulkerson sends flow along any path from source to sink in the residual graph, then updates residual capacities in both directions. A residual edge backward carries the option to undo flow. When no residual path remains, the flow is maximum, and the reachable set from the source…
How Floyd’s cycle algorithm meets a tortoise and a hare
Short answer: Floyd’s cycle-finding algorithm detects a cycle in a sequence defined by x, f(x), f(f(x)), … with two pointers and no stored history. The tortoise advances one step and the hare two. If there is a cycle, they meet. The meeting point is then used to find the…
