networks
spantree
finds a minimum weight spanning tree
Calling Sequence
Parameters
Description
Examples
spantree(G)
spantree(G, s)
spantree(G, s, w)
G
-
graph or network
s
starting or root vertex for the tree
w
name for returning the sum of the edge weights in the tree
Important: The networks package has been deprecated.Use the superseding command GraphTheory[MinimalSpanningTree] instead.
This routine constructs a spanning tree for the graph G. The result is returned as a new graph derived from G and consisting of that spanning tree.
The chosen tree has edges which minimize the total edge weight of the tree.
The routine uses Prim's algorithm, which fails if G is not strongly connected.
The routine is normally loaded via the command with(networks) but may also be referenced using the full name networks[spantree](...).
Important:The networks package has been deprecated.Use the superseding command GraphTheory[MinimalSpanningTree] instead.
with⁡networks:
G≔petersen⁡:
ends⁡G
1,2,1,5,1,6,2,3,2,8,3,4,3,10,4,5,4,7,5,9,6,7,6,10,7,8,8,9,9,10
spantree⁡G,1,w
procxoptionGRAPH,2;ifx=_Edgesthenthisproc⁡_Edges ≔ elifx=_EdgeIndexthenthisproc⁡_EdgeIndex ≔ table⁡symmetricelifx=_Headthenthisproc⁡_Head ≔ table⁡elifx=_Tailthenthisproc⁡_Tail ≔ table⁡elifx=_Eweightthenthisproc⁡_Eweight ≔ table⁡elifx=_Endsthenthisproc⁡_Ends ≔ table⁡elifx=_Verticesthenthisproc⁡_Vertices ≔ elifx=_Vweightthenthisproc⁡_Vweight ≔ table⁡sparseelifx=_Ancestorthenthisproc⁡_Ancestor ≔ table⁡elifx=_Daughterthenthisproc⁡_Daughter ≔ table⁡elifx=_Neighborsthenthisproc⁡_Neighbors ≔ table⁡elifx=_Statusthenthisproc⁡_Status ≔ 'SIMPLE'elifx=_Emaxnamethenthisproc⁡_Emaxname ≔ 0elsereturn'procname⁡args'end ifend proc
ends⁡
1,2,1,6,2,8,3,10,4,5,4,7,5,9,6,10,8,9
9
See Also
GraphTheory
GraphTheory[MinimalSpanningTree]
networks(deprecated)[shortpathtree]
with
Download Help Document