dfs_tree#

dfs_tree(G, source=None, depth_limit=None)[源代码]#

返回从源深度优先搜索构造的定向树。

参数
G网络X图表
source节点,可选

指定深度优先搜索的起始节点。

depth_limit整型,可选(默认值=len(G))

指定最大搜索深度。

返回
T网络X有向图

有方向的树

实例

>>> G = nx.path_graph(5)
>>> T = nx.dfs_tree(G, source=0, depth_limit=2)
>>> list(T.edges())
[(0, 1), (1, 2)]
>>> T = nx.dfs_tree(G, source=0)
>>> list(T.edges())
[(0, 1), (1, 2), (2, 3), (3, 4)]