Trace one breadth-first frontier

Keep the names of states and actions distinct. · 184 words

Breadth-first search (BFS) explores a graph in layers. The frontier is the set of discovered states not yet expanded. BFS keeps the frontier in a first-in, first-out queue, so nearer states are expanded first. Here is a museum gift-shop network: S is the entrance, A and B are rooms, C is a junction, D is a side room, and G is checkout. Edges are S-A, S-B, A-C, A-G, B-C, B-D, and C-G. Each edge costs one move.

Start with frontier [S] and visited {S}. Expanding S discovers A and B, giving [A, B]. Expanding A discovers C and G, giving [B, C, G]. Expanding B finds C already discovered and adds only D, giving [C, G, D]. BFS therefore discovers G at depth two through S-A-G, the shortest route in this graph. The visited set prevents cycles from causing repeated work. If D were the goal instead, BFS would reach it at depth two through S-B-D, because B is one move from the entrance. BFS is complete on a finite graph, but its memory use can grow quickly because it stores a wide layer.

Check your recall

After expanding S and then A in the gift-shop example, what is the frontier, and why is G reached in two moves?

Check your answer

The frontier is [B, C, G]. G is reached through S-A-G because it is first discovered when A, a state one move from S, is expanded.

Sources and credits

Original KeyTouch lesson. Background reading · UC Berkeley · Introduction to Artificial Intelligence.