Data Structure 📂 Graph Algorithms · 6 of 6 21 min read

Pathfinding Lab — Visualise DFS, BFS, Dijkstra & Bellman-Ford on a Grid

An interactive shortest-path playground: set a start and end, draw walls (or generate a random maze), pick an algorithm, and watch the grid flood sky-blue as it explores, then trace the yellow shortest path. Instead of code, a live Effort meter and operations counter reveal how much more work Dijkstra and Bellman-Ford spend than BFS for the same result — while DFS wanders to a non-optimal path. Includes a how-to guide and an effort/optimality comparison table.

Pathfinding Lab

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.

Algorithm
Start End Wall Visited Shortest Path Speed
BFSAlgorithm
0Cells explored
Path length
0Operations
⚡ Effort spent idle
Pick an algorithm and press Visualise to measure its effort.

Guide

How to Play

🎮 Five Steps
1
Click Set Start, then click a cell — the green point is where the search begins.
2
Click Set End, then click a cell — the red point is the goal.
3
With Draw Walls active, click and drag across the grid to build blockers. Drag over a wall again to erase it. Or hit Random Maze.
4
Choose an Algorithm from the dropdown (DFS, BFS, Dijkstra, Bellman-Ford).
5
Press Visualise. Watch the sky-blue flood explore, then the yellow shortest path appear. Read the Effort meter to compare.
💡
Try This Comparison

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.


Reference

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.

AlgorithmShortest path?Effort (work)Effort tierBehaviour
DFSNot guaranteedO(V + E)LowDives deep, wanders far
BFSYes ✓O(V + E)LowEven ripple, layer by layer
DijkstraYes ✓O((V + E) log V)MediumLike BFS + a priority queue
Bellman-FordYes ✓O(V · E)HighRelaxes every edge, V−1 times
Floyd-WarshallAll pairs ✓O(V³)Very HighTriple loop: try every cell as a midpoint
Johnson'sAll pairs ✓O(V² log V + V·E)Very HighReweight 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.

🧮
The Takeaway

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.

You have completed Graph Algorithms. View all sections →