Step 1 / 9The maze: 0 = open, 1 = wall (dimmed). We start BFS from cell (0,0).
Step 2 / 9Initialize BFS. Mark (0,0) as the starting cell (blue = current frontier).
Step 3 / 9Dequeue (0,0) (green = visited). Expand south to (1,0). Wall at (0,1) blocks east.
Step 4 / 9Dequeue (1,0). Expand south to (2,0). Walls block east at (1,1).
Step 5 / 9Dequeue (2,0). Expand east to (2,1) and (2,2). Wall at (3,0) blocks south.
Step 6 / 9Dequeue (2,1) and (2,2). Discover (3,2) southward and (1,2) northward.
Step 7 / 9Expand further. Discover (3,3), (3,4), and (0,2). Getting closer to the goal.
Step 8 / 9Expand frontier. We reach (4,4) — the goal! BFS guarantees shortest path.
Step 9 / 9Shortest path found (sky blue): (0,0)→(1,0)→(2,0)→(2,1)→(2,2)→(3,2)→(3,3)→(3,4)→(4,4). BFS finds the shortest path in an unweighted grid.