Paths & Grids
Grid topologies represent 2D cellular worlds with orthogonal and diagonal connectivity. Shortest path search on grids translates Dijkstra algorithm and BFS into coordinate matrices with terrain costs, waterlines, toroidal wraparound boundaries, and multi-source spreads.
Key Invariants & Rules
- Flat index translation: index = row · cols + col; row = floor(index / cols); col = index % cols.
- Dijkstra priority queue orders frontier nodes by cumulative distance distTo[v].
- Toroidal wrapping computes neighbor coordinates modulo grid dimensions: (r + dr + R) % R.
- Flood fill labels all reachable dry/open cells within the same connected component.
- Edge relaxation updates distTo[w] = distTo[v] + weight(v,w) whenever a strictly shorter path is found.
Must-Know Algorithms
Explores orthogonal neighbors to find unweighted shortest escape route.
Searches weighted terrain grids with elevation difference costs.
Directs every cell to its nearest exit via reverse multi-source Dijkstra.
Learning Path (7 Lessons)
Self-Check & Concept Review
1. When mapping a 2D grid cell (row, col) with C columns to a 1D array index, what formula is used?
2. Why does standard BFS find the shortest path in an unweighted grid maze, whereas DFS does not?
3. In a toroidal grid world (e.g. Mine Climbing), how are neighbor coordinates evaluated across the left boundary?
4. In Dijkstra algorithm on weighted grids, when is a node considered finalized?
5. What does flood fill compute on a binary island grid (e.g. Global Warming)?