What is A* Pathfinding?
Find a shortest path faster by guiding the search toward the goal.
Type a tool name, format or task
Find a shortest path faster by guiding the search toward the goal. Interactive step-by-step animation with JavaScript code, complexity and front-end use cases.
Loading animation...
Find a shortest path faster by guiding the search toward the goal. Keep an open list and the cost so far (g) for each cell. Always expand the cell with the lowest g plus the estimated distance to the goal. Update neighbours whose cost improves, and stop when the goal is chosen. Time complexity: Depends on the estimate; far fewer cells than BFS. Space complexity: O(cells). Games, maps and drag-and-drop connectors in diagram editors.
Find a shortest path faster by guiding the search toward the goal.
Time: Depends on the estimate; far fewer cells than BFS. Space: O(cells).
Games, maps and drag-and-drop connectors in diagram editors.
No. This converter runs in your browser for ordinary use, so the input is not sent to a backend by this tool.
Keep working without searching again.
A* explores like Dijkstra but prefers cells that look closer to the goal (cost so far + straight-line estimate).
function aStar(grid, start, end) {const open = [start];const g = new Map([[key(start), 0]]);while (open.length) {open.sort((a, b) => f(a) - f(b)); // f = g + estimateconst cur = open.shift();if (same(cur, end)) return buildPath(cur);for (const next of neighbours(grid, cur)) {const cost = g.get(key(cur)) + 1;if (cost < (g.get(key(next)) ?? Infinity)) {g.set(key(next), cost);open.push(next);}}}}
Tip: use the arrow keys to step and the space bar to play or pause.