DS-chapter9(graph -1)

DS-chapter9(graph -1) - CHAPTER 9 GRAPH ALGORITHMS 9.1...

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

View Full Document Right Arrow Icon
CHAPTER 9 GRAPH ALGORITHMS 9.1 Definitions G( V, E ) where G ::= graph, V = V( G ) ::= finite nonempty set of vertices, and E = E( G ) ::= finite set of edges. Undirected graph: ( v i , v j ) = ( v j , v i ) ::= the same edge. Directed graph (digraph): < v i , v j > ::= < v j , v i > v i v j tail head Restrictions : (1) Self loop is illegal. (2) Multigraph is not considered 0 1 0 1 2 Complete graph: a graph that has the maximum number of edges 0 2 1 3 2 ) 1 ( 2 E of # V of # - = = = n n n C n 0 2 1 3 ) 1 ( E of # V of # 2 - = = = n n P n n
Background image of page 1

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

View Full DocumentRight Arrow Icon
v i v j v i and v j are adjacent ; ( v i , v j ) is incident on v i and v j v i v j v i is adjacent to v j ; v j is adjacent from v i ; < v i , v j > is incident on v i and v j Subgraph G’ G ::= V( G’ ) V( G ) && E( G’ ) E( G ) Path ( G) from v p to v q ::= { v p , v i 1 , v i 2 , ⋅ ⋅ ⋅ , v in , v q } such that ( v p , v i 1 ), ( v i 1 , v i 2 ), ⋅ ⋅ ⋅ , ( v in , v q ) or < v p , v i 1 >, ⋅ ⋅ ⋅ , < v in , v q > belong to E( G ) Length of a path ::= number of edges on the path Simple path ::= v i 1 , v i 2 , ⋅ ⋅ ⋅ , v in are distinct Cycle ::= simple path with v p = v q v i and v j in an undirected G are connected if there is a path from v i to v j (and hence there is also a path from v j to v i ) An undirected graph G is connected if every pair of distinct v i and v j are connected Definitions
Background image of page 2
Definitions (Connected) Component of an undirected G ::= the maximal connected subgraph A tree ::= a graph that is connected and acyclic Strongly connected directed graph G ::= for every pair of v i and v j in V( G ), there exist directed paths from v i to v j and from v j to v i . If the graph is connected without direction to the edges, then it is said to be weakly connected Strongly connected component ::= the maximal subgraph that is strongly connected Degree( v ) ::= number of edges incident to v . For a directed G, we have in-degree and out-degree . For example: v in-degree( v ) = 3; out-degree( v ) = 1; degree( v ) = 4 Given G with n vertices and e edges, then ) ( degree where 2 1 0 i i n i i v d d e = = - = A DAG ::= a directed acyclic graph
Background image of page 3

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

View Full DocumentRight Arrow Icon
Definitions Representation of Graphs Adjacency Matrix Adjacency Matrix adj_mat [ n ] [ n ] is defined for G(V, E) with n vertices, n 1 : < = otherwise 0 ) ( , or ) , ( if 1 ] ][ [ adj_mat G E v v v v j i j i j i Note: If G is undirected, then adj_mat[ ][ ] is symmetric. Thus we can save space by storing only half of the matrix. directed) is G (if ] ][ [ adj_mat ) undirected is G (if ] ][ [ adj_mat ) ( degree 1 0 1 0 - = - = + = n j n j i j j i i I know what you’re about to say: this representation wastes space if the graph has a lot of vertices but very few edges, right? Hey you begin to know me! Right. And it wastes time as well. If we are to find out whether or not G is connected, we’ll have to examine all edges. In this case T and S are both O( n 2 ) The trick is to store the matrix as a 1-D array: adj_mat [ n ( n +1)/2 ] = { a 11 , a 21 , a 22 , . .., a n 1 , . .., a nn } The index for a ij is ( i ( i - 1 ) / 2 + j ).
Background image of page 4
Definitions Adjacency Lists Adjacency Lists Replace each row by a linked list HExample H 0 1 2 = 0 0 0 1 0 1 0 1 0 ] 3 ][ 3 [ adj_mat 1 graph[0] 0 graph[1] 2 graph[2] Note: The order of nodes in each list does not matter.
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.

This note was uploaded on 02/16/2011 for the course CS 135 taught by Professor Yuechen during the Fall '08 term at Zhejiang University.

Page1 / 23

DS-chapter9(graph -1) - CHAPTER 9 GRAPH ALGORITHMS 9.1...

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