AlgoScope

Flood Fill

AlgorithmbeginnerGraph Traversal

BFS or DFS on a grid, treating same-coloured neighbours as edges.

Decision · step 2 of 12Flood Fill: Fill a region
012301232200200111110010

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

Open in the player →or start at step 2

What you will see

Colour spreads across the grid from the start cell.

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.

Leads to

Topics that need this one first.

Taught by the same lesson

Flood Fill covers these too, in the same run.