
Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The depth-first search (dfs) algorithm for traversing a graph, explaining the coloring scheme and the classification of edges as tree, back, forward, or cross. The dfs algorithm is crucial for graph theory and computer science, and this handout offers a clear and concise explanation.
Typology: Assignments
1 / 1
This page cannot be seen from the preview
Don't miss anything!

ECS122A Handout May 17, 2009
Depth-first search
DFS(G) for each vertex u ∈ V do color[u] = white endfor time = 0 for each vertex u ∈ V do if color[u] = white then DFS-visit(u) endif end for
DFS-visit(u) color[u] = gray time = time + 1 d[u] = time for each v ∈ Adj[u] do if color[v] = white then DFS-visit(v) color[u] = black time = time + 1 f [u] = time
Classification of edges
Note: In an undirected graph, there may be some ambiguity since edge (u, v) and (v, u) are the same edge. Classify by the first type above that matches. Therefore, if G is undirected, a DFS produces only tree (T) and back (B) edges.