BFS
Explore a graph one ring at a time, so the first time you reach a node is guaranteed to be by the fewest possible steps.
After this lesson you will be able to
- Describe a graph as nodes and edges, and store it as an adjacency list.
- Explain why a queue makes the search spread outward level by level.
- Compute shortest distances (in number of edges) from a start node, and rebuild the actual path.
- Run BFS on a grid, treating each cell as a node, and start it from many sources at once.
- State BFS's cost as O(V + E) and explain where each part comes from.
Before you start. You should know lists, dictionaries and sets. Stacks and Queues explains the queue used here; Graphs introduces the vocabulary.