rustworkx.bfs_layers

bfs_layers(graph, sources=None)[source]

Return the BFS layers of a graph as a list of lists.

Parameters:
  • graph – The input graph to use. Can either be a PyGraph or PyDiGraph

  • sources (list[int]) – An optional list of node indices to use as the starting nodes for the BFS traversal. If not specified, all nodes in the graph will be used as sources.

Returns:

A list of lists where each inner list contains the node indices at that BFS layer/level from the source nodes

Return type:

list[list[int]]