Tables 1.2

# Tables 1.2 - BFS Algorithm Pattern BFS(G,s Precondition G...

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

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

View Full Document

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.

Unformatted text preview: BFS Algorithm Pattern BFS(G,s) Precondition: G is a graph, s is a vertex in G Postcondition: all vertices in G reachable from s have been visited for each vertex u V [G] color[u] BLACK //initialize vertex colour[s] RED Q.enqueue(s ) while Q u Q.dequeue() for each v Adj[u ] //explore edge (u,v ) if color[v ] = BLACK colour[v] RED Q.enqueue(v ) colour [u ] GRAY CSE 2011 Prof. J. Elder - 121 - Last Updated: 4/1/10 10:16 AM BFS Example A undiscovered A discovered (on Queue) A finished unexplored edge A L1 B discovery edge C E D F cross edge L0 L1 L0 A B C E CSE 2011 Prof. J. Elder L1 D F A B C E - 122 - D F Last Updated: 4/1/10 10:16 AM BFS Example (cont.) L0 L1 L0 A B C E L0 L1 D F L0 C E CSE 2011 Prof. J. Elder B L2 A B L2 L1 L1 D - 123 - C E D F A B L2 F A C E D F Last Updated: 4/1/10 10:16 AM BFS Example (cont.) L0 L1 L0 L1 A B L2 C E L1 D B L2 F A C E D F A B L2 L0 C E CSE 2011 Prof. J. Elder D F - 124 - Last Updated: 4/1/10 10:16 AM Properties Notation Gs: connected component of s A Property 1 BFS(G, s) visits all the vertices and edges of Gs B C D Property 2 E The discovery edges labeled by BFS(G, s) form a spanning tree Ts of Gs L0 Property 3 For each vertex v in Li The path of Ts from s to v has i edges Every path from s to v in Gs has at least i edges CSE 2011 Prof. J. Elder - 125 - L1 A B L2 F C E D F Last Updated: 4/1/10 10:16 AM ...
View Full Document

{[ snackBarMessage ]}

### Page1 / 5

Tables 1.2 - BFS Algorithm Pattern BFS(G,s Precondition G...

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

View Full Document
Ask a homework question - tutors are online