liveBook · Manning

Spanning tree

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

A spanning tree is a tree that includes every vertex of a graph.

A spanning tree is a tree that connects every vertex in a graph. Because a tree has exactly one path between any two vertices, it contains no cycles; pruning suitable edges can turn a graph into one. section 4.3

In a weighted graph, the related minimum-spanning-tree problem asks for:

  • A set of edges touching every vertex. section 4.3
  • The smallest possible combined edge weight among spanning trees. section 4.3
  • A practical minimum-cost connection for transportation or computer networks. section 4.3

Connecting cities

A weighted graph of 15 United States metropolitan areas uses distances as edge weights. Prim’s algorithm selects connecting edges to produce a spanning tree with 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, connectivity, and minimum spanning trees, then demonstrates an implementation with Prim’s algorithm.
Examples
Uses a cycle-pruning diagram and a weighted graph connecting 15 United States metropolitan areas.
What it assumes
Assumes graph representation and weighted edges, while defining trees, cycles, connectivity, and spanning trees explicitly.
What you can do after
Builds a minimum spanning tree in Swift using a weighted graph, visited vertices, and an ascending priority queue.
How it connects
Connects spanning trees with graphs, cycles, weighted graphs, minimum spanning trees, priority queues, and Prim’s algorithm.

Also explained in

Compare how 2 books explain 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.