L05 - Graph algorithms(Ch.22 Graphs Set of OBJECTS with...

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

View Full Document Right Arrow Icon
CS0250, Set 5 Graph algorithms (Ch.22) Graphs:  Set of OBJECTS with pairwise CONNECTIONS Design and analysis of graph algorithms is a challenging branch of  computer science. There are hundreds of graph algorithms known, and thousands of  practical applications. Note: We have    0 ≤ |E| ≤ |V|(|V|-1)/2   because there are                           possible pairs of  vertices. Vertex: for object Edge:  for connection 2 ) 1 | (| | | 2 | | - = V V V
Background image of page 1

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

View Full DocumentRight Arrow Icon
CS0250, Set 5 Representation Representation of graphs Mathematical representation  G=(V, E) where V={1, 2, 3, 4, 5} and E={(1,2), (2,3), (3,4), (4,1),(3,5)} Adjacency matrix 4 3 2 5 1 0 1 0 1 0 1 0 1 0 0 0 1 0 1 1 1 0 1 0 0 0 0 1 0 0 1 2 3 4 5 For any pair of vertices i, j, a[i,j] = 1 if there is an edge (i,j); otherwise a[i,j]=0. Note that (i,j) is an edge  (j,i)  is an edge, thus a[i,j]=a[j,i] 1 2 3 4 5
Background image of page 2
CS0250, Set 5 Representation (cont) Adjacency-list Every vertex u is associated with a linked list Adj[u], which contains all the vertices  adjacent to u. 
Background image of page 3

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

View Full DocumentRight Arrow Icon
CS0250, Set 5 Breadth-first search (Ch.22.2) Breadth-first search (BFS)  is a simple algorithm for searching a  graph. Given G=(V, E), and a distinguished  source vertex  s, BFS  systematically explores the edges of G to  – discover every vertex that is reachable from s, – compute distance (i.e., smallest number of edges) from s to each  reachable vertex, and – produce a “breadth-first” tree with root s that contains all reachable  vertices. u v Vertex  v is reachable from u because there is a sequence of consecutive edges from u to v.  The distance from u to v is 3.
Background image of page 4
CS0250, Set 5 Breadth-first means to expand the frontier between  discovered  and  undiscovered  vertices uniformly across the breadth of the  frontier .  That is, the algorithm discovers all vertices at distance  k from s before discovering any vertices at distance k+1. F A B C G D E H frontier, with distance 0. The source s is node A.
Background image of page 5

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

View Full DocumentRight Arrow Icon
CS0250, Set 5 Breadth-first  means the algorithm expands the frontier between  discovered and undiscovered vertices uniformly across the  breadth of the frontier.  That is, the algorithm discovers all  vertices at distance k from s before discovering any vertices at  distance k+1. F A B C G D E H 1 1 1 1 All nodes next to A form a new frontier with  distance 1 from  A.
Background image of page 6
CS0250, Set 5 Breadth-first  means the algorithm expands the frontier between  discovered and undiscovered vertices uniformly across the  breadth of the frontier.  That is, the algorithm discovers all  vertices at distance k from s before discovering any vertices at  distance k+1.
Background image of page 7

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

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

This note was uploaded on 07/05/2008 for the course CS CSIS0250 taught by Professor Dr.hing-fungting during the Summer '08 term at HKU.

Page1 / 55

L05 - Graph algorithms(Ch.22 Graphs Set of OBJECTS with...

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

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