Problem: Begin at start and visit all possible
locations in order of their distance from start.
Solution: Replace the stack of DFS with a queue Q. Begin by
pushing start onto Q.
While (!Q.empty()) { push the unvisited neighbors of Q.front() onto Q, then Q.pop(); }
Variations:
Find the distance from start to goal.
Find a shortest path from start to goal.
|