# 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:
1. Deciding connectivity of an undirected graph
2. Finding directed cycles in a digraph. Lemma: a digraph is acyclic iff there are no back edges.
3. 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.
1. Decomposition into strongly connected components and the condensed graph of a digraph.
2. Algorithm:
1. Do a DFS traversal of the digraph, label the vertices in postfix DFS order.
2. Compute the reversed digraph (all arrows are reversed).
3. 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.
4. Continue until all vertices are visited. In the resulting forest, each tree contains the vertices of a strongly connected component.
5. Examples.
• Application: Topological Sort. Algorithm:
1. Perform a DFS on the directed graph, check for acyclicity (if cyclic, stop).
2. Label the vertices in postorder (by finishing time).
3. As each vertex is finished, insert it in front of a linked list.
4. Return the linked list of vertices.