AlgoScope

Number of Islands

PatternintermediateGraph Traversal

Count connected components on a grid with flood fill from every unvisited land cell.

Decision · step 3 of 18Flood Fill: Count the islands
01234012322000200110001010100

Island 1. Pop (0, 0). 2 neighbours still land: (1, 0), (0, 1). Paint and queue them.

Open in the player →or start at step 3

What you will see

Each island is flooded with its own number.

How flood fill works →

Cost

BestO(r * c)
AverageO(r * c)
WorstO(r * c)
SpaceO(r * c)

How you work with it here

play it through, step one change at a time, scrub to any step, run it on your own input, predict what happens next, try operations in any order.

Screen readers: Vertices announce name, neighbours and state (in queue, visited, current); each step announces which vertex is processed and which neighbours are discovered.

Reduced motion: Frontier and visited changes are crossfades; the traversal edge is emphasized without a travelling token.

Taught by the same lesson

Flood Fill covers these too, in the same run.