At weight , column is considered just after horizontal row . At this point its first graph vertices already lie in the component built so far, while graph vertices above them in that column are isolated. Consequently vertical edges with create a graph cycle, while those with attach the isolated graph vertices in a chain:Together with the horizontal rule this gives an induction on the alternating row and column stages and justifies the component description used in both numbered answers. The vertical contribution to the minimum spanning tree cost is
For a finite connected graph, a spanning tree contains every graph vertex and is connected and acyclic. A minimum spanning tree minimizes over all such trees. A shortest-path tree rooted at is a spanning tree whose unique -to- graph path has length for every graph vertex . Here the weighted path length is the sum of its edge weights. The two optimizations generally differ, as (b) shows. Connectedness is needed for either spanning-tree object to exist.
For the grid, Kruskal's algorithm examines edges in nondecreasing order of weight and accepts an edge exactly when it joins two different components of the current forest. The weights are encountered in the orderThe horizontal and vertical acceptance rules are detailed in the two numbered subanswers. Together they produceThere are horizontal and vertical edges, totaling . Every accepted edge attaches a previously isolated graph vertex to the component already built, so the result is connected and acyclic. The correctness theorem for Kruskal's algorithm, which follows from the minimum spanning tree cut property, proves minimality. Its total cost isFor the tree has one graph vertex, no edges and cost zero. The source's numbered items specify the two edge types; the following subanswers record their contributions to the algorithm.
Kruskal spanning tree of the weighted grid, with accepted horizontal and vertical edges highlighted
. Details. Use a triangle with graph vertices and edge weightsIts unique minimum spanning tree is , of cost , because the other two spanning-tree costs are . In this tree the -to- graph path has length , whereas the edge gives length in the original graph. ThereforeSince the minimum spanning tree is unique, none is a shortest-path tree rooted at .
Let be the unique minimum spanning tree. If is an edge outside , adding it creates a unique graph cycle consisting of and the tree graph path . Every edge on that graph path has : otherwise the distinct weights would give , and replacing by would produce a cheaper spanning tree. This is the minimum spanning tree cycle property in exchange form.
By the domination inequality in (i), it follows more strongly thatNow consider any simple graph path from to that is not the tree graph path. It must use an edge outside . Replace every such edge by the corresponding tree graph path. Each replacement strictly reduces length and produces a walk entirely in . Removing any repeated-vertex excursions leaves the unique tree graph path and can only reduce length further. ThereforeSo every root-to-vertex graph path in is the unique shortest graph path in , andThe argument works for every choice of root .
Take a minimum spanning tree , for example one constructed by Kruskal's algorithm. Fix and let be a longest edge of the tree's unique path. Deleting partitions into two components separating and . Any alternative path crosses this graph cut. If all of its edges were shorter than , a crossing edge would let us replace by , producing a spanning tree of smaller total length. This contradicts minimality of .
Therefore every competing path has an edge at least as long as , and the tree path solves the bottleneck shortest path problem. The same minimum spanning tree works simultaneously for every ; this is the minimax path property of a minimum spanning tree.
To find a minimum-weight acyclic subgraph, filter to the subgraph containing only strictly negative-weight edges, and run Kruskal's algorithm on those edges, accepting an edge exactly when it joins different current components. Return the resulting forest, with any omitted vertices regarded as isolated. Zero-weight edges may be omitted without worsening the objective.
To prove correctness, first remove all nonnegative edges from any feasible acyclic graph; removing them preserves acyclicity and cannot increase weight. Thus an optimum using only negative edges exists. Inside a connected component of , any forest not yet connected can be extended by a negative crossing edge: some such edge exists because the original component is connected. Adding it preserves acyclicity and strictly reduces total weight. Consequently an optimum must span each component of , and its restriction there must be a minimum spanning tree. Kruskal's algorithm finds exactly the resulting minimum spanning forest of . This proves optimality among all acyclic subgraphs, including disconnected ones.
Assume the graph is connected so that a minimum spanning tree exists, and let be the output of Kruskal's algorithm. With distinct weights there is a strict total edge ordering. Suppose another minimum spanning tree existed. Choose and increase only by a positive so small that the strict ordering of all edge weights remains unchanged. For a finite graph such an exists, using less than the gap to the next larger weight; if is largest, any sufficiently small positive increase works.
Running Kruskal's algorithm again examines exactly the same order and makes exactly the same component decisions. It therefore still returns , which must remain optimal for the perturbed weights. But has become more expensive by , while is unchanged. They had equal original weight, so now is cheaper, a contradiction. This proves that distinct weights imply a unique minimum spanning tree.
The converse is false. A triangle with edge weights has a unique minimum spanning tree, consisting of its two weight-one edges. Its total is , while either other spanning tree has total . Thus equal edge weights permit, but do not force, multiple optimum trees. The same perturbation proof applies componentwise to a minimum spanning forest.
The minimum spanning tree cut property says: if a cut of a graph respects an edge set contained in some minimum spanning tree, a minimum-weight edge across that cut is safe to add to , meaning that some minimum spanning tree contains together with that edge. Respecting means no edge of crosses the cut. In particular, any lightest cut edge belongs to some minimum spanning tree; a uniquely lightest cut edge belongs to every minimum spanning tree.
For the exchange argument, take a minimum spanning tree containing . If it lacks the chosen edge , add to create its fundamental cycle. The remaining route between 's endpoints crosses the cut at some edge , with . Since the cut respects , . Replacing by preserves a spanning tree, retains , and cannot increase weight. Hence it is also minimum. Strict inequality would contradict minimality, which gives the unique-lightest assertion.
For an illustration, take a triangle with weights , , . Across the cut , is the unique lightest edge and must be in every minimum spanning tree. The minimum tree is , of weight . With tied light edges, the existence assertion need not mean that every minimum spanning tree contains the particular tied edge chosen.
Write each undirected edge with its smaller endpoint first. Kruskal's algorithm orders candidates first by weight and then lexicographically:Thus the requested addition order isand the minimum spanning tree has total weight . Five accepted edges connect all six vertices, so the remaining weight-four edges need not be scanned.
Prim's algorithm 2026-10-14
Start from one graph vertex. Repeatedly add the least-weight edge joining the reached graph vertices to an unreached graph vertex. Each step grows a tree and obeys the minimum spanning tree cut property. On a finite connected graph, the result is a minimum spanning tree.
Reverse-delete algorithm Created 2026-10-14 Updated 2026-10-25
Process edges in decreasing weight and delete an edge whenever the remaining graph stays connected. Previously retained heavier edges are bridges in a graph and remain so under deletion. Thus a deletable edge is heaviest on a current graph cycle, and the minimum spanning tree cycle property excludes it from every minimum spanning tree. At termination the surviving connected graph has no graph cycle, so it is a minimum spanning tree.
Shortest-path tree 2026-10-25
A shortest-path tree rooted at a source vertex is a spanning tree whose unique tree route from the source to every vertex solves the shortest path problem in the original weighted graph. Dijkstra's algorithm constructs one for a finite connected graph with nonnegative edge lengths, recording a predecessor whenever a distance improves. It need not be a minimum spanning tree: one minimizes each source-route length, the other the total weight of the tree's edges.
Spanning tree Created 2026-09-24 Updated 2026-10-14
A spanning tree of a connected graph is a subgraph that is a tree and contains every vertex of . Its edges must come from . For finite on vertices, every spanning tree has edges, the minimum possible number preserving reachability between all locations. This makes a spanning tree a compact certificate that the original graph is connected. A minimum spanning tree additionally minimizes a specified total edge weight; merely selecting a spanning tree supplies no such optimization. [ref]
Let be our seven-vertex tree with edge added. It has seven edges and a graph cycle. Removing gives the original spanning tree ; removing instead gives another spanning tree . Both retain all seven vertices and six edges, but their graph distances differ: , whereas . In , but , along , compared with . Preserving reachability permits longer journeys; breadth-first search can preserve graph distances from one chosen starting vertex.
To construct a spanning tree, repeatedly delete any edge on a graph cycle. Its endpoints remain joined through the rest of that graph cycle, so the deletion preserves connectedness. Finiteness ensures that this stops at a connected acyclic graph. Conversely, adding an omitted edge to a spanning tree creates its unique fundamental cycle; deleting any other edge on that graph cycle produces another spanning tree. The displayed exchange replaces by . [ref]
https://www.maths.tcd.ie/~dwilkins/Courses/MA2C03/MA2C03Courseware_2014to15/MA2C03_S4_Yr1415.pdf. Trinity College Dublin, section 4.16: deleting cycle edges preserves connectivity
Superincreasing sequence 2026-10-25
A positive sequence is superincreasing if each term exceeds the sum of all earlier terms. If , a geometric series proves . Distinct finite subsets of its indices have distinct sums: cancel their common terms and compare the largest remaining term with the sum of all smaller terms. This gives uniqueness of minimum spanning trees and of simple graph paths with fixed endpoints when a finite weighted graph has such separated edge weights.

