【发布时间】:2011-09-21 02:10:45
【问题描述】:
所以目前我有一个带有以下伪代码的 DFS
procedure DFS(Graph,source):
create a stack S
push source onto S
mark source
while S is not empty:
pop an item from S into v
for each edge e incident on v in Graph:
let w be the other end of e
if w is not marked:
mark w
push w onto S
如何更改此函数以接受限制搜索深度的第三个参数?
【问题讨论】:
-
这不是完全正确的 DFS 算法。它首先访问顶点的所有后继,然后再深入。它应该先深入,然后回溯访问其他子节点。
标签: graph stack graph-theory depth-first-search iterative-deepening