descendants_at_distance#

descendants_at_distance(G, source, distance)[source]#

Returns all nodes at a fixed distance from source in G.

Parameters:
GNetworkX graph

A graph

sourcenode in G
distancethe distance of the wanted nodes from source
Returns:
set()

The descendants of source in G at the given distance from source

Examples

>>> G = nx.path_graph(5)
>>> nx.descendants_at_distance(G, 2, 2)
{0, 4}
>>> H = nx.DiGraph()
>>> H.add_edges_from([(0, 1), (0, 2), (1, 3), (1, 4), (2, 5), (2, 6)])
>>> nx.descendants_at_distance(H, 0, 2)
{3, 4, 5, 6}
>>> nx.descendants_at_distance(H, 5, 0)
{5}
>>> nx.descendants_at_distance(H, 5, 1)
set()