liveBook · Manning

Minimum spanning tree

As explained in Optimization Algorithms: AI techniques for design, planning, and control problems

An algorithm that finds a minimum-weight tree connecting every node of a connected weighted graph.

A minimum spanning tree (MST) connects every vertex in a connected, undirected, weighted graph with no cycles while minimizing the sum of its edge weights. It chooses a cost-effective connected structure rather than preserving every available edge. MST problems belong to informed search, where edge costs guide the search toward an optimal solution. section 4.1 section 4.2

Common MST strategies differ in how they grow or merge tree components:

  • Kruskal’s algorithm sorts edges by increasing weight, adds the next edge that does not create a cycle, and continues until the tree is complete. section 4.1 section 4.2
  • Jarník-Prim’s algorithm starts at a root and repeatedly adds the lowest-weight edge from the current MST to a non-MST vertex. section 4.1
  • Borůvka’s algorithm begins with one tree per vertex, selects the cheapest outgoing edge for each tree, and merges the resulting components; it also handles minimum spanning forests for disconnected graphs. section 4.1

Repairing a muddy city

Treat damaged roads as weighted edges, where weight represents repair or paving cost. Kruskal’s algorithm examines roads from cheapest to most expensive, keeps a road when it connects components without forming a loop, and produces a connected minimum-cost road network. The same workflow can be visualized on a toy graph or applied to a real street network near the University of Toronto. section 4.2

Algorithm 4.1 Kruskal’s algorithm
Input: Graph G = (V, E) with each edge e ∈ E having a weight w(e)
Output: A minimum spanning tree T
  
Create a new graph T:= ∅ with the same vertices as G, but with no edges.
Define a list S containing all the edges in the graph G
Sort the edges list S in ascending order of their weights.
For each edge e in the sorted list:
   If adding edge e to T does not form a cycle:
      Add this edge to T.
   Else:
      Skip this edge and move to the next edge in the list.
Continue this process until all the edges are processed.
Return T as the minimum spanning tree of graph G.

Follow the compact Kruskal procedure from graph input through edge sorting, cycle checks, and the returned tree. section 4.2

A practical Python workflow can construct a NetworkX graph, attach weights, compute the MST with Kruskal’s implementation, and highlight selected edges. Real street data can be loaded with OSMnx, converted to an undirected graph, and sorted by road length before computing the tree. section 4.2

How Optimization Algorithms: AI techniques for design, planning, and control problems covers it

How deep it goes
Defines spanning trees, compares three algorithms, works through Kruskal, and demonstrates Python implementation without formal proofs.
Examples
Uses the muddy city road-repair problem, toy graph figures, a NetworkX graph, and a University of Toronto street network.
What it assumes
Assumes basic graph terminology while defining vertices, edges, weights, connectivity, cycles, and spanning-tree requirements.
What you can do after
Apply it via NetworkX and OSMnx to compute, visualize, and inspect minimum spanning trees for toy or street-network graphs.
How it connects
Connects minimum spanning trees with informed search, shortest-path search, greedy algorithms, weighted graphs, and routing.

Also explained in

Compare how 2 books explain minimum spanning tree →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Optimization Algorithms: AI techniques for design, planning, and control problems. The section links point to the parts of the book it draws on.