Projects › Intermediate
Pathfinding Visualizer
Draw walls on a grid and watch BFS, DFS, Dijkstra and A* find the path step by step — DSA you can show off.
Level: Intermediate · Time: 1 week · Tech stack: React, BFS, Dijkstra, A*
Features to build
- Grid with start, end and walls (click and drag)
- BFS, DFS, Dijkstra and A* with animation
- Weighted cells for Dijkstra/A*
- Maze generator (recursive backtracking)
- Speed control and stats (visited count, path length)
What you will learn
- Graph algorithms on grids
- Priority queues
- Heuristics (A*)
- Animating algorithm steps in React
Step-by-step guide
1. Grid as a graph
Each cell is a node; neighbours are up/down/left/right that aren't walls.
2. Record, then animate
Run the algorithm instantly and record the order cells were visited; then animate that list with setTimeout. This keeps the algorithm code clean.
function bfs(grid, start, end) {
const order = [], prev = new Map(), q = [start], seen = new Set([key(start)]);
while (q.length) {
const cur = q.shift(); order.push(cur);
if (same(cur, end)) break;
for (const n of neighbours(grid, cur)) if (!seen.has(key(n))) { seen.add(key(n)); prev.set(key(n), cur); q.push(n); }
}
return { order, path: buildPath(prev, end) };
}
3. Dijkstra and A*
Use a min-heap keyed by distance (Dijkstra) or distance + Manhattan heuristic (A*). Show how A* visits far fewer cells.
4. Performance
Update cells with CSS classes via refs during animation instead of re-rendering the whole grid on every step.
5. Maze generation
Recursive backtracking: carve passages from a start cell, visiting neighbours in random order.
6. Explain it
Add a sidebar explaining each algorithm's guarantees: BFS shortest (unweighted), DFS not shortest, Dijkstra shortest (weights ≥ 0), A* shortest with an admissible heuristic.
Level it up
- Bidirectional BFS
- Diagonal moves
- Compare algorithms side by side
On your resume
- Built an interactive pathfinding visualizer in React (BFS, DFS, Dijkstra, A*) with weighted cells, maze generation and step animation.