0% found this document useful (0 votes)
9 views9 pages

Maze Problem-Search

The document describes solving a maze problem using the Breadth-First Search (BFS) algorithm. The solution path from A to N is outlined as [A, B, C, D, G, E, H, F, K, I, L, J, M, N], with a total cost of 13 nodes. The document provides a step-by-step visualization of the BFS process applied to the maze transformed into a graph.

Uploaded by

noreennazmrd123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views9 pages

Maze Problem-Search

The document describes solving a maze problem using the Breadth-First Search (BFS) algorithm. The solution path from A to N is outlined as [A, B, C, D, G, E, H, F, K, I, L, J, M, N], with a total cost of 13 nodes. The document provides a step-by-step visualization of the BFS process applied to the maze transformed into a graph.

Uploaded by

noreennazmrd123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Solve Maze Problem with BFS

Let’s say we have the following Maze to be solved

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:

Graph view of the maze

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.

The answer to the above ques on will be:

 Solu on: [A, B, C, D, G, E, H, F, K, I, L, J, M, N]

 Costs: 13 (there are 13 nodes to step to reach the end node from the start node)

You might also like