A* Search
GraphsavgO((V + E) log V)worstO((V + E) log V)spaceO(V)
Start at (7, 2): g = 0 and the Manhattan estimate to the end is 24
1 / 297
Draw
Size
Drag on the grid to draw. Grab the start or end cell to move it. Edits re-run the search from step 1.
How it works
A* is Dijkstra's algorithm steered by a heuristic: it expands the cell with the smallest f = g + h, where g is the cost so far and h is the Manhattan distance still to go. Because h never overestimates on a 4-connected grid, the first path to the end is still optimal, but far fewer cells are expanded on the way.
Complexity
- Best
- O(1)
- Average
- O((V + E) log V)
- Worst
- O((V + E) log V)
- Space
- O(V)