VFlash: Fast, Accurate Visual Planning via Flash Primitive Decoding
u_Unrolled
DSA for AI/ML · Module 13: Tries and strings

Lesson 13.3 of 6 in this module Unrolled Pro

Design Add and Search Words

A dictionary that supports adding words and searching with '.' wildcards that match any one letter. From matching the pattern against every stored word (O(N · L)), to a trie walked by depth-first search that branches only at the dots and only into children that exist, to pruning branches whose remaining word lengths can't fit. Then '*' wildcards that match any run of letters (memoised DFS), patterns with many dots, and recovering words from OCR output with unreadable characters, ranked by frequency.

about 10 min 4 Python examples 2 quick checks

Problem. Implement a structure with:

  • addWord(word): store a lowercase word;
  • search(pattern): return True if any stored word matches, where . matches any one letter.
text
addWord("bad"), addWord("dad"), addWord("mad")
search("pad")   →  False
search("bad")   →  True
search(".ad")   →  True
search("b..")   →  True
search("b...")  →  False     (no 4-letter word)

A trie handles exact letters by following one edge. A dot means "any edge": the walk branches into every existing child. That turns the walk into a depth-first search over the trie, but one that only explores paths that actually exist.

ML context. OCR and speech systems often know most characters of a word but not all: "c?t" where one letter was unreadable. Recovering the candidates is exactly this search, and ranking them by word frequency (or by a language model) picks the likely one (Change D). The same pattern lookup filters a vocabulary by shape, such as all 5-letter tokens ending in "ing".


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 "Design Add and Search Words"

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