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: Gis a graph, sis a vertex in GPostcondition: d[u]=shortest distance ±[u] and ²[u] = predecessor of u on shortest paths from sto each vertex uin Gfor each vertex u³V[G]d[u]´ µ²[u]´null color[u] = BLACK //initialize vertexcolour[s] ´REDd[s]´0 Q.enqueue(s)while Q¶ ·u´Q.dequeue()for each v³Adj[u] //explore edge (u,v)if color[v] = BLACKcolour[v]´REDd[v]´d[u]+1 ²[v]´uQ.enqueue(v)colour[u]´GRAY
This preview has intentionally blurred sections.
Sign up to view the full version.