它突然出现在我的脑海里。为什么BFS使用2种颜色标记节点,而使用3种颜色的DFS?
为什么我们只使用2 BFS图表颜色traveral都需要DFS
和3?
例如:维基百科:
BFS:
procedure BFS(G,v):
2 create a queue Q
3 enqueue v onto Q
4 mark v
5 while Q is not empty:
6 t ← Q.dequeue()
7 if t is what we are looking for:
8 return t
9 for all edges e in G.adjacentEdges(t) do
12 u ← G.adjacentVertex(t,e)
13 if u is not marked:
14 **mark u**
15 enqueue u onto Q
16 return none
DFS:
procedure DFS(G,v):
2 label v **as explored**
3 for all edges e in G.adjacentEdges(v) do
4 if edge e is unexplored then
5 w ← G.adjacentVertex(v,e)
6 if vertex w is unexplored then
7 label e as a **discovery edge**
8 recursively call DFS(G,w)
9 else
10 label e as a **back edge**
为什么两种颜色不够的DFS? 为什么BFS有3种颜色的还原剂?
这里是另一个BFS(这次3色):
你能提供一个关于这方面的参考? BFS和DFS需要什么样的颜色才能说出两种颜色? – templatetypedef
维基百科。编辑mt q –