note07-1x2

# note07-1x2 - Graph Algorithms Many problems in CS can be...

This preview shows pages 1–4. Sign up to view the full content.

Graph Algorithms Many problems in CS can be modeled as graph problems . Algorithms for solving graph problems are fundamental to the ﬁeld of algorithm design. Deﬁnition A graph G = ( V , E ) consists of a vertex set V and an edge set E . | V | = n and | E | = m . Each edge e = ( x , y ) E is an unordered pair of vertices. If ( u , v ) E , we say v is a neighbor of u . The degree deg ( u ) of a vertex u is the number of edges incident to u . c ± Xin He (University at Buffalo) CSE 431/531 Algorithm Analysis and Design 2 / 64 Graph Algorithms Fact ± v V deg ( v ) = 2 m This is because, for each e = ( u , v ) , e is counted twice in the sum, once for deg ( v ) and once for deg ( u ) . c ± Xin He (University at Buffalo) CSE 431/531 Algorithm Analysis and Design 3 / 64

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

View Full Document
Directed Graphs Deﬁnition If the two end vertices of e are ordered, the edge is directed , and we write e = x y . If all edges are directed, then G is a directed graph. The in-degree deg in ( u ) of a vertex u is the number of edges that are directed into u . The out-degree deg out ( u ) of a vertex u is the number of edges that are directed from u . c ± Xin He (University at Buffalo) CSE 431/531 Algorithm Analysis and Design 4 / 64 Directed Graphs Fact ± v V deg in ( v ) = ± v V deg out ( v ) = m This is because, for each e = ( u v ) , e is counted once ( deg in ( v ) ) in the sum of in-degrees, and once ( deg out ( u ) ) in the sum of out-degrees. c ± Xin He (University at Buffalo) CSE 431/531 Algorithm Analysis and Design 5 / 64
The numbers n ( = | V | ) and m ( = | E | ) are two important parameters to describe the size of a graph. It is easy to see 0 m n 2 . It is also easy to show: if G is a tree (namely undirected, connected graph with no cycles), them m = n - 1 . If m is close to n , we say G is sparse . If m is close to n 2 , we say G is dense . Because n and m are rather independent to each other, we usually use both parameters to describe the runtime of a graph algorithm. Such as O ( n + m ) or O ( n 1 / 2 m ). c ± Xin He (University at Buffalo) CSE 431/531 Algorithm Analysis and Design 6 / 64 Graph Representations We mainly use two graph representations. Adjacency Matrix Representation We use a 2D array A [ 1 .. n , 1 .. n ] to represent G = ( V , E ) : A [ i , j ] = ± 1 if ( v i , v j ) E 0 if ( v i , v j ) ±∈ E Sometimes, there are other information associated with the edges. For example, each edge e = ( v i , v j ) may have a weight w ( e ) = w ( v i , v j ) (for example, MST). In this case, we set A [ i , j ] = w ( v i , v j ) . For undirected graph, A is always symmetric . The Adjacency Matrix Representation for directed graph is similar. A [ i , j ] = 1 (or w ( v i , v j ) if G has edge weights) iff v i v j E . For directed graphs,

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This document was uploaded on 02/02/2010.

### Page1 / 28

note07-1x2 - Graph Algorithms Many problems in CS can be...

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

View Full Document
Ask a homework question - tutors are online