VFlash: Fast, Accurate Visual Planning via Flash Primitive Decoding
u_Unrolled
DSA for AI/ML · Module 08: Recursion and backtracking

Lesson 8.8 of 10 in this module Unrolled Pro

Word Search

Is a word spelled by a path of adjacent grid cells, each used once? From building every path of the right length and comparing at the end, to depth-first search that stops at the first wrong letter, to marking cells in place, a letter-count pre-check and starting from the rarer end of the word, which turns hopeless searches into instant answers. Then many words at once with a trie, iterative flood fill for connected regions of a segmentation mask, diagonal moves, and when cells may be reused.

about 15 min 5 Python examples 2 quick checks

Problem. Given an m × n grid of letters and a word, return whether the word can be formed by a path of cells that are horizontally or vertically adjacent, using each cell at most once.

text
A B C E
S F C S          "ABCCED" → True     "SEE" → True     "ABCB" → False (would reuse B)
A D E E

This is backtracking on a grid: the choices at each step are the four neighbours, and the "used" set is the path itself. The search space is huge (4 · 3^(L−1) paths per starting cell for a word of length L), so everything depends on pruning early.

ML context. Grids are images, maps and attention matrices. The same depth-first search with a visited mark finds connected regions: blobs in a segmentation mask, connected components in an occupancy grid, clusters of active cells in a feature map (Change B). There, the depth can reach the number of pixels, so the recursion must become an explicit stack.


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 "Word Search"

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