Short answer: Floyd-Warshall computes the shortest path between every pair by allowing intermediate vertices in order. After step k, dist[i][j] is the best path that uses only intermediates among the first k vertices. The triple loop is Θ(V³) time and Θ(V²) memory. Negative edges are allowed. A negative value…
Author: HoHo Zhao
How Fleury avoids burning a bridge early
Short answer: Fleury’s algorithm builds an Eulerian tour by a walking rule: from the current vertex, take an edge that is not a bridge of the remaining graph, unless every remaining edge is a bridge. The rule keeps the unused edges in one connected piece until they are consumed.…
How Fisher-Yates shuffles with one swap per index
Short answer: The Fisher-Yates shuffle, in the modern inside-out or the usual in-place form, produces each permutation of an array with equal probability. The in-place loop walks i from the end down to 1 and swaps i with a uniformly chosen index j in 0..i, inclusive. That is n−1…
How Fibonacci search splits on Fibonacci sizes
Short answer: Fibonacci search probes a sorted array on boundaries taken from the Fibonacci sequence, so each remaining window has a Fibonacci length and the next window is the previous Fibonacci number. The comparison count is O(log n), the same order as binary search. Index arithmetic uses addition and…
How external mergesort sorts beyond memory
Short answer: External mergesort sorts runs that fit in memory, writes them out, and merges them k at a time. With R runs and a k-way merge, the number of full passes over the file is ⌈log_k R⌉. Replacement selection with a heap of M records produces runs whose…
How exponential search brackets a nearby key
Short answer: Exponential search probes a sorted array at indices 1, 2, 4, 8, and so on, until the key at the probe is at least the target or the array ends. It then binary-searches the bracket that contains the answer. If the target sits at position p, the…
How expectation-maximization alternates two steps
Short answer: Expectation-maximization fits a probabilistic model with latent variables by alternating two steps. The E-step computes the posterior of the latent variables given the current parameters. The M-step maximizes the expected complete-data log-likelihood under that posterior, which for many models is a weighted closed-form update. Each full iteration…
How Edmonds-Karp bounds augmentations with BFS
Short answer: Edmonds-Karp is Ford-Fulkerson with one restriction: the augmenting path is a shortest residual path, measured by number of edges, so the search is breadth-first. Each augmentation can be found in O(E), and the number of augmentations is O(VE), for a total of O(VE²). The bound is polynomial…
How Edmonds finds a minimum arborescence
Short answer: Edmonds’ branching algorithm, also called Chu-Liu/Edmonds, finds a minimum-cost spanning arborescence of a directed graph: a directed tree in which every vertex except the root has in-degree one and every vertex is reachable from the root. Each vertex selects its cheapest incoming edge. If those edges form…
How earliest deadline first schedules one processor
Short answer: Earliest deadline first schedules a single processor by always running the ready job whose absolute deadline is soonest. For periodic implicit-deadline tasks, the schedule meets every deadline if and only if the total utilization is at most 1. The test is necessary and sufficient on one preemptive…
How Earley’s algorithm parses a general grammar
Short answer: Earley’s algorithm parses a context-free grammar in O(n³) time for an input of length n, O(n²) when the grammar is unambiguous, and O(n) for many deterministic grammars. It keeps a chart of items, each a grammar rule with a dot and an origin index. Prediction adds rules…
How Dinic blocks a level graph
Short answer: Dinic’s algorithm repeats two steps. Breadth-first search assigns a level, the residual distance from the source, and discards every edge that does not advance exactly one level. Depth-first search then pushes a blocking flow: every residual source-sink path in that level graph is saturated. The level of…
How Dijkstra grows a settled shortest-path tree
Short answer: Dijkstra’s algorithm grows a set of settled vertices whose distances from the source are final. The next vertex settled is the unsettled vertex with the smallest tentative distance, and its outgoing edges relax their heads. With a binary heap the time is O((V+E) log V) on nonnegative…
How Diffie-Hellman agrees on a shared secret
Short answer: Diffie-Hellman lets two parties derive the same secret from a public generator. They agree on a group. Each party samples a secret exponent, sends the generator raised to that exponent, and raises the value it receives to its own exponent. Both compute g raised to the product…
How Dial’s algorithm buckets integer distances
Short answer: Dial’s algorithm is Dijkstra for nonnegative integer weights whose maximum is C. It keeps a bucket for each possible distance. Because an edge increases distance by at most C, a circular array of C+1 buckets holds the whole frontier. Scanning buckets in order and relaxing edges is…
How depth-first search records discovery and finish
Short answer: Depth-first search follows an edge as far as it can, then backtracks, using a stack or the call stack. Each vertex receives a discovery time and a finish time. Those times classify every edge as tree, back, forward, or cross, and the finish order is the input…
How DBSCAN grows a density cluster
Short answer: DBSCAN grows clusters from core points. A core point has at least minPts points, including itself, inside radius ε. A cluster is a core point plus every point density-reachable from it through a chain of cores. Points that are within ε of a cluster and are not…
How cycle sort writes each item to its final index
Short answer: Cycle sort follows the cycle that a permutation forms and writes each misplaced item directly to the index its rank names. Items already in place are left untouched. The comparison count stays Θ(n²), because each rank is computed by scanning. The point of the algorithm is the…
