Practice Discrete Math

Algorithms / Grid Coordinate Reasoning

Least You Need to Know: Grid Coordinates, Neighbor Rules, and Unweighted Shortest Paths

Grid problems are geometry disguised as arrays. The reusable ideas are bounds checks, choosing the correct neighborhood model, and remembering that BFS solves unweighted shortest paths while visited-state tracking prevents the scan from bouncing forever.

The least you need to know

Key notation

(r, c) row and column coordinates
|r1-r2| + |c1-c2| Manhattan distance
BFS layer all cells at the same unweighted distance

Tiny worked example

  • In a maze where each step has equal cost, treat each open cell as a node.
  • Add edges to valid neighboring cells.
  • BFS expands layer by layer, so the first time you reach the target you have found a shortest path.

Common mistakes

How to recognize this kind of problem

Start practice