Third edition of Artificial Intelligence: foundations of computational agents, Cambridge University Press, 2023 is now available (including the full text).
3.5.2 Breadth-First Search
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 stage.
These are the paths containing two arcs and starting at o103. These five paths are the next elements of the frontier chosen, at which stage the frontier contains the paths of three arcs away from o103, namely,
Note how each of the paths on the frontier has approximately the same number of arcs. For breadth-first search, the number of arcs in the paths on the frontier always differs by, at most, one.
Suppose the branching factor of the search is b. If the first path of the frontier contains n arcs, there are at least bn-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
- space is not a problem;
- you want to find the solution containing the fewest arcs;
- few solutions may exist, and at least one has a short path length; and
- infinite paths may exist, because it explores all of the search space, even with infinite paths.
It is a poor method when all solutions have a long path length or there is some heuristic knowledge available. It is not used very often because of its space complexity.