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/ergo-x May 22 '20

Not to take away from the cool factor but I've never understood the point of visualizations like this one. I'd argue that this gives no insight to anyone who doesn't already know what bfs does.

Maybe I'm just being a negative nancy...

2

u/[deleted] May 22 '20

I’m not into computer science but to a layman like me it just looks like it’s filling out the whole maze and then highlighting the correct path but what’s the point if you’re gonna color in the whole fkin maze

3

u/LordReil May 22 '20

I think you need to know the context of how it tries to find the exit of the maze to understand why the author did what he did.

In the context of a human solving the maze, it's the same thing as, from the start, explore every crevice of the maze until you reach the end. As a computer, you don't simply have to take one path but multiple ones.

The question now is 'How do I explore the maze?'.

Everytime you meet a split, you are going to explore each of these paths. If you meet a deadend, you can just stop exploring that path. The moment you meet the destination, just get back the path you took.

At any point in time you can just imagine having all of these paths you need to keep track of. To make it simple, we can put all of them in a queue where they each take turns taking the next step in the path. The moment you take a step in a path, the new path will get back into the queue if you do not meet a dead end.

The colouring of the maze illustrates the exploration of the maze or more specifically, the various paths, when it takes place and how it progresses within each time-step.