NetworkX

Previous topic

networkx.algorithms.shortest_paths.unweighted.single_source_shortest_path

Next topic

networkx.algorithms.shortest_paths.unweighted.all_pairs_shortest_path

networkx.algorithms.shortest_paths.unweighted.single_source_shortest_path_length

networkx.algorithms.shortest_paths.unweighted.single_source_shortest_path_length(G, source, cutoff=None)

Compute the shortest path lengths from source to all reachable nodes.

Parameters :

G : NetworkX graph

source : node

Starting node for path

cutoff : integer, optional

Depth to stop the search. Only paths of length <= cutoff are returned.

Returns :

lengths : dictionary

Dictionary of shortest path lengths keyed by target.

See also

shortest_path_length

Examples

>>> G=nx.path_graph(5)
>>> length=nx.single_source_shortest_path_length(G,0)
>>> length[4]
4
>>> print(length)
{0: 0, 1: 1, 2: 2, 3: 3, 4: 4}