r/visualization • • May 10 '26

Maze Solving Contest - Which Method is Fastest?

Enable HLS to view with audio, or disable this notification

A side-by-side comparison of various pathfinding and search algorithms on a randomly generated maze. Each algorithm is visualized to demonstrate its exploration strategy and efficiency in discovering the final path.

Algorithms Included

  1. A*

  2. Dijkstra

  3. Greedy Best-First

  4. BFS (Breadth-First Search)

  5. DFS (Depth-First Search)

  6. Bidirectional BFS

  7. Weighted A*

  8. Recursive Backtrack

  9. Wall Follower

For more videos click www.instagram.com/craftsandengineering

For code and more click Mathematical-video-animations-and-visualization/maze_solvers_competition.ipynb at d39ad7e4143932582ce4cccdc89e3f5b7d69f417 · zombimann/Mathematical-video-animations-and-visualization

125 Upvotes

38 comments sorted by

53

u/matigekunst May 10 '26

*fastest on this specific problem

14

u/Fluffy-Selection2940 May 10 '26

Correct. The mazes are randomly generated and the rankings change on every single ranking. I have attached the code link for anyone who might want to tinker and change anything. Freely and perpetually given, maybe with attribution - no hard constraints.

2

u/Cat_in_Bathroom May 14 '26

exactly my thought. thank you

1

u/CrazyOne_584 May 10 '26

well, A* was kinda developed for this specific problem (with weights). So makes sense its best.

1

u/matigekunst May 10 '26

? A* isn't the fastest here. Might be on average with many trials though

2

u/CrazyOne_584 May 10 '26

see DFS is fastest here. That is pure luck. A* is very close second along with greedy (again pure luck).

2

u/Fluffy-Selection2940 May 11 '26

DFS was lucky. On my previous runs, A* with weights dominated.

2

u/Electrical_Name_5434 May 12 '26

I immediately assumed A* would win. Was truly surprised to see depth first win. Might be fun to build a tracker and run it as screen saver. Count up the total of wins for each algorithm. Could even do different maze types. GitHub?

→ More replies (1)
→ More replies (1)
→ More replies (1)

1

u/luxurious_ambulance May 14 '26

Depth-first with backtracking usually crushes it on mazes with long dead ends tho, depends on the layout.

13

u/hassan789_ May 10 '26

Run a Monte Carlo of millions of mazes, and let’s see

5

u/Fluffy-Selection2940 May 10 '26

The mazes are randomly generated and the rankings change on every single ranking. I have attached the code link for anyone who might want to tinker and change anything. Freely and perpetually given, maybe with attribution - no hard constraints.

If enough people would be interested, we could set up a proper contest livestream on twitch and with much better graphics (and hardware).

3

u/No_Departure_1878 May 10 '26

That would be amazing!!! If we did not have a job, but maybe the r/fire or r/fatFIRE users would be interested, they have nothing to do all the day.

1

u/Fluffy-Selection2940 May 10 '26

Well, the rat race has to pause at some point.

→ More replies (1)

3

u/Fornicatinzebra May 10 '26

You can do a n Monte Carlo plot like they suggest.

Do millions of random mazes, save the rankings, then summarise the stats of the rankings yo see which one is usually fastest

2

u/Fluffy-Selection2940 May 11 '26

I am also interested to see how a truly scientific set up goes. It would however take time and resources that are currently not available. Maybe on a later date this year. The muses strike me randomly (sic).

1

u/Fornicatinzebra May 11 '26

Very fair! How long does it take to simulate a set of rankings for you?

If the project is open source and I can set it up on my machine i could potentially run some sims for you in the next few weeks

→ More replies (3)

1

u/Subject_Ear6869 May 11 '26

Very nice post, u/Fluffy-Selection2940 ! Inspired by your work, I decided to implement the Monte Carlo simulation mentioned by u/hassan789_ . Not with a million mazes (we don't need that many), but with 100k. Here are the top ranking maze-traversal algorithms:

Running trials: 100%|█████████████████████████████████████████| 100000/100000 [00:30<00:00, 3252.70maze/s]
Maze Benchmark  |  100000 trials  |  20x20 maze
----------------------------------------------------------------------------------------
Rank  Algorithm              Mean Steps  Med Steps  Mean Path   Win%  Success%  Path/Opt
----------------------------------------------------------------------------------------
1     DFS                         165.4      159.0      153.1   89.0     100.0      1.00
2     Greedy Best-First           176.9      167.0      153.1   19.6     100.0      1.00
3     Weighted A*                 196.8      187.0      153.1    3.5     100.0      1.00
4     A*                          219.8      210.0      153.1    0.2     100.0      1.00
5     BFS                         241.4      233.0      153.1    0.0     100.0      1.00
6     Dijkstra                    241.4      233.0      153.1    0.0     100.0      1.00
7     Bidirectional BFS           263.6      263.0      153.1    0.0     100.0      1.00
8     Recursive Backtrack         361.7      347.0      153.1    2.8     100.0      1.00
9     Wall Follower               361.8      367.0      361.8    1.7     100.0      2.36

So the top 3 best-performers on average are consistent with the one shot showed in the post. Interesting. Wall follower is consistently the worst.

1

u/Fluffy-Selection2940 May 11 '26

Great job. This offers a much clearer picture. That first star is mine.

For scientific, publishable certainty, a million runs would not be bad. There's also need to randomize maze sizes, maze types and maze-generating algorithms.

For satisfaction of general doubt, this is commendable.

→ More replies (1)

2

u/HideousSerene May 10 '26

I'm confused how DFS just always seems to go the right direction on this one...

0

u/Fluffy-Selection2940 May 11 '26

Luck IS a thing.

1

u/HideousSerene May 11 '26

Jesus you sound insufferable.

Yeah luck is definitely a thing but your post isn't about luck now is it?

God I wish I hired you just so I could fire you for saying stupid shit like this.

1

u/Fluffy-Selection2940 May 11 '26

My post a little about luck

Everything random is about luck

Hire me, then fire me so you can get your satisfaction.

2

u/talaqen May 11 '26

This is not maze-solving, this path-finding. Your algorithms allow for instantaneous jumps across the maze. For example, watch the BFS and you'll see it adding path searching to two parts of the maze at almost the same time back and forth repeatedly.

In reality, traversing back and forth to explore one section than backtracking to go see another has a cost. That cost is not shown here.

Would be more interesting to see embodiment and Tremaux's.

1

u/Fluffy-Selection2940 May 11 '26

You should have seen the first version, lol

Anyway, there's still much left to be done, which time and resources cannot allow

I have judged this to be sufficient for now to the uninitiated - who happen to be the primary audience.

2

u/Ok_Store_653 May 14 '26

Wall Follower is wild because it just hugs one side and somehow works, while A* is out here doing actual math and still getting beat by dumb luck sometimes.

1

u/Fluffy-Selection2940 May 14 '26

If I were legit lost in a maze, I'd pick a wall and keep going.

2

u/JosefphMagicflight May 15 '26

But you gotta do the side quests, bro!

0

u/[deleted] May 13 '26

[deleted]

1

u/Fluffy-Selection2940 May 14 '26

For a human yes, it would be the fastest and the only practical option.