VFlash: Fast, Accurate Visual Planning via Flash Primitive Decoding
u_Unrolled
DSA for AI/ML · Module 11: Graphs

Lesson 11.2 of 16 in this module Unrolled Pro

Flood Fill

Recolour the connected region of same-coloured pixels around a starting pixel. From sweeping the whole image again and again until nothing changes (O((R·C)²) in the worst case), to a single breadth- or depth-first search from the start pixel that touches only the region (O(region)). Then the 'new colour equals old colour' trap, 8-connectivity, tolerance-based fills like a magic-wand selection, and the ML use: growing a segmentation mask from a seed pixel without hitting recursion limits.

about 10 min 4 Python examples 2 quick checks

Problem. An image is an R × C grid of integer colours. Starting from pixel (sr, sc), recolour it and every pixel connected to it (up, down, left, right) that has the same original colour, to new_color. Return the image.

text
image = 1 1 1        start (1, 1), new colour 2        2 2 2
        1 1 0                                          2 2 0
        1 0 1                                          2 0 1     (the bottom-right 1 isn't connected)

A grid is a graph: each pixel is a node, and edges join neighbouring pixels of the same colour. Flood fill is "find the connected component of one node", the simplest real use of BFS and DFS from lesson 11.1.

ML context. Region growing from a seed is a classic segmentation step: click a point, grow a mask over similar pixels (the "magic wand"), or clean up a predicted mask by filling holes and removing specks. Annotation tools, medical imaging and post-processing of segmentation models all run this, on images large enough that recursion fails (Change C).


1. Step 1: Clarify

That's the preview. Modules 00–01 are free; this lesson is part of Unrolled Pro.
Staff AI & Pro Tier Lesson

Unlock "Flood Fill"

The foundations are free forever. Unrolled Pro unlocks the complete lesson, production architectures, and 55 battle-tested ML system design case studies.

Everything included with Pro:
All 234+ Deep-Dive Lessons across transformer internals, inference, RAG & agents
55 Staff-Level ML & System Design Case Studies with mathematical capacity estimates
AI Engineer Sheet & Exercises with worked solutions, self-checks, and code
100 Landmark Research Papers guided walkthroughs & progress tracking
14-Day Money-Back Guarantee — 100% full refund if you aren't satisfied
View Plans & Unlock All Lessons

From ₹167/mo (~$2/mo) · Cancel anytime · Instant activation

100% Risk-Free: 14-day no-questions-asked money-back guarantee