Developer

This experience deserves a bigger screen

The DSA Visualizer is designed for deep focus,
side-by-side code, and real-time execution insight.

On small screens, that level of clarity can't be preserved.

Open on a tablet (landscape) or desktop for the intended experience.

Desktop experience preview

Number of IslandsStep-by-Step Visualization

A classic grid DFS/BFS problem that simulates counting connected components.

Problem Statement

Given an m x n 2D binary grid grid which represents a map of "1"s (land) and "0"s (water), return the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically.

Approach

Iterate through every cell. If we encounter a "1", increment island count and start a DFS/BFS to mark all connected "1"s as visited (or turn them to "0").

Time & Space Complexity

Time complexity is O(M * N) where M is rows and N is cols. Space complexity is O(M * N) for the recursion stack/queue in worst case.

Interactive Visualization

Loading Interactive Visualizer...

Click "Play" or use arrow keys to step through the execution.