Finding unreachable sections of a 2D map
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.
In the field of computational geometry and robotics, identifying unreachable sections of a 2D map is a common problem. Such maps are used in various applications, including robotics navigation, geographic information systems (GIS), and video game development. This article delves into methods for detecting unreachable areas, the algorithms involved, and their practical applications.
Understanding 2D Maps
A 2D map can be represented as a grid, a graph, or a continuous plane. Each representation has specific advantages depending on the application:
- Grid Representation: In a grid, the map is divided into cells, which can either be open (traversable) or blocked (obstacles).
- Graph Representation: Nodes represent positions on the map, and edges represent possible paths between these positions.
- Continuous Representation: Paths can be any continuous line on the map, similar to maps used in GPS systems.
Algorithmic Approaches
Several algorithms can be employed to identify unreachable sections in these maps. The choice depends on the map's representation and the application's real-time requirements.
Breadth-First Search (BFS) and Depth-First Search (DFS)
Both BFS and DFS are graph traversal algorithms suitable for grid and graph representations. They can identify all reachable nodes from a given starting point:
- BFS: This algorithm explores the nearest nodes first and is particularly effective for finding the shortest path.
- DFS: It explores as far as possible along a branch before backtracking, which can be less efficient than BFS in finding reachable nodes but uses less memory.
Example
Consider a grid with cells marked as '0' representing open paths and '1' representing obstacles.
0 0 0 1 0 0 1 0 1 0 0 0 0 0 1 1 0 1 0 0
- Only cells (0, 0), (0, 1), (1, 0), (2, 0), (2, 1), (2, 2), (2, 3), and (3, 3) are reachable.
- The unreachable sections include areas fully enclosed by obstacles and with no path from the starting point.
Related reading
- Finding whether a point lies inside a rectangle or not
- Fingerprint matching/recognition algorithms/implementations
- First-Occurrence Parallel String Matching Algorithm
- First occurrence in a binary search
- First appearance in Stern's Diatomic Sequence
- Fit multivariate gaussian distribution to a given dataset
- fitting rectangles in the smallest possible area
- Fitting rectangles together in optimal fashion

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.