What will you explore?

Back to Home

Pathfinding Algorithms

Compare routes on a four-direction grid. Terrain costs apply when entering a tile: plain 1, medium 3, high 8.

1–100 visualization steps per second.

Choose a tool, then click or focus a tile and press Enter. Use the arrow keys to move between tiles. Walls block movement; diagonal moves are disabled.

Ready

Tile cost: 1 / 3 / 8

Elapsed visualization time: 0.00 s

This includes playback delays and shows how long the animation took. It is not raw algorithm performance.

S: start · G: destination · ■: wall · 3 / 8: terrain cost · O: frontier · V: visited · C: current · striped green: final path

Nodes visited
0
Path length (steps)
—
Path cost
—

Breadth-First Search

Explore layer by layer. BFS finds a route with the fewest moves when every move has equal cost; it ignores terrain weights when choosing the route.

Unweighted shortest path by number of moves; terrain weights do not affect route choice.

Time complexity: O(V + E) · Space: O(V)

Algorithm tradeoffs
AlgorithmTimeSpaceHow it chooses
Breadth-First SearchO(V + E)O(V)Unweighted shortest path by number of moves; terrain weights do not affect route choice.
Dijkstra's algorithmO(V²) with the grid open-set scanO(V)Weighted shortest path; enters medium and high terrain at costs 3 and 8.
A* SearchO(V²) with the grid open-set scanO(V)Weighted shortest path guided by Manhattan distance; optimal for these four-direction moves and positive terrain costs.