Download presentation
Presentation is loading. Please wait.
1
CS344: Lecture 16 S. Muthu Muthukrishnan
2
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. A C E B D A C E B D
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 G: G’: a d c b e f g a d c b e f g
7
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 } a d c b e f g
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?
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.