summaryrefslogtreecommitdiff
path: root/networkx/algorithms/traversal
diff options
context:
space:
mode:
Diffstat (limited to 'networkx/algorithms/traversal')
-rw-r--r--networkx/algorithms/traversal/breadth_first_search.py17
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
-----