networkx 2.8.2 Pypi GitHub Homepage
Other Docs
NotesParametersReturnsBackRef
minimum_spanning_tree(G, weight='weight', algorithm='kruskal', ignore_nan=False)

Notes

For Borůvka's algorithm, each edge must have a weight attribute, and each edge weight must be distinct.

For the other algorithms, if the graph edges do not have a weight attribute a default weight of 1 will be used.

There may be more than one tree with the same minimum or maximum weight. See networkx.tree.recognition for more detailed definitions.

Isolated nodes with self-loops are in the tree as edgeless isolated nodes.

Parameters

G : undirected graph

An undirected graph. If G is connected, then the algorithm finds a spanning tree. Otherwise, a spanning forest is found.

weight : str

Data key to use for edge weights.

algorithm : string

The algorithm to use when finding a minimum spanning tree. Valid choices are 'kruskal', 'prim', or 'boruvka'. The default is 'kruskal'.

ignore_nan : bool (default: False)

If a NaN is found as an edge weight normally an exception is raised. If :None:None:`ignore_nan is True` then that edge is ignored instead.

Returns

G : NetworkX Graph

A minimum spanning tree or forest.

Returns a minimum spanning tree or forest on an undirected graph G.

Examples

>>> G = nx.cycle_graph(4)
... G.add_edge(0, 3, weight=2)
... T = nx.minimum_spanning_tree(G)
... sorted(T.edges(data=True)) [(0, 1, {}), (1, 2, {}), (2, 3, {})]
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

networkx.algorithms.tree.mst.minimum_spanning_tree

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /networkx/algorithms/tree/mst.py#540
type: <class 'function'>
Commit: