BFS

BFS uses a coloring scheme and queue to search nodes in a graph. The algorithm works like this: Give a Graph G and a starting node s.

Algorithm

Properties

Theorem: The BFS values stored in d[u] give the length of the shortest path from s->u.

Proof: Our inductive hypothesis is

We can prove this based on the number of equeue operations and the assignment of d[v]=d[u]+1 in line 9 above. Let (s,v) be the shortest path from s→v. The base case is d[s]=0=(s,s).

For the inductive step, consider a white vertex v that is discovered during the search from a vertex u. The inductive hypothesis impleys that

From the assignment in line 9 we have

since v is never enqueued again and hence d[v] never changes again, the inductive hypothesis is maintained. Thus we conclude that BFS finds the shortest path from s->v, for v∈V.

BreadthFirstSearch (last edited 2004-10-19 22:34:20 by yakko)