1 / 8

CS344: Lecture 16

CS344: Lecture 16. S. Muthu Muthukrishnan. E. D. C. B. A. Graph Navigation. BFS: DFS: DFS numbering by start time or finish time. tree, back, forward and cross edges. How to do a DFS and identify what each edge type is?

colt-nelson
Download Presentation

CS344: Lecture 16

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS344: Lecture 16 S. Muthu Muthukrishnan

  2. E D C B A Graph Navigation • BFS: • DFS: DFS numbering by start time or finish time. • tree, back, forward and cross edges. • How to do a DFS and identify what each edge type is? • Prove that a directed graph G is acyclic if and only if DFS of G has no back edges. E D C B A

  3. Details • Iterative algorithm for BFS uses a queue, that for DFS uses a stack. • How to use BFS or DFS to test whether a undirected graph is connected? • Both BFS and DFS take time O(|V|+|E|) given graph in the adjacency list format.

  4. DAGs • DAG • Topological ordering of a DAG G is a linear ordering of the vertices of G such that if (u,v) is an edge in G than v appears before u in the linear ordering. This can be thought of as numbering vertices in the topological order, and we will refer to it as topological numbering. • Use DFS to do topological numbering.

  5. Another application • A directed graph G is strongly connected if there is a path from u to v and v to u for all pairs of vertices u,v. • Cute trick to check if G is strongly connected: • Pick some v. • Do DFS(v). If some vertex w is not reachable, print NOT strongly connected. • Reverse edges of G to get G’. • Do DFS(v) in G’. If some vertex w is not reachable, print NOT strongly connected. Else, print YES. • Time: O(|V|+|E|)

  6. Strongly connected graph? Example a G: g c d e b f a g G’: c d e b f

  7. a g c d e b f SC components • How to partition a graph into strongly connected components (SCC)? • SCC: Maximal subgraphs such that each vertex can reach all other vertices in the subgraph { a , c , g } { f , d , e , b }

  8. SC Components Algorithm • Do DFS of G and put vertices in a stack at their finishing times. • Reverse edges of G to get G’. • Do DFS of G’ starting from vertices that get popped off the stack from the first step! Each DFS tree generated will be a SCC. • Question: What is the graph of SCC components of a directed graph G?

More Related