Shortest-Path Visualiser — DFS · BFS · Dijkstra · Bellman-Ford
Set a start and end, draw walls, pick an algorithm, and hit Visualise. The grid floods sky-blue as the algorithm explores ("full working"), then traces the path in yellow. No code here — instead, the Effort meter shows how much work each algorithm spends to reach the same answer.
How to Play
Build one wall layout, then run each algorithm in turn without resetting the walls (use Clear Path between runs). Notice that BFS, Dijkstra, and Bellman-Ford all find the same shortest path — but the Operations count and Effort meter climb dramatically. DFS is cheap to run but its path usually wanders and isn't the shortest.
How Much Effort Each Algorithm Uses
On an unweighted grid (every step costs 1), all four can be compared on two things: does it find the shortest path, and how much work does it spend getting there? V = open cells, E = connections between them.
| Algorithm | Shortest path? | Effort (work) | Effort tier | Behaviour |
|---|---|---|---|---|
| DFS | Not guaranteed | O(V + E) | Low | Dives deep, wanders far |
| BFS | Yes ✓ | O(V + E) | Low | Even ripple, layer by layer |
| Dijkstra | Yes ✓ | O((V + E) log V) | Medium | Like BFS + a priority queue |
| Bellman-Ford | Yes ✓ | O(V · E) | High | Relaxes every edge, V−1 times |
| Floyd-Warshall | All pairs ✓ | O(V³) | Very High | Triple loop: try every cell as a midpoint |
| Johnson's | All pairs ✓ | O(V² log V + V·E) | Very High | Reweight once, then Dijkstra from every cell |
The first four are single-source (one start). Floyd-Warshall and Johnson's are all-pairs — they find shortest paths between every pair of cells at once. The game shows their start→end result, and the Effort meter reflects their full all-pairs cost, so you can see just how much more work they do for a single query.
Same grid, same shortest path — wildly different cost. BFS is the sweet spot for unweighted grids. Dijkstra earns its extra cost only when edges have different weights. Bellman-Ford spends the most, but it's the only one that tolerates negative weights and can flag negative cycles. DFS is fast but takes whatever path it stumbles into.