networkx 2.8.2 Pypi GitHub Homepage
Other Docs
NotesParametersYields
generic_bfs_edges(G, source, neighbors=None, depth_limit=None, sort_neighbors=None)

The breadth-first search begins at :None:None:`source` and enqueues the neighbors of newly visited nodes specified by the :None:None:`neighbors` function.

Notes

This implementation is from :None:None:`PADS`, which was in the public domain when it was first accessed in July, 2004. The modifications to allow depth limits are based on the Wikipedia article ":None:None:`Depth-limited-search`".

            <Unimplemented 'target' '.. _PADS: http://www.ics.uci.edu/~eppstein/PADS/BFS.py'>
           
            <Unimplemented 'target' '.. _Depth-limited-search: https://en.wikipedia.org/wiki/Depth-limited_search'>
           

Parameters

G : NetworkX graph
source : node

Starting node for the breadth-first search; this function iterates over only those edges in the component reachable from this node.

neighbors : function

A function that takes a newly visited node of the graph as input and returns an iterator (not just a list) of nodes that are neighbors of that node. If not specified, this is just the G.neighbors method, but in general it can be any function that returns an iterator over some or all of the neighbors of a given node, in any order.

depth_limit : int, optional(default=len(G))

Specify the maximum search depth

sort_neighbors : function

A function that takes the list of neighbors of given node as input, and returns an iterator over these neighbors but with custom ordering.

Iterate over edges in a breadth-first search.

Yields

edge

Edges in the breadth-first search starting from :None:None:`source`.

Examples

>>> G = nx.path_graph(3)
... print(list(nx.bfs_edges(G, 0))) [(0, 1), (1, 2)]
>>> print(list(nx.bfs_edges(G, source=0, depth_limit=1)))
[(0, 1)]
See :

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/traversal/breadth_first_search.py#14
type: <class 'function'>
Commit: