{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Tables 2.0 - Progress On every iteration one vertex is...

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

View Full Document Right Arrow Icon
Last Updated: 4/1/10 10:16 AM CSE 2011 Prof. J. Elder - 161 - Progress? ± On every iteration one vertex is processed (turns gray ). BFS(G,s) Precondition: G is a graph, s is a vertex in G Postcondition: d [ u ] = shortest distance ± [ u ] and ² [u] = predecessor of u on shortest paths from s to each vertex u in G for each vertex u ³ V [ G ] d [ u ] ´ µ ² [ u ] ´ null color[u] = BLACK //initialize vertex colour[s] ´ RED d [ s ] ´ 0 Q.enqueue( s ) while Q ¶ · u ´ Q.dequeue() for each v ³ Adj[ u ] //explore edge ( u , v ) if color[ v ] = BLACK colour[v] ´ RED d [ v ] ´ d [ u ] + 1 ² [ v ] ´ u Q.enqueue( v ) colour [ u ] ´ GRAY
Image of page 1

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

View Full Document Right Arrow Icon