【主要思路】v 的所有出发变进行探索 =》直到所有的出发表发现
“回溯” v 的前驱点。
搜索前驱点的出发边, 一直到源节点s 被发现。
【区别】广度优先搜索的前驱点是一颗树,但是深度 的前驱点 是多个树组成。
【边的分类】树边,后向边,前向边,横线边。
DFS(G)
for each vertex u is belong to G,V
u.color = white
u.pi = NIL
time = 0
for each vertex u is belong to G.V
if u.color == white
DFS-VISIT(G,u)
DFS-VISIT(G,u)
time = time + 1
u.time = time
u.color = GRAY
for each v is belong to G:Adj[u]
for v.color == white
v.pi = u
DFS.VISIT(G,v)
u.color = Black // blacken u; it is finished
time = time +1
u.f = time
【时间复杂度】和广度搜索一样为O(V+E)