Chapter 22 Extended

Chapter 22 Extended - SHEN'S CLASS NOTES Chapter 22...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
SHEN’S CLASS NOTES Chapter 22 Elementary Graph Algorithms 22.1 Representation of Graphs There are two commonly used methods. (1) Adjacency list (2) Adjacency matrix Example 1 For undirected graph 1 4 5 2 3 1 2 3 5 4 3 4 3 2 2 1 2 4 2 5 5 4 1 5 (a) A graph G (b) The adjacency-list 1 2 3 4 5 1 2 3 5 4 0 1 0 0 1 1 0 1 1 1 0 1 0 1 0 0 1 1 0 1 1 1 0 1 0 (c) The adjacency matrix Fig. 22-1 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
SHEN’S CLASS NOTES Example 2 For directed graph (a) A directed graph G 1 2 3 4 5 6 1 2 3 5 4 0 1 0 1 0 0 0 0 0 0 1 0 0 0 0 0 1 1 0 1 0 0 0 0 0 0 0 1 0 0 (c) The adjacency matrix 1 5 4 2 3 6 1 2 3 5 4 2 6 6 5 6 4 2 4 5 (b) The adjacency-list 0 0 0 0 0 1 6 Fig. 22-2 Comments (1) Give a graph G(V, E), the adjacency-list needs Θ ( m ) space, where m = |E|. Therefore, when the graph is sparse, the adjacency-list is more efficient. If the graph is weighted, we can include the weights in each record easily. (2) The adjacency-matrix needs Θ ( n 2 ) space, where n = |V|. When the graph is dense, it is a good and convenient 2
Background image of page 2
SHEN’S CLASS NOTES representation. If the graph is weighted, we can put the weight of edge ( i , j ) in the entry ( i , j ). (3) Another representation is called incidence matrix which is useful in theorem proofs. Example 3. b d c a e 1 e 2 e 3 e 4 e 5 a b d c 1 0 0 0 1 1 1 1 0 0 0 1 0 1 0 0 0 1 1 1 (b) The incidence matrix e 1 e 2 e 3 e 4 e 5 (a) A graph G Fig. 22-3 (4) We introduce a notation that will be used in the discussion of graph algorithms later. Let v be a vertex in graph G( V , E ). We denote the set of vertices that are adjacent to v by Adj ( v ) = { u | u V and ( v , u ) E}. For example, in the graph of Fig. 22-3, Adj ( c ) = { b , d }. In case the graph is a directed graph, Adj ( v ) denotes all adjacent vertices from v . For example, in the graph of Fig. 22-2, Adj (2) ={5}. Another notation we will define is the distance . Given a path P( a , b ) from vertex a to vertex b , the number of edges in the path is called the path length of P( a b ), denoted by | P( a b )|. Then, the distance from vertex a to vertex b is 3
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
SHEN’S CLASS NOTES defined to be the path length of the shorted path from a to b , denoted by dis ( a , b ) = Min {|P( a , b )| | P( a , b ) is a path }. The largest distance in a graph is called the diameter of the graph. When the graph is weighted, we define the weighted path length for path P( a , b ) to be the sum of all weights on the edges of P( a , b ), denoted by W(P( a , b )) = ) , ( ) ( b a P e e w . We also define the weighted distance from a to b to be the smallest weight among all weighted paths from a to b . weighted - dis ( a , b ) = Min { W(P( a , b )) | P( a , b ) is a path }. For convenience, we often use |P( a b )| and dis ( a b ) for W(P( a b )) and weighted - dis ( a b ) when the meaning is clear. 4
Background image of page 4
SHEN’S CLASS NOTES 22.2 Breadth-First search (BFS) Breadth-First search is one of graph traversal algorithms. A  graph traversal is to systematically visit every vertex (and every  edge) in a given graph. The purpose of the graph traversal  depends on applications. An efficient traversal algorithm will  support efficient algorithms for applications.
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 44

Chapter 22 Extended - SHEN'S CLASS NOTES Chapter 22...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online