The graph is implicit — no adjacency list exists, neighbours are computed by (r±1, c) and (r, c±1). Scan every cell; each time you land on un-sunk land, that is one new island, so sink the whole component before the scan moves on.
"sink(r, c) is a flood-fill helper that mutates all connected land reachable from (r, c) into '0', effectively sinking the entire component."
"We mark grid[r][c] = '0' before recursing. If we waited, the first neighbor call (down) would immediately look up and call sink back on us, causing an infinite recursive loop!"
"When sink(0, 0) calls down to sink(1, 0), frame (0, 0) is suspended on the stack. It cannot advance to up, right, or left until the entire subtree under down returns."
"Time is O(m · n) since every cell is sunk once. Auxiliary space is bounded by the maximum call stack depth: O(m · n) in the worst case (a snake/spiral island filling the grid)."
before the four calls, not after — mark first, or the neighbours call straight back and the recursion never ends.