random_labeled_rooted_tree#

random_labeled_rooted_tree(n, *, seed=None)[source]#

Returns a labeled rooted tree with n nodes.

The returned tree is chosen uniformly at random from all labeled rooted trees.

Parameters:
nint

The number of nodes

seedinteger, random_state, or None (default)

Indicator of random number generation state. See Randomness.

Returns:
networkx.Graph

A networkx.Graph with integer nodes 0 <= node <= n - 1. The root of the tree is selected uniformly from the nodes. The “root” graph attribute identifies the root of the tree.

Raises:
NetworkXPointlessConcept

If n is zero (because the null graph is not a tree).

Notes

This function returns the result of random_labeled_tree() with a randomly selected root.