The.Algorithm.Design.Manual.Springer-Verlag.1998

The.Algorithm.Design.Manual.Springer-Verlag.1998 The.Algorithm.Design.Manual.Springer-Verlag.1998

18.04.2013 Views

Applications of Graph Traversal Next: Connected Components Up: Graph Algorithms Previous: Depth-First Search Applications of Graph Traversal Most elementary graph algorithms involve making one or two traversals of the graph, while we update our knowledge of the graph as we visit each edge and vertex. Properly implemented using adjacency lists, any such algorithm is destined to be very fast. Both BFS and DFS run in O(n+m) on both directed and undirected graphs where, as usual, n is the number of vertices and m the number of edges in the graph. This is optimal, since it is as fast as one can hope to read the graph. The trick is seeing when traversal approaches are destined to work. We present several examples below. ● Connected Components ● Tree and Cycle Detection ● Two-Coloring Graphs ● Topological Sorting ● Articulation Vertices Algorithms Mon Jun 2 23:33:50 EDT 1997 file:///E|/BOOK/BOOK2/NODE66.HTM [19/1/2003 1:29:08]

Connected Components Next: Tree and Cycle Detection Up: Applications of Graph Traversal Previous: Applications of Graph Traversal Connected Components Either breadth-first or depth-first search can be used to identify the connected components of an undirected graph and label each vertex with the identifier of its components. In particular, we can modify the DFS-graph algorithm to increment a counter for the current component number and label each vertex accordingly as it is discovered in DFS. For directed graphs, there are two distinct notions of connectivity, leading to algorithms for finding both weakly connected and strongly connected components. Both of these can be found in O(n+m) time, as discussed in Section . Algorithms Mon Jun 2 23:33:50 EDT 1997 file:///E|/BOOK/BOOK2/NODE67.HTM [19/1/2003 1:29:08]

Applications of Graph Traversal<br />

Next: Connected Components Up: Graph <strong>Algorithm</strong>s Previous: Depth-First Search<br />

Applications of Graph Traversal<br />

Most elementary graph algorithms involve making one or two traversals of the graph, while we update<br />

our knowledge of the graph as we visit each edge and vertex. Properly implemented using adjacency<br />

lists, any such algorithm is destined to be very fast. Both BFS and DFS run in O(n+m) on both directed<br />

and undirected graphs where, as usual, n is the number of vertices and m the number of edges in the<br />

graph. This is optimal, since it is as fast as one can hope to read the graph. <strong>The</strong> trick is seeing when<br />

traversal approaches are destined to work. We present several examples below.<br />

● Connected Components<br />

● Tree and Cycle Detection<br />

● Two-Coloring Graphs<br />

● Topological Sorting<br />

● Articulation Vertices<br />

<strong>Algorithm</strong>s<br />

Mon Jun 2 23:33:50 EDT 1997<br />

file:///E|/BOOK/BOOK2/NODE66.HTM [19/1/2003 1:29:08]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!