BUILT-IN MATHEMATICA SYMBOL

performs a breadth-first scan (bfs) of the graph g starting at the vertex s and evaluates whenever occurs.

performs a breadth-first scan of the whole graph g.

## DetailsDetails

• BreadthFirstScan[g, s, {...}] visits vertices in the graph g connected to the vertex s in breadth-first order.
• In breadth-first order, all vertices adjacent to the currently visited vertex are visited first.
• BreadthFirstScan[g, {...}] performs multiple breadth-first scans starting from the first vertex in the vertex list of g, and then starts from the first vertex in the vertex list that has not been visited, effectively scanning each connected component.
• BreadthFirstScan[g, ...] gives a list representing a tree where is the predecessor of and where is the vertex list of g.
•  "DiscoverVertex" when vertices are discovered "UnvisitedVertex" when unvisited vertices are rediscovered "VisitedVertex" when visited vertices are rediscovered
• "DiscoverVertex"->fd calls when vertex u is discovered from visited vertex v at distance d from the start vertex s.
• "UnvisitedVertex"->fru calls when the unvisited vertex u is rediscovered from the visited vertex v.
• "VisitedVertex"->frv calls when the visited vertex u is rediscovered from the visited vertex v.
•  "PrevisitVertex" before a vertex is visited "PostvisitVertex" after a vertex has been visited
• "PrevisitVertex"->fs calls before the vertex u has been visited.
• "PostvisitVertex"->fe calls after the vertex u has been visited.
• A bfs-tree is the tree generated by the edges traversed during a breadth-first scan.
• Events that provide access to edge exploration from the visited vertex include:
•  "FrontierEdge" edge in the bfs-tree "CycleEdge" edge not in the bfs-tree
• "FrontierEdge"->ffe calls for an edge where the vertex v is being visited and u has not been discovered. Typically useful for scanning the bfs-tree.
• "CycleEdge"->fce calls for an edge where the vertex v is being visited and u has already been discovered. Typically useful for finding cycles or edges not in the bfs-tree.
• For an undirected graph the edges used in the callbacks are taken to be undirected edges .

## ExamplesExamplesopen allclose all

### Basic Examples (2)Basic Examples (2)

Visit the vertices of a tree in breadth-first order:

 Out[1]=
 Out[2]=

### Properties & Relations (4)Properties & Relations (4)

New in 8
New to Mathematica? Find your learning path »
Have a question? Ask support »