Discovery Phase
We iterate through every cell. If we find land ('1') that hasn't been visited, we've found the start of a new island.
Loading...
Loading Curriculum...
Loading Subject...
Loading Topic...
Loading Lesson...
Loading Lab...
A fundamental problem in graph theory: identifying isolated regions in a grid. Each island is a maximal connected component of land cells.
We iterate through every cell. If we find land ('1') that hasn't been visited, we've found the start of a new island.
Upon finding new land, we use DFS to visit all reachable landmasses, marking them as visited so they aren't counted again.
In this simulation, we consider 4-directional connectivity (up, down, left, right). Diagonals do not connect landmasses.
DFS stops if we hit water ('0'), go out of bounds, or reach a cell that is already part of a discovered island.