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

Lesson 11.3 of 16 in this module Unrolled Pro

Number of Islands

Count the groups of connected land cells in a grid. From running a fresh search from every land cell and comparing the regions it finds (O((R·C)²)), to one scan that starts a flood fill only at unvisited land and marks as it goes (O(R·C)), and the same count with union-find. Then the area of the largest island, islands appearing one cell at a time (union-find again, near O(1) per cell), and the ML use: counting and sizing the objects in a predicted segmentation mask.

about 10 min 4 Python examples 2 quick checks

Problem. Given an R × C grid of "1" (land) and "0" (water), return the number of islands: groups of land cells connected horizontally or vertically.

text
1 1 0 0 0
1 1 0 0 0        →   3
0 0 1 0 0
0 0 0 1 1

Lesson 11.2 filled one connected region. Counting all of them is the core connected components problem: every unvisited land cell found by a scan starts a new island, and a flood fill claims the whole island at once.

ML context. After a segmentation model predicts a binary mask, the first post-processing step is usually connected components: how many objects (cells in a microscope image, cars in a road scene, lesions in a scan), how big each is, and removing specks below a minimum area. scipy.ndimage.label and OpenCV's connectedComponents implement exactly this (Changes A and 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 "Number of Islands"

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