Maze Problem-Search
Maze Problem-Search
Example of a maze
What is the solu on and cost of the above Maze problem if we want to move from A to N?
Let’s answer that ques on in the BFS way. But to make the visualiza on easier, let’s transform the maze
into a graph:
Below is the step-to-step visualiza on of solving the search problem using the BFS algorithm:
Append A to the Fron er.
Append A to the Visited and BFS, then append A’s neighbor (B) to the Fron er. Finally, pop A from
the Fron er.
Append B to the Visited and BFS, then append B’s neighbor (C) to the Fron er. Finally, pop B from
the Fron er.
Append C to the Visited and BFS, then append C’s neighbor (D, G) to the Fron er. Finally, pop C from
the Fron er.
Append D to the Visited and BFS, then append D’s neighbor (E) to the Fron er. Finally, pop D from
the Fron er.
Append G to the Visited and BFS, then append G’s neighbor (H) to the Fron er. Finally, pop G from
the Fron er.
Append E to the Visited and BFS, then append E’s neighbor (F) to the Fron er. Finally, pop E from
the Fron er.
Append H to the Visited and BFS, then append H’s neighbor (K, I) to the Fron er. Finally, pop H from
the Fron er.
Append F to the Visited and BFS. Finally, pop F from the Fron er.
Append K to the Visited and BFS, then append K’s neighbor (L) to the Fron er. Finally, pop K from
the Fron er.
Append I to the Visited and BFS, then append I’s neighbor (J) to the Fron er. Finally, pop I from
the Fron er.
Append L to the Visited and BFS, then append L’s neighbor (M) to the Fron er. Finally, pop L from
the Fron er.
Append J to the Visited and BFS. Finally, pop J from the Fron er.
Append M to the Visited and BFS, then append M’s neighbor (N) to the Fron er. Finally, pop M from
the Fron er.
Append N to the Visited and BFS. Finally, pop N from the Fron er.
There you go! That is how you can perform step-by-step how to solve a maze problem using the BFS
algorithm.
Costs: 13 (there are 13 nodes to step to reach the end node from the start node)