liveBook · Manning

Kruskal's algorithm

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

A minimum-spanning-tree algorithm that processes edges in increasing weight order and adds edges that extend the growing forest without creating a cycle.

Kruskal's algorithm builds a minimum spanning tree (MST) for an undirected, connected, weighted graph. It sorts edges from smallest to largest and repeatedly adds the next edge unless that edge creates a cycle. The result connects every vertex without loops while minimizing the total edge weight. section 4.2 section 4.5

The muddy city problem

Treat road lengths as edge weights and repair only the roads needed to connect every location. Choose E-H with length 1 first; then select the length-2 edges that do not create cycles. Among length-3 edges, reject C-F and F-J because they close cycles, while accepting A-D, D-E, and G-I. Reject A-E at length 4 for the same reason, then finish with G-H. Arbitrary choices are possible when edges have equal weights. section 4.2

A Python implementation can use NetworkX to test connectivity and cycles, then visualize the selected MST by highlighting its edges. The same approach scales to a road network: an OSMnx graph of the University of Toronto area is converted to an undirected graph, its edges are sorted by length, and the MST edges are highlighted. section 4.2

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

How deep it goes
Explains definitions, pseudocode, cycle decisions, and worked iterations, but does not develop formal proofs or complexity analysis.
Examples
Uses the muddy city road network, NetworkX visualizations, and a University of Toronto road graph sorted by edge length.
What it assumes
Assumes vertices, edges, weights, connectivity, spanning trees, and cycles; defines MST properties before applying the algorithm.
What you can do after
Apply it via NetworkX to construct, inspect, and visualize a minimum spanning tree from a weighted graph.
How it connects
Connects minimum spanning trees with spanning trees, greedy algorithms, informed search, Borůvka's algorithm, and Jarník-Prim's algorithm.

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.