Breadth-first Search Algorithm

Breadth-first Search Algorithm visualized. Breadth-first search guarantees the shortest path. It runs much faster than this, but this is just a visualization for a game I am making. Looking forward to adding more pathfinding algorithms. Who knows? I might even open source the game. :eyes:

5 Likes

Cool! Does the underlying implementation utilize a queue or recursion?

1 Like

No recursion is used here to ensure the most efficient solution. There’s no reason to use recursion when you can iterate. Iteration is faster.

For Depth-first Search, it uses a stack which is a last-in, first-out data structure.

Breadth-first Search is the same exact thing as Depth-first Search but instead of the Frontier being a stack, it is now a queue. A queue is a first-in, first-out data structure.

1 Like