CS-0S- Connecte Components -0: Strongly Connecte Graph Directe Path rom every noe to every other noe Strongly Connecte -: Strongly Connecte Graph Directe Path rom every noe to every other noe Strongly Connecte -: Connecte Components Subgraph (subset o the vertices) that is strongly connecte. -: Connecte Components
CS-0S- Connecte Components Subgraph (subset o the vertices) that is strongly connecte. -: Connecte Components Subgraph (subset o the vertices) that is strongly connecte. -: Connecte Components Subgraph (subset o the vertices) that is strongly connecte. -6: Connecte Components Connecte components o the graph are the largest possible strongly connecte subgraphs I we put each vertex in its own component each component woul be (trivially) strongly connecte Those woul not be the connecte components o the graph unless there were no larger connecte subgraphs -: Connecte Components Calculating Connecte Components
CS-0S- Connecte Components Two verticesv anv are in the same connecte component i an only i: Directe path romv to v Directe path romv to v To in connecte components in irecte paths Use DFS -8: DFS Revisite We can keep track o the orer in which we visit the elements in a Depth-First Search For any vertex v in a DFS: [v] = Discovery time when the vertex is irst visite [v] = Finishing time when we have inishe with a vertex (an all o its chilren) -9: DFS Revisite class Ege { public int neighbor; public int next; } voi DFS(Ege G[], int vertex, boolean Visite[], int [], int []) { Ege tmp; Visite[vertex] = true; [vertex] = time++; or (tmp = G[vertex]; tmp!= null; tmp = tmp.next) { i (!Visite[tmp.neighbor]) DFS(G, tmp.neighbor, Visite); } [vertex] = time++; } -0: DFS Revisite To visit every noe in the graph: TraverseDFS(Ege G[]) { int i; boolean Visite = new boolean[g.length]; int = new int[g.length]; int v = new int[g.length]; time = ; or (i=0; i<g.length; i++) Visite[i] = alse; or (i=0; i<g.length; i++) i (!Visite[i]) DFS(G, i, Visite,, ); } -: DFS Example
CS-0S- Connecte Components -: DFS Example -: DFS Example -: DFS Example
CS-0S- Connecte Components -: DFS Example -6: DFS Example
CS-0S- Connecte Components 6 -: DFS Example -8: DFS Example
CS-0S- Connecte Components 6-9: DFS Example 6-0: DFS Example
CS-0S- Connecte Components 8 8 6 -: DFS Example 8 9 6 -: DFS Example
CS-0S- Connecte Components 9 0 8 9 6 -: DFS Example 0 8 9 6 -: DFS Example
CS-0S- Connecte Components 0 0 8 9 6 -: DFS Example 0 8 9 6-6: DFS Example 0 8 9 6
CS-0S- Connecte Components -: DFS Example 0 8 9 6-8: DFS Example 0 8 6 9 6-9: DFS Example
CS-0S- Connecte Components -0: DFS Example -: DFS Example
CS-0S- Connecte Components -: DFS Example -: DFS Example -: DFS Example
CS-0S- Connecte Components -: DFS Example 6-6: DFS Example 6
CS-0S- Connecte Components -: DFS Example 8 6-8: DFS Example 9 8 6-9: DFS Example
CS-0S- Connecte Components 6 0 9 8 6-0: DFS Example 0 9 8 6 -: DFS Example 0 9 8 6
CS-0S- Connecte Components -: DFS Example 0 9 8 6 -: DFS Example 0 9 8 6 -: DFS Example 0 9 8 6
CS-0S- Connecte Components 8 -: DFS Example 0 6 9 8 6-6: Using [] & [] Given two verticesv anv, what o we know i[v ] < [v ]? -: Using [] & [] Given two verticesv anv, what o we know i[v ] < [v ]? Either: -8: Using [] & [] Path romv tov Start romv Eventually visit v Finishv Finishv Given two verticesv anv, what o we know i[v ] < [v ]? Either: -9: Using [] & [] I[v ] < [v ]: Path romv tov No path romv tov Start romv Eventually inishv Start romv Eventually inishv Either a path romv tov, or no path romv tov I there is a path romv tov, then there must be a path romv tov
CS-0S- Connecte Components 9 [v ] < [v ] an a path romv tov v anv are in the same connecte component -0: Calculating paths Path romv tov ingi an only i there is a path romv tov in G T G T is the transpose og Gwith all eges reverse I ater DFS, [v ] < [v ] Run secon DFS ong T, starting romv, anv anv are in the same DFS spanning tree v anv must be in the same connecte component -: Connecte Components Run DFS ong, calculating [] times ComputeG T Run DFS ong T examining noes in inverse orer o inishing times rom irst DFS Any noes that are in the same DFS search tree ing T must be in the same connecte component -: Connecte Components Eg. -: Connecte Components Eg. 0 8 6 9 6 -: Connecte Components Eg.
CS-0S- Connecte Components 0 0 8 6 9 6 -: Connecte Components Eg. 0 8 6 9 6-6: Connecte Components Eg. -: Connecte Components Eg.
CS-0S- Connecte Components 0 6 9 8 6-8: Connecte Components Eg. 0 6 9 8 6-9: Connecte Components Eg. 0 6 9 8 6-60: Topological Sort
CS-0S- Connecte Components How coul we use DFS to o a Topological Sort? (Hint Use iscover an/or inish times) -6: Topological Sort How coul we use DFS to o a Topological Sort? (Hint Use iscover an/or inish times) (What oes it mean i noe x inishe beore noe y?) -6: Topological Sort How coul we use DFS to o a Topological Sort? Do DFS, computing inishing times or each vertex As each vertex is inishe, a to ront o a linke list This list is a vali topological sort