nonisomorphic_trees#

nonisomorphic_trees(order)[source]#

Generate nonisomorphic trees of specified order.

Parameters:
orderint

order of the desired tree(s)

Yields:
networkx.Graph instances

A tree with order number of nodes that is not isomorphic to any other yielded tree.

Raises:
ValueError

If order is negative.

Examples

There are 11 unique (non-isomorphic) trees with 7 nodes.

>>> n = 7
>>> nit_list = list(nx.nonisomorphic_trees(n))
>>> len(nit_list) == nx.number_of_nonisomorphic_trees(n) == 11
True

All trees yielded by the generator have the specified order.

>>> all(len(G) == n for G in nx.nonisomorphic_trees(n))
True

Each tree is nonisomorphic to every other tree yielded by the generator. >>> seen = [] >>> for G in nx.nonisomorphic_trees(n): … assert not any(nx.is_isomorphic(G, H) for H in seen) … seen.append(G)