Step 1: Start at (0,0), find land, begin BFS/DFS to mark connected land
[1↑,1,0,0,0]
[1,1,0,0,0]
[0,0,1,0,0]
[0,0,0,1,1]
Why: We found the first island starting point
Step 2: Visit neighbors of (0,0): (0,1) and (1,0) are land, mark visited
[X,X,0,0,0]
[X,1,0,0,0]
[0,0,1,0,0]
[0,0,0,1,1]
Why: Mark connected land to avoid recounting
Step 3: Visit neighbor (1,1), mark visited
[X,X,0,0,0]
[X,X,0,0,0]
[0,0,1,0,0]
[0,0,0,1,1]
Why: Complete marking first island
Step 4: Move to next unvisited land at (2,2), start BFS/DFS for second island
[X,X,0,0,0]
[X,X,0,0,0]
[0,0,↑1,0,0]
[0,0,0,1,1]
Step 5: Mark (2,2) visited, no connected neighbors
[X,X,0,0,0]
[X,X,0,0,0]
[0,0,X,0,0]
[0,0,0,1,1]
Why: Second island is a single cell
Step 6: Move to next unvisited land at (3,3), start BFS/DFS for third island
[X,X,0,0,0]
[X,X,0,0,0]
[0,0,X,0,0]
[0,0,0,↑1,1]
Step 7: Mark (3,3) and (3,4) visited as connected land
[X,X,0,0,0]
[X,X,0,0,0]
[0,0,X,0,0]
[0,0,0,X,X]
Why: Complete marking third island
Result: [X,X,0,0,0]
[X,X,0,0,0]
[0,0,X,0,0]
[0,0,0,X,X]
Number of islands = 3