Interactive · Search Algorithms
Pathfinding Visualizer
Draw a grid — walls, and heavy cells that cost more to cross — then watch BFS, Dijkstra, and A* search for the shortest path. The counter shows how many cells each one settles: the whole point of A*’s heuristic is that it explores far fewer than Dijkstra while finding the same optimal path.
Click or drag to paint with the selected brush. Heavy cells cost 8× a normal step; walls are impassable.
BFS, Dijkstra, A* — same goal, different effort
- BFS treats every step as equal, so it finds the fewest-cells path but ignores the heavy cells — it will happily plough through mud.
- Dijkstra respects the weights and always returns the lowest-cost path, expanding outward by cost in every direction.
- A* is Dijkstra plus a Manhattan-distance heuristic that steers the frontier at the goal. Same optimal path, far fewer cells settled — press Compare all 3 to see the numbers side by side.
The clearest demo: paint a band of heavy cells across the middle, put the start and goal on opposite sides, and run each algorithm. BFS barges straight through; Dijkstra and A* detour around the expensive band; A* gets there having touched a fraction of the cells.
Where this shows up
A* on a grid is the standard pathfinding in games and robotics. On LK Forge, breadth-first search is the engine behind valid-path checks in puzzles like Color Lines. For the adversarial cousins — minimax, expectimax — see the Game AI Visualizer, and the write-up Six Games, Three Classic Algorithms. Everything here runs client-side; nothing you draw leaves your browser.
Frequently asked questions
What is the difference between BFS, Dijkstra and A*?
Breadth-first search (BFS) treats every step as equal cost, so it finds the path with the fewest cells but ignores weights. Dijkstra's algorithm accounts for cell weights and always finds the lowest-cost path, exploring outward by cost. A* is Dijkstra plus a heuristic — an estimate of the remaining distance to the goal — which steers the search toward the goal so it settles far fewer cells while still finding the same optimal path. The visualizer shows all three on the same grid with a cells-explored count.
Why does A* explore fewer cells than Dijkstra?
Dijkstra expands in every direction in order of distance from the start, with no idea where the goal is. A* adds an admissible heuristic (here, Manhattan distance) to each cell's priority, which biases the frontier toward the goal. Because the heuristic never overestimates the true remaining cost, A* is still guaranteed to find the optimal path — but it wastes far less effort on cells pointing away from the goal. On an open grid the difference is dramatic; behind walls the two converge.
What are the weighted (heavy) cells for?
Heavy cells cost more to move through — think mud, sand or traffic. BFS ignores them and may return a path that crosses many heavy cells; Dijkstra and A* route around them when the detour is cheaper than pushing through. Painting a band of heavy cells between the start and goal is the clearest way to see BFS and the weighted algorithms disagree.
Is this the same pathfinding used in games?
Yes — A* on a grid or navigation graph is the standard pathfinding in games and robotics, and Dijkstra and BFS are its unweighted and heuristic-free relatives. LK Forge's own puzzle games use breadth-first search for valid and shortest paths. This tool runs the textbook versions, in the browser, so you can watch the frontier and the path directly.