UtilityToolsLab

© 2026 UtilityToolsLab. Built and maintained by the UtilityToolsLab Team.

Free eBooks·About·Changelog·Privacy Policy·Terms of Service·Report a bug
HomeCompetitive ProgrammingPath Finder

Related Tools

Code FormatterMatrix GeneratorComplexity CalcBit VisualizerBitmask PlannerPrime FactorsMEX CalcInterval MergerMatrix RotationPBDS GeneratorSegment TreeGraph VisualizerStress TesterModulo CalcConvex HullOffline JudgeBig-O AnalyzerCombinatoricsDP Table BuilderExtended GCDSieve VisualizerBinary SearchSorting VisualizerSparse Table RMQUnion-Find DSU

Grid / Matrix Path Finder

Paint walls on an N×M grid, set start and end cells, then run BFS to visualize the shortest path. Copy the grid as a C++ 2D vector instantly.

You Might Also Like

All Competitive Programming

Graph Visualizer

Paste CP-style edge lists and watch a force-directed graph build itself. Drag nodes, toggle directed and 0/1-indexed, then copy the adjacency list.

Matrix Generator

Generate grid/matrix inputs for competitive programming. Random, zeros, identity, or sequential fill. Outputs in multiple formats.

Matrix Rotation

Input a 2D matrix, choose 90°/180°/270° CW or CCW rotation. See the visual index shift and get the C++ implementation.

Convex Hull

Click the canvas to place coordinate points. Renders the enclosing convex hull polygon live using Andrew's monotone chain. Outputs C++ points vector.

Breadth-first search finds a shortest path on an unweighted grid because it expands in rings, so the first time it reaches a cell it has arrived by the fewest possible steps. The Grid Path Finder draws those rings. Paint walls, drop a start and an end, and watch the frontier spread before the path is traced back through it.

Two colours carry the whole idea. Blue marks every cell the search visited, yellow marks the shortest path itself, and the gap between the two areas is the work BFS did that the answer did not need. On an open grid that gap is enormous, which is the honest picture of the algorithm.

Movement is 4-directional, up, down, left and right, with no diagonals, which is the standard convention for grid problems. Everything computes in the page and nothing is uploaded.

Getting a Path Across a Maze

  1. Set the grid to your dimensions. The default is 10 rows by 14 columns, and cell size shrinks automatically as columns grow so the board stays inside the panel.
  2. Pick 🧱 Wall and drag across the grid. Painting is continuous while the pointer is held down, so a corridor takes one stroke rather than 20 clicks.
  3. Switch to 🟢 Start and 🔴 End and place them. Each exists only once, so placing a new one clears the old.
  4. Run the search. Visited cells fill in blue and the path is traced in yellow, with a step count reported alongside.
  5. Use ⬜ Erase to open a wall and run it again. Watching the visited region change shape as you widen a gap is the fastest way to build intuition about the frontier.

Edge Cases: Walls, Gaps and No Path at All

  • An unreachable end is reported explicitly rather than as an empty result. The search exhausts every reachable cell first, so the blue region shows exactly which part of the grid the start can see.
  • Missing a start or an end produces nothing at all. BFS needs both endpoints, and there is no default corner.
  • A start adjacent to the end gives a path of 1 step and almost no visited cells, which is a useful sanity check that the step count means edges rather than cells.
  • Because movement is 4-directional, a diagonal gap between two walls is not a gap. Cells touching only at a corner are not neighbours here.
  • Every path of the same length is equally shortest, and BFS returns the one its neighbour ordering happened to find first. A different tie-break gives an equally correct path of identical length.
  • Walls painted over the start or end replace them, so check both markers are still on the board before reading a no-path result as meaningful.
Grid:
Start (S)
End (E)
Wall
Visited
Shortest Path

Copy Grid as C++ 2D Vector

vector<vector<int>> grid = {
    {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
};
// 0 = empty, 1 = wall