AlgoScope

Flood Fill

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

Graph traversal, algorithm, beginner
Cell 0, 0 is painted. 2 neighbours join the queue.012301232200200111110010
Cell 0, 0 is painted. 2 neighbours join the queue.012301232200200111110010

Flood Fill: Fill a region

Decision, step 2 of 12

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

Cost

Best
O(r * c)
Average
O(r * c)
Worst
O(r * c)
Space
O(r * c)

Leads to

Topics that need this one first.

Taught by the same lesson

Flood Fill covers these too, in the same run.