Breadth-first search visits every reachable node in a graph in order of increasing distance from the starting node. It can be thought of as a ShortestPath algorithm for the special case where all edges have length 1.

Typical code for breadth-first-search:

{{{BFS(G, s):

}}}

If the queue is replaced by a stack, the algorithm becomes DepthFirstSearch. For a combined implementation of both breadth-first and depth-first search in C, see C/Graphs.


CategoryAlgorithmNotes CategoryProgrammingNotes

BreadthFirstSearch (last edited 2007-12-25 23:42:28 by localhost)