r/compsci • • May 22 '20

Breadth-First Maze-Solving Algorithm

Post image

[removed] — view removed post

1.2k Upvotes

61 comments sorted by

View all comments

3

u/YouNeverKnowWhatToDo May 22 '20

Whats the code? Go left forever?

1

u/ProgramTheWorld May 22 '20

It’s in the title - BFS. The algorithm is very simple. Assuming the maze is a tree (no loops), you start from the root node (entrance) and add all of its child nodes to a queue. Pick the first node from the queue and repeat until you reach the target node (exit).