🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101

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. 1

    Grid model

    A 2D array of nodes {row, col, isWall, weight, distance, previous}.

  2. 2

    Drawing

    Handle mousedown/mouseenter/mouseup to toggle walls; drag the start and end nodes.

  3. 3

    BFS

    Queue from start, mark visited, record the visit order; stop at the end node.

  4. 4

    Dijkstra

    Use a min-heap (write a small binary heap) keyed by distance; supports weighted cells.

  5. 5

    A*

    Priority = distance + Manhattan distance to the end; compare visited counts with Dijkstra.

  6. 6

    Animate

    Play the visit order with a delay, then trace back via previous to draw the path.

  7. 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