【发布时间】:2018-09-03 14:46:56
【问题描述】:
在此question 中提供了 DFS 的伪代码:
DFS(source):
s <- new stack
visited <- {} // empty set
s.push(source)
while (s is not empty):
current <- s.pop()
if (current is in visited):
continue
visited.add(current)
// do something with current
for each node v such that (current,v) is an edge:
s.push(v)
然而,它有一个非常明显的细节——同一个节点可以——而且经常会——被推入堆栈两次!!!!!!
1
| \
| 2
| /
3
按 1
流行音乐 1
添加1到访问
按 2、3
流行音乐 2
添加 2 到访问
再次按 1 堆叠
...
...
当然,这不可能吧??
【问题讨论】:
-
@Marco13 你是对的。您应该发表您的评论作为答案。
-
请使用正确标签。 DFS 是 Windows 使用的分布式文件系统
标签: data-structures graph depth-first-search