finds a spanning tree that minimizes the total distance between the vi.


finds a spanning tree of the graph g that minimizes the total distances between vertices.


finds a spanning tree of the connected component of g that includes the vertex v.


uses rules vw to specify the graph g.

Details and Options


open allclose all

Basic Examples  (1)

Find a minimum spanning tree in a graph:

Highlight the spanning tree:

Scope  (10)

FindSpanningTree works with a list of points:

A list of strings:

A list of geodetic positions:

FindSpanningTree works with undirected graphs:

Directed graphs:

Weighted graphs:


Find a minimum spanning tree with a start root:

Use rules to specify the graph:

FindSpanningTree works with large graphs:

Generalizations & Extensions  (1)

Find a maximum spanning tree:

Options  (5)

EdgeWeight  (1)

By default, the edge weight is taken to be its EdgeWeight annotation if available, and otherwise 1:

Use EdgeWeight->weights to set the edge weight:

Method  (4)

The method is automatically chosen depending on input:

"Prim" can be used for undirected dense graphs:

"Kruskal" can be used for undirected sparse graphs:

"MinimumCostArborescence" can be used for directed graphs:

Applications  (7)

A company is planning a fiber network for a number of Chicago suburbs. It only has the right of way for its fiber along certain corridors. Some of those corridors might be more expensive. Find the subgraph of connection corridors that connect every suburb with the lowest total cost:

The phone company task is to provide phone lines to a village with 10 houses. Each node is a house and each house has a location. Find a way to wire up all houses using the least telephone wiring:

The resulting total length for the phone lines:

A two-dimensional array such that the rows have similar entries and differ only at a few places. denotes the number of different entries in row and . The array can be stored by representing one full row and all other rows as the entries that differ from another row. Each matrix row can be modeled as a vertex, with an edge to every other and a weight of that represents the number of entries that differ. Use a minimal-weight spanning tree to find an efficient storage scheme:

Store row 1 completely, and for the remaining rows store only the positions and entries where the row differs from its parent:

Build an interstate highway system joining the geographical centers of all African countries:

Minimize the total distances between all countries:

Show the highways:

Generate mazes from a grid graph with random weights:

A minimum spanning tree:

Custom styling for mazes:

Maze graph:

Find the expected size of minimal spanning trees for complete graphs with uniform random weights:

Size of a spanning tree is given as a sum of edge weights for the spanning tree:

For large complete graphs, the expected size approaches TemplateBox[{3}, Zeta]:

Find a minimal spanning tree for visiting Europe countries:

Visualize the path between countries:

Properties & Relations  (2)

The spanning tree graph is a tree:

BreadthFirstScan can be used to find a spanning tree of a graph:

Find a spanning tree using DepthFirstScan:

Possible Issues  (1)

Disconnected graphs give a spanning tree for each of their connected components:

Highlight the spanning trees:

Neat Examples  (1)

Minimum spanning tree of a random graph with vertices uniformly distributed on the sphere:

Wolfram Research (2014), FindSpanningTree, Wolfram Language function, (updated 2021).


Wolfram Research (2014), FindSpanningTree, Wolfram Language function, (updated 2021).


Wolfram Language. 2014. "FindSpanningTree." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2021.


Wolfram Language. (2014). FindSpanningTree. Wolfram Language & System Documentation Center. Retrieved from


@misc{reference.wolfram_2024_findspanningtree, author="Wolfram Research", title="{FindSpanningTree}", year="2021", howpublished="\url{}", note=[Accessed: 12-July-2024 ]}


@online{reference.wolfram_2024_findspanningtree, organization={Wolfram Research}, title={FindSpanningTree}, year={2021}, url={}, note=[Accessed: 12-July-2024 ]}