您是在递归算法中以广度优先还是深度优先进行搜索?
Do you search in breadth- or depth-first in a recursive algorithm?
深度优先搜索使用LIFO/Stack。
广度优先搜索使用 FIFO/Queue。
递归算法使用什么?两者的结合?
递归算法总是使用深度优先搜索 (DFS)
伪代码
输入:图G和G的顶点v
输出: 从标记为已发现的 v 可达的所有顶点
DFS 的递归实现:
1 procedure DFS(G,v):
2 label v as discovered
3 for all edges from v to w in G.adjacentEdges(v) do
4 if vertex w is not labeled as discovered then
5 recursively call DFS(G,w)
深度优先搜索使用LIFO/Stack。 广度优先搜索使用 FIFO/Queue。 递归算法使用什么?两者的结合?
递归算法总是使用深度优先搜索 (DFS)
伪代码
输入:图G和G的顶点v
输出: 从标记为已发现的 v 可达的所有顶点
DFS 的递归实现:
1 procedure DFS(G,v):
2 label v as discovered
3 for all edges from v to w in G.adjacentEdges(v) do
4 if vertex w is not labeled as discovered then
5 recursively call DFS(G,w)