DSA Lab

Grid pathfinding

A grid is a graph whose nodes are squares and whose edges join neighbours. BFS finds shortest paths when every step costs the same; A* adds a guess of the distance left, so it heads towards the goal and visits fewer squares.

Grid pathfinding: how it works

In this tool: bFS, DFS and A* through a maze. Put in your own values and watch it change. Each operation runs one step at a time and says in plain words what happened, with its calculation worked out. The code is shown in Python, C, C++ or Java with the line that just ran marked, and an Understand it panel gives the idea, why it works, the cost of each operation, common mistakes and a short quiz.

Lessons that use it

  • Graph traversal: BFS and DFS (Data Structures)Breadth-first search with a queue finds the fewest edges to every vertex; depth-first search goes deep with recursion.
  • Searching grids: BFS and A* (Algorithms)Treat a grid as a graph to find shortest paths through mazes and maps with BFS, then reach the goal faster with A*'s distance guess.
  • Graph patterns (Interview Prep)Grids are graphs: counting islands with DFS or BFS, shortest paths in unweighted graphs with BFS, and ordering tasks with topological sort.