foundations of computational agents
In breadth-first search the frontier is implemented as a FIFO (first-in, first-out) queue. Thus, the path that is selected from the frontier is the one that was added earliest.
This approach implies that the paths from the start node are generated in order of the number of arcs in the path. One of the paths with the fewest arcs is selected at each iteration.
Consider the tree-shaped graph in Figure 3.5. Suppose the start node is the node at the top, and the children of a node are added in a left-to-right order. In breadth-first search, the order in which the paths are expanded does not depend on the location of the goal. The nodes at the end of the first sixteen paths expanded are numbered in order of expansion in the figure. The shaded nodes are the nodes at the ends of the paths of the frontier after the first sixteen iterations.
Consider breadth-first search from ${o}{\mathit{}}{\mathrm{103}}$ in the graph given in Figure 3.2. The only goal node is ${r}{\mathit{}}{\mathrm{123}}$. Initially, the frontier is $$. This is extended by ${o}{\mathit{}}{\mathrm{103}}$’s neighbors, making the frontier $$, $$, $$. These are the nodes one arc away from ${o}{\mathit{}}{\mathrm{013}}$. The next three paths chosen are $$, $$, and $$, at which stage the frontier contains
$$ | ||
$$ |
These are the paths containing two arcs starting at ${o}{\mathit{}}{\mathrm{103}}$. These five paths are the next paths on the frontier chosen, at which stage the frontier contains the paths of three arcs away from ${o}{\mathit{}}{\mathrm{103}}$, namely,
$$ | ||
$$ |
Note how in breadth-first search each path on the frontier has either the same number of arcs or one more arc than the next element of the frontier that will be selected.
Suppose the branching factor of the search is $b$. If the next path to be selected on the frontier contains $n$ arcs, there are at least ${b}^{n-1}$ elements of the frontier. All of these paths contain $n$ or $n+1$ arcs. Thus, both space and time complexities are exponential in the number of arcs of the path to a goal with the fewest arcs. This method is guaranteed, however, to find a solution if one exists and will find a solution with the fewest arcs.
Breadth-first search is useful when
the problem is small enough so that space is not a problem (e.g., if you already need to store the graph) and
you want a solution containing the fewest arcs.
It is a poor method when all solutions have many arcs or there is some heuristic knowledge available. It is not used very often for large problems where the graph is dynamically generated because of its exponential space complexity.