FindSpanningTree

FindSpanningTree[{v1,v2,,vn}]

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

FindSpanningTree[g]

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

FindSpanningTree[{g,v},]

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

FindSpanningTree[{vw,},]

uses rules vw to specify the graph g.

Details and Options

  • FindSpanningTree is also known as minimum spanning tree and spanning forest.
  • Typically used to find optimal connections without cycles.
  • FindSpanningTree[{v1,,vn}] gives a spanning tree of the complete graph with vertices v1,,vn that minimizes the total distance between the vi.
  • A spanning tree of a connected graph g is a subgraph of g that is a tree and connects all vertices of g.
  • For weighted graphs, FindSpanningTree gives a spanning tree with minimum sum of edge weights.
  • For disconnected graphs, FindSpanningTree gives a subgraph that consists of a spanning tree for each of its connected components.
  • FindSpanningTree has the same options as Graph, with the following additions and changes:
  • DistanceFunctionAutomaticfunction to apply to pairs of objects
    MethodAutomaticmethod to use
  • The Automatic setting for DistanceFunction includes the following choices:
  • EuclideanDistancenumbers of lists of numbers
    EditDistancestrings
    GeoDistancegeo positions
  • For a graph g, the distance is taken to be GraphDistance.
  • Possible settings for Method include:
  • "Kruskal"support sparse undirected graphs
    "MinimumCostArborescence"support directed graphs
    "Prim"support dense undirected graphs
  • The default setting of Automatic switches among these methods depending on the graph given.

Examples

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:

Multigraphs:

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)

Use TreeGraph to construct the spanning tree graph:

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, https://reference.wolfram.com/language/ref/FindSpanningTree.html (updated 2021).

Text

Wolfram Research (2014), FindSpanningTree, Wolfram Language function, https://reference.wolfram.com/language/ref/FindSpanningTree.html (updated 2021).

BibTeX

@misc{reference.wolfram_2021_findspanningtree, author="Wolfram Research", title="{FindSpanningTree}", year="2021", howpublished="\url{https://reference.wolfram.com/language/ref/FindSpanningTree.html}", note=[Accessed: 12-June-2021 ]}

BibLaTeX

@online{reference.wolfram_2021_findspanningtree, organization={Wolfram Research}, title={FindSpanningTree}, year={2021}, url={https://reference.wolfram.com/language/ref/FindSpanningTree.html}, note=[Accessed: 12-June-2021 ]}

CMS

Wolfram Language. 2014. "FindSpanningTree." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2021. https://reference.wolfram.com/language/ref/FindSpanningTree.html.

APA

Wolfram Language. (2014). FindSpanningTree. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/FindSpanningTree.html