GraphTheory
SpanningTree
Calling Sequence
Parameters
Description
Examples
SpanningTree(G)
SpanningTree(G, r)
G
-
undirected graph
r
vertex of the graph
The SpanningTree command returns a spanning tree of G, a subgraph that contains all the vertices and is a tree. Edge weights are ignored.
To compute a minimal-weight spanning tree for a weighted graph, use MinimalSpanningTree.
with⁡GraphTheory:
with⁡SpecialGraphs:
P≔PetersenGraph⁡
P≔Graph 1: an undirected unweighted graph with 10 vertices and 15 edge(s)
T1≔SpanningTree⁡P
T1≔Graph 2: an undirected unweighted graph with 10 vertices and 9 edge(s)
IsTree⁡T1
true
DrawGraph⁡P
DrawGraph⁡T1
T2≔SpanningTree⁡P,5:
Edges⁡T1
1,2,1,5,1,6,2,3,2,9,4,5,5,8,6,7,6,10
Edges⁡T2
1,2,1,5,1,6,3,4,4,5,4,10,5,8,7,8,8,9
See Also
IsTree
MinimalSpanningTree
NumberOfSpanningTrees
TreeHeight
Download Help Document
What kind of issue would you like to report? (Optional)