Short answer: Union-find maintains a partition of elements under union and under “are these two in the same set.” Each set is a tree of parent pointers. Union by rank attaches the shorter tree under the taller one, and path compression points every node on a lookup path at…
Category: Graphs
How topological sort orders a directed acyclic graph
Short answer: Topological sort orders a directed graph so every edge points forward. Kahn’s algorithm peels vertices of indegree zero and reduces their successors’ indegrees. Depth-first search emits vertices in reverse order of finish time. Both run in Θ(V+E). If Kahn’s queue empties before every vertex is emitted, or…
How the Hungarian algorithm solves an assignment
Short answer: The Hungarian algorithm, or Kuhn-Munkres, solves the assignment problem: pair n agents with n jobs so that the sum of costs is minimum. It maintains dual variables on agents and jobs so that a reduced cost c(i, j) − u(i) − v(j) is never negative, and it…
How the blossom algorithm matches a general graph
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…
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 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 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 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 push-relabel moves preflow downhill
Short answer: Push-relabel maintains a preflow: every vertex except the source may hold excess, and no residual edge runs from a higher label to a lower one except when the algorithm is mid-push. A vertex with excess pushes flow along a residual edge to a neighbor labeled exactly one…
How Prim grows a minimum spanning tree from a cut
Short answer: Prim’s algorithm grows one tree. The lightest edge with one end in the tree and one end outside it is safe to add, by the cut property. A binary heap implements the fringe in O((V+E) log V). A Fibonacci heap improves the proof to O(E + V…
How PageRank iterates a damped link matrix
Short answer: PageRank assigns every page a score that is the stationary distribution of a random surfer. With probability d the surfer follows a link chosen uniformly among the page’s out-links. With probability 1−d the surfer jumps to a uniformly random page. The usual damping factor is 0.85. The…
How Kuhn matches by augmenting DFS
Short answer: Kuhn’s algorithm builds a bipartite matching by a depth-first search for one augmenting path at a time. Each free left vertex tries to find an alternating path to a free right vertex, flipping the matching if it succeeds. With a visited mark cleared every search, the time…
How Kruskal adds the cheapest safe edge
Short answer: Kruskal’s algorithm sorts the undirected edges by weight and adds an edge when its ends lie in different trees of a forest. A union-find structure answers that test. The sort dominates, at O(E log E), and the union-find work is essentially linear. The first |V|−1 accepted edges…
How Kosaraju uses a transpose graph
Short answer: Kosaraju’s algorithm finds strongly connected components with two depth-first searches. The first search records vertices in reverse order of finish time on the original graph. The second search runs on the transpose, in which every edge is reversed, and starts vertices in that recorded order. Each tree…
How Karger contracts a random min-cut
Short answer: Karger’s algorithm finds a global minimum cut of an undirected multigraph by randomly contracting edges until two supernodes remain. The edges between those two supernodes are a cut, and each run returns the minimum cut with probability at least 1/binom(n, 2), about 2/n². Repeating O(n² log n)…
How Johnson reweights edges and runs Dijkstra
Short answer: Johnson’s algorithm adds a super-source, runs Bellman-Ford to get potentials, and reweights every edge to w'(u,v) = w(u,v) + h(u) − h(v). The new weights are nonnegative, so Dijkstra from each vertex is legal. A path’s reweighted length differs from its true length by h(start) − h(end),…
How iterative deepening DFS saves the frontier
Short answer: Iterative deepening depth-first search runs a depth-limited depth-first search with limit 0, then 1, then 2, and so on, until the target is found. On an unweighted graph the first success is a shortest path. The space is O(d) for the current path, not O(b^d) for a…
