Trace a breadth-first search
Use your thumb for spaces and keep your eyes on the next word. · 144 words
Breadth-first search explores a graph one step at a time. Imagine paths from a station to a park and a shop. Only the park connects directly to a lake. Starting at the station, the search explores places one edge away before places two edges away. Its first route to the lake uses two edges.
Draw a circle for each place and put the station in a queue, a list where the oldest entry leaves first. Remove the station and add its neighbors. When you remove the park, add the lake behind any remaining places at the same distance. Mark each place when it first enters the queue so a return path cannot add it repeatedly. If traveling one edge takes an hour and another takes a minute, the fewest edges can still mean the longer trip. Edge costs determine which question this search answers.
Check your recall
When does this procedure find a minimum-cost route?
Check your answer
When every edge has the same positive cost, minimizing the number of edges minimizes cost.
Sources and credits
Original KeyTouch lesson. Background reading · UC Berkeley · Introduction to Artificial Intelligence.