Dijkstra (Grid)
GraphsavgO((V + E) log V)worstO((V + E) log V)spaceO(V)
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
Start at (7, 2) with distance 0; every other cell is unknown (∞)
1 / 406
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
Dijkstra's algorithm always expands the open cell with the smallest known distance, so on a weighted grid it finds the cheapest path rather than the one with fewest moves. Entering a cell costs its weight (the mud patches here cost 5), and the optimal route detours around them when that is cheaper.
Complexity
- Best
- O(1)
- Average
- O((V + E) log V)
- Worst
- O((V + E) log V)
- Space
- O(V)