Pathfinding visualiser (BFS, Dijkstra, A*)
Draw walls on a grid and watch BFS, DFS, Dijkstra and A* search for the shortest path.
Intermediateâą 10â14 hoursđĒ 7 stepsJavaScriptReact (optional)Graphs
What you'll learn
- âGraphs on a grid
- âQueues, priority queues and heuristics
- âWhy A* explores fewer cells
What you'll build
- âClick and drag to draw walls
- âMove start and end points
- âBFS, DFS, Dijkstra, A*
- âWeighted cells and a random maze
Step-by-step guide
- 1
Grid model
A 2D array of nodes {row, col, isWall, weight, distance, previous}.
- 2
Drawing
Handle mousedown/mouseenter/mouseup to toggle walls; drag the start and end nodes.
- 3
BFS
Queue from start, mark visited, record the visit order; stop at the end node.
- 4
Dijkstra
Use a min-heap (write a small binary heap) keyed by distance; supports weighted cells.
- 5
A*
Priority = distance + Manhattan distance to the end; compare visited counts with Dijkstra.
- 6
Animate
Play the visit order with a delay, then trace back via previous to draw the path.
- 7
Maze
Generate a maze with recursive division or randomised DFS.
đ Make it stand out
- +Diagonal moves
- +Bidirectional BFS
- +Show the open set as a heat map