Skip to content
Laviyx Learn

Try

Mini project

Pathfinding Visualizer (BFS, Dijkstra and A*)

An interactive grid where you draw walls and watch BFS, DFS, Dijkstra and A* search for a path, with the visited cells and the final shortest path animated step by step.

Intermediate 2–3 weeks 1–2 studentsUpdated

HTMLCSSJavaScript

The problem

Maps, games and delivery apps all need to find a good route between two points. Graph search algorithms do this, but they behave very differently. This project lets you draw a map and watch how each algorithm explores it, which makes the difference between them obvious.

Features to build

  • A grid with a start and an end cell that can be dragged
  • Draw and erase walls with the mouse, and add weighted cells such as 'mud' that cost more to cross
  • Run BFS, DFS, Dijkstra and A* and animate the cells each one visits
  • Draw the final path and show its length, its total cost and the number of cells visited
  • Generate a random maze with recursive backtracking
  • Clear the path but keep the walls, to compare algorithms on the same map

Build plan

  1. 1

    Model the grid as a graph

    Each cell is a node and its up, down, left and right neighbours are its edges. Store walls and weights in a 2D array.

  2. 2

    Write the algorithms

    Implement BFS with a queue, DFS with a stack, and Dijkstra and A* with a min-heap. Each returns the order cells were visited and a map of parents for rebuilding the path.

  3. 3

    Animate the result

    Colour the visited cells in order with a short delay, then trace the path from the end back to the start using the parent map.

  4. 4

    Add the heuristic

    For A* on a 4-direction grid use the Manhattan distance |dx| + |dy| multiplied by the lowest cell cost, so it never overestimates.

  5. 5

    Mazes and polish

    Generate mazes with recursive backtracking, and add controls for speed, algorithm choice and clearing.

Learn these first

Each part of the project is taught in one of these free lessons.

Make it stand out

  • Allow diagonal moves and switch A* to a matching heuristic
  • Bidirectional BFS
  • Compare all algorithms on one map in a results table
  • Load a small real map, for example a campus layout drawn as a grid

Viva and interview questions

Try to answer each one aloud before you open it.

  • Which of these algorithms guarantee the shortest path?

    BFS does when all moves cost the same. Dijkstra does with any non-negative costs. A* does when its heuristic never overestimates the real remaining cost. DFS does not; it just finds some path.

  • Why is A* usually faster than Dijkstra?

    Dijkstra explores in all directions by distance from the start. A* adds an estimate of the distance to the goal, so it explores cells towards the goal first and visits far fewer cells, while still finding the shortest path if the heuristic is admissible.

  • Why does Dijkstra fail with negative edge weights?

    It assumes that once a node is taken from the priority queue, its distance is final. A negative edge found later could make that distance shorter, which breaks the assumption. Bellman–Ford handles negative weights instead.

  • Why use the Manhattan distance as the heuristic?

    With only up, down, left and right moves, you need at least |dx| + |dy| moves to reach the goal, so it never overestimates. With diagonal moves you would use a different distance, such as the octile distance.

What to put in your project report

  1. Abstract: the problem, your solution and the result in one paragraph.
  2. Introduction and problem statement: who has the problem and why it matters.
  3. Requirements: the features (functional) and qualities such as speed and security (non-functional).
  4. Design: architecture diagram, database tables or data flow, and screen layouts.
  5. Implementation: the main modules and the most interesting code, explained.
  6. Testing: the test cases you ran, with inputs, expected and actual results.
  7. Results: screenshots or numbers that show the project working.
  8. Conclusion and future scope: what you achieved and what you would add next.

Your college may give its own format. Follow that first, and use this list to check nothing is missing.

All project ideas →