Pathfinding Algorithm Visualizer

watch different search algorithms race across the same grid, frontier by frontier

Loading interactive simulation...

why heuristics matter 🖖

The formula f(n)=g(n)+h(n) makes A* prefer nodes that are cheap so far and still look close to the goal. If h never overestimates the remaining cost, A* keeps its shortest-path guarantee; a stronger admissible h explores fewer unnecessary cells. Switch the algorithm dropdown to see what happens when you drop the heuristic (Dijkstra), drop the cost-so-far (Greedy), or drop scoring entirely (BFS).

One loop, four personalities 🖖

All four algorithms run the exact same loop: pull the most promising cell off a waiting list (the amber frontier), mark it visited (indigo), then add its open neighbours back to the list. They differ only in how they decide which cell looks most promising. Takeaway: the expanded nodes count is the real scoreboard — fewer indigo cells means the algorithm reached the same goal with less wasted work.

Diagonals can break the guarantee 🖖

Turn on 'Allow diagonal' with the Manhattan heuristic and A* can quietly return a path that isn't the shortest. A diagonal step here costs only √2 ≈ 1.41, but Manhattan distance charges it as 2 — so the heuristic overestimates, becomes inadmissible, and the optimality guarantee is lost. Switch to Euclidean, which never overshoots the straight-line distance, and the shortest path comes back.

Example problems

  • open grid - Sparse obstacles produce a near-direct A* path with very few expansions.
  • maze-like - Dense obstacles force A* into longer detours and more expansions.
  • weak heuristic - A weaker heuristic explores far more cells before finding the same path.
  • dijkstra explores - Dijkstra ignores the goal and floods outward in every direction.
  • greedy trap - Greedy Best-First rushes toward the goal and can be lured into dead ends.
  • bfs + diagonals - BFS treats diagonal and orthogonal steps as equal cost, so its path can differ from A*'s.