Visual · solution-first · verifiable

Solve Mazes in Python with BFS and DFS

Every exercise is a perfect maze: there is exactly one path from start to goal. Run your code, watch the exploration order animate on the maze, and find out automatically whether your solution matches the reference.

LB

Oturum kontrol ediliyor…

How it works

The mazes are generated with labyrinth-py using depth-first search, Kruskal, Prim and Wilson. The same exercise always runs on the same maze instance, so the verification result stays stable.

You see three layers: the exploration trace (the cells your algorithm visited), the path you found, and — on demand — the reference solution. Invalid steps that try to cross a wall are highlighted.

Verification is fully automatic: does the path start at the start, reach the goal, move only between neighbours, never cross a wall, never visit a cell twice, and match the reference? How many cells you explored is measured too, so the difference between BFS and DFS becomes visible.

Your code runs in the Python interpreter inside the browser; nothing is sent to a server. The solution guide offers three levels of hints: maze logic, algorithm choice, and the reference code.

Frequently asked questions

Does this page send my code to a server?

No. The Python interpreter loads in the browser and the code runs on your device.

Why is my solution not verified?

The maze is perfect: there is exactly one path from start to goal. Your path has to be that exact path; crossing a wall or visiting a cell twice invalidates it.

Should I use BFS or DFS?

Both find a path. BFS finds the shortest path and explores fewer cells; DFS walks a stack and usually visits far more cells. Compare the explored counter to see the difference yourself.

Where do the mazes come from?

They are generated with the labyrinth-py package using DFS, Kruskal, Prim and Wilson. The generated catalog is committed to the repository so every run solves the same instance.

Open the data playground