liveBook · Manning

Minimum spanning tree

As explained in Classic Computer Science Problems in Swift: Essential techniques for practicing programmers

A minimum spanning tree is a spanning tree of a weighted graph whose total edge weight is minimal among all spanning trees of that graph.

A minimum spanning tree connects every vertex in a connected weighted graph while minimizing total edge weight. It is a tree, so it contains no cycles and exactly one path connects any two vertices. The practical goal is to connect a network at minimum cost. section 4.3

Connecting major metropolitan areas

A weighted graph of 15 U.S. metropolitan areas uses distances as edge weights. The resulting tree includes Seattle–San Francisco, Los Angeles–Riverside, and Dallas–Houston, connects all 15 areas, and has total weight 5,372.

How Classic Computer Science Problems in Swift: Essential techniques for practicing programmers covers it

How deep it goes
Defines trees, cycles, connected graphs, and spanning trees, then implements Prim's algorithm with a priority queue.
Examples
Uses a 15-city distance graph, printed adjacency lists, selected MST edges, and a total weight of 5,372.
What it assumes
Assumes graph familiarity enough to use vertices and edges, while defining trees, cycles, connected graphs, and spanning trees.
What you can do after
Apply it via Swift by constructing a weighted graph and calling mst(start:) to obtain selected edges.
How it connects
Connects weighted graphs, spanning trees, cycles, priority queues, adjacency lists, and Prim's algorithm.

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 Classic Computer Science Problems in Swift: Essential techniques for practicing programmers. The section links point to the parts of the book it draws on.