DFS

advertisement
Tracing An Algorithm for Strongly Connected
Components that uses Depth First Search
Graph obtained from Text, page 273
252a-al: Geetika Tewari
Initial Graph: Directed, multiple edges
DFS started: All vertices are labeled sequentially in postorder
Above, finished visiting vertex 1 first
Finished visiting vertex 2
Finished visiting vertex 3
Finished visiting vertex 4
Finished visiting vertex 5. Now have to pick a new vertex to
start DFS from.
Started DFS at a new vertex. Now finished
visiting vertex 6
Finished visiting vertex 7
Finished visiting vertex 8
Finished visiting vertex 9
Finished visiting vertex 10.
Notice: Entire graph has been visited and all nodes are labeled
in post order
Inverse Digraph: all directed edges have been
reversed
Start DFS in the reverse graph, starting at the highest
numbered vertex.
Above: DFS started at vertex 10. Could only visit 2 other
nodes. Have to choose the next highest numbered vertex
Next started DFS at vertex labeled 7. Could only visit one
other vertex. Have to resume DFS on the next highest
numbered vertex.
Resumed DFS on vertex 5. Could visit 3 other vertices
Resumed DFS on vertex 1. Finished traversing the
entire graph.
The result is a forest. In this case, a forest of 4 trees, each is a
strongly connected component of the original graph.
Strongly connected means every two vertices are reachable
from each other. Strongly connected components only exist in
the context of directed graphs.
1
2
3
A Forest
4
Download