Matrix BFS (breadth-first search on a grid)
medium 18 minMatrix BFS explores a 2D grid in rings of equal distance from the start, using a queue.
Where it shows up
The same pattern appears across everyday software.
Game pathfinding on tile maps
Strategy and puzzle games move units across square tiles where each step costs the same. BFS from the unit gives the fewest moves to every tile, which is also how a game highlights the squares a unit can reach this turn.
Circuit board routing (Lee's algorithm)
Lee's 1961 maze-routing algorithm, still taught in electronic design, is matrix BFS: a wave spreads from one pin across the board grid, numbering cells, then the wire is traced back along decreasing numbers to the start.
Warehouse and vacuum robots
A robot on a floor plan divided into cells uses BFS to find the fewest moves to a shelf or a charging dock, treating racks and furniture as walls. Multi-source BFS from every dock tells each cell which dock is nearest.
Fire, flood and epidemic simulations
Cellular spread models start from every burning or infected cell at once and advance one ring per time step. That is multi-source BFS, the same loop as rotting oranges, and it reports when each cell is reached.
Image processing: distance transforms and paint bucket
The distance transform labels each pixel with its distance to the nearest edge pixel, which is the 01 matrix problem. The paint-bucket tool fills a connected region of similar colour, often with a queue-based flood fill.
Minesweeper reveal
Clicking an empty square in Minesweeper opens a whole region: the game spreads from that square to neighbouring empty squares (all 8 directions) and stops at numbered ones, a breadth-first flood over the board.