CSC252
Fall 2000
Ileana Streinu
Lecture 14
- More on Depth First Search on directed and undirected
graphs: collecting information about vertices and edges. White
(not seen yet),
grey (considered but not finished) and black (finished) vertices.
Edges: tree, back, forward and cross edges.
- What types of edges are possible in undirected graphs?
- DFS numbering: prefix or postfix numbering of the visited vertices.
- Linear time algorithms for:
- Deciding connectivity of an
undirected graph
- Finding directed cycles in a digraph. Lemma: a
digraph is acyclic iff there are no back edges.
- Deciding
if the graph is bipartite. Lemma: a graph is bipartite
iff it does not contain an odd cycle.
- Application: Linear time algorithm for strongly connected
components.
- Decomposition into strongly connected components and the
condensed graph of a digraph.
- Algorithm:
- Do a DFS traversal of the digraph, label the vertices in
postfix DFS order.
- Compute the reversed digraph (all arrows are
reversed).
- Perform DFS of the reverse graph beginning at the highest
numbered vertex. If the search does not visit all the vertices,
choose the highest numbered unvisited vertex and resume the
search there.
- Continue until all vertices are visited. In the resulting
forest, each tree contains the vertices of a strongly connected
component.
- Examples.
- Application: Topological Sort. Algorithm:
- Perform a DFS on the directed graph, check for acyclicity (if
cyclic, stop).
- Label the vertices in postorder (by finishing time).
- As each vertex is finished, insert it in front of a linked
list.
- Return the linked list of vertices.