This preview shows pages 1–4. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: Elementary Graph Algorithms CSE 680 Suggested Reading : Appendix B4, Chapter 22 1 Graphs G ( V,E ) V : vertex set; E : edge set. Directed graphs, undirected graphs, weighted graphs. An edge is incident on , incident from , or incident to a vertex. ( u,v ) E iff v is adjacent to u . Degree, indegree, outdegree of a vertex. A path from a vertex v to a vertex v is a sequence of vertices, ( v ,v 1 ,...,v k ), such that v = v , v = v k and ( v i 1 ,v i ) E for i = 1 , 2 ,...,k . Length of path: the number of edges in the path. Simple path: all vertices in the path are distinct. Cycle, simple cycle Acyclic graph Graph representations Adjacency matrix Adjacency lists 1 2 Basic DepthFirst Search procedure Search ( G = ( V,E )) // Assume V = { 1 , 2 ,...,n } // // global array visited [1 ..n ] // visited [1 ..n ] 0; for i 1 to n if visited [ i ] = 0 then call dfs ( i ) procedure dfs ( v ) visited [ v ] 1; for each node w such that ( v,w ) E do if visited [ w ] = 0 then call dfs ( w ) How to implement the forloop if an adjacency matrix A is used to represent the graph? Time complexity Using adjacency matrix: O ( n 2 ) Using adjacency lists: O (  V  +  E  ) 2 3 Connectivity An undirected graph is connected if every pair of vertices are connected by a path. A connected component is a subgraph which is connected and is not contained in any other connected subgraph. A connected component is usually identified by the vertices in that component. Problem : Given an undirected graph, identify all its connected components. procedure Connected Components ( G = ( V,E )) // Assume V = { 1 , 2 ,...,n } // // global array component [1 ..n ] // component [1 ..n ] cn for i 1 to n if component [ i ] = 0 then cn cn + 1 call dfs ( i,cn ) procedure dfs ( v,cn ) component...
View
Full
Document
 Spring '08
 Hari
 Algorithms

Click to edit the document details