SimulatorEducationDeveloperEntertainment

Pathfinding Visualizer

Watch BFS, DFS, Dijkstra and A* explore a grid in real time. Paint walls, drop weighted terrain, and compare which algorithm visits fewer cells while still finding the shortest path.

Algorithm

Paint mode

Animation speed20 cells/frame
Visited 0Path —

Four algorithms, one grid

AlgorithmFrontierOptimal?Notes
BFSFIFO queueYes (unweighted)Expands like a flood; ignores costs.
DFSLIFO stackNoDives along one branch until it dead-ends.
DijkstraMin-heap by g(n)YesRespects weights; explores in all directions equally.
A*Min-heap by g(n) + h(n)Yes (admissible h)Pulls toward the goal — usually fewest visits.

g(n) = cost so far, h(n) = estimate to the goal. This tool uses Manhattan distance as the heuristic, which is admissible on a 4-connected grid.

Weights matter

Paint a few amber weight cells in front of the goal and re-run each algorithm. BFS plows straight through because it counts steps. Dijkstra and A* route around them because they minimise total cost (each weight cell costs 5 instead of 1).

This single change is why most real route-planners are Dijkstra or A* variants: weighted edges capture terrain difficulty, traffic, fuel, time — anything that varies cell to cell.

Reading the visualization

  • Start and End: drag or paint to relocate.
  • Wall: impassable.
  • Weight ×5: passable but expensive.
  • Visited: cell the algorithm popped from its frontier.
  • Path: the shortest route reconstructed via parent pointers.

Things to try

  • Build a U-shape wall in front of the goal — watch DFS dive in and crawl out, while A* hops around.
  • Wall the goal off completely — every algorithm fills the entire reachable area before giving up.
  • Same maze, all four algorithms — use "Instant" to compare visited cell counts at a glance.
  • Random maze — generates scatter walls plus weighted patches for varied terrain.