diff options
author | Jeffrey Finkelstein <jeffrey.finkelstein@gmail.com> | 2015-11-16 01:44:10 -0500 |
---|---|---|
committer | Jeffrey Finkelstein <jeffrey.finkelstein@gmail.com> | 2016-07-29 23:14:29 -0400 |
commit | 2435e76b7ed9677dc28e469ae3409cdd5a191846 (patch) | |
tree | 962bf717fe987a11f727b427d9bbb74ba7277465 /networkx/algorithms/traversal | |
parent | 9fcaea9cae8beaf46cbb9df0576102de92bbc691 (diff) | |
download | networkx-2435e76b7ed9677dc28e469ae3409cdd5a191846.tar.gz |
Adds tree encoding and decoding functions.
This commit makes several additions. The main additions are two
encoding/decoding schemes for trees, the nested tuple and Prüfer
sequence schemes. These appear in a new module,
`networkx.algorithms.tree.coding`.
These encoding/decoding functions required implementing a function for
joining subtrees at a root node, which appears as the `join` function in
a new module, `networkx.algorithms.tree.operations`.
Finally, the encoding/decoding schemes suggest a simple implementation
for generating a uniformly random tree. The random tree generator first
generates a random Prüfer sequence, then converts that sequence to the
corresponding tree. This `random_tree` function appears in a new module,
`networkx.generators.tree`.
Diffstat (limited to 'networkx/algorithms/traversal')
-rw-r--r-- | networkx/algorithms/traversal/breadth_first_search.py | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/networkx/algorithms/traversal/breadth_first_search.py b/networkx/algorithms/traversal/breadth_first_search.py index 6166ce0b..c8be79a9 100644 --- a/networkx/algorithms/traversal/breadth_first_search.py +++ b/networkx/algorithms/traversal/breadth_first_search.py @@ -32,9 +32,20 @@ def bfs_edges(G, source, reverse=False): Examples -------- - >>> G = nx.path_graph(3) - >>> print(list(nx.bfs_edges(G,0))) - [(0, 1), (1, 2)] + To get the edges in a breadth-first search:: + + >>> G = nx.path_graph(3) + >>> list(nx.bfs_edges(G, 0)) + [(0, 1), (1, 2)] + + To get the nodes in a breadth-first search order:: + + >>> G = nx.path_graph(3) + >>> root = 2 + >>> edges = nx.bfs_edges(G, root) + >>> nodes = [root] + [v for u, v in edges] + >>> nodes + [2, 1, 0] Notes ----- |