Breadth-First Search (BFS)
How Breadth-First Search Works
1. Initialize
Add the start node to the queue and mark it as visited.
2. Visit Node
Remove the front node from the queue and explore its neighbors.
3. Add Neighbors
For each unvisited neighbor, mark as visited, set its previous node, and add to the queue.
4. Repeat
Continue until the end node is found or the queue is empty.
5. Reconstruct Path
Trace back from the end node to the start node to get the shortest path.
Key Concepts
Queue
BFS uses a queue to explore nodes in order of their distance from the start.
Layered Exploration
Nodes are visited level by level, ensuring the shortest path in unweighted graphs.
Shortest Path
BFS always finds the shortest path in unweighted graphs.
Legend
Start Node
Click and drag to move
End Node
Click and drag to move
Wall
Click to add/remove
Visited Nodes
Shortest Path
How to Use
1. Create Your Maze
Click or drag on the grid to add or remove walls
2. Position Start & End
Drag the green and red nodes to set start and end points
3. Visualize
Click "Visualize BFS" to find the shortest path
4. Experiment
Try different mazes and see how BFS finds the path
About BFS
Breadth-First Search (BFS) explores nodes in layers and always finds the shortest path in unweighted graphs.
Shortest Path
Always finds the shortest path in unweighted graphs
Layered
Explores nodes level by level
Simple
Easy to implement and understand
Breadth-First Search always finds the shortest path in an unweighted grid. "Queue" is used to explore nodes in order of distance.