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

Lesson 11.12 of 16 in this module Unrolled Pro

Word Ladder

The fewest single-letter changes to turn one word into another, where every intermediate word must be in a word list. From comparing every pair of words to build the graph (O(N² · L)), to generating each word's neighbours by trying every letter at every position against a hash set (O(N · L · 26)), or grouping words by wildcard patterns like h*t; then BFS for the fewest steps, and bidirectional BFS that meets in the middle. Then returning the ladder, weighted edits, and finding spelling variants of a label in a vocabulary.

about 10 min 3 Python examples 2 quick checks

Problem. Given begin_word, end_word and a word_list, return the number of words in the shortest transformation sequence from begin to end, where each step changes exactly one letter and every word after the first must be in the list. Return 0 if there's none.

text
begin = "hit", end = "cog", word_list = ["hot", "dot", "dog", "lot", "log", "cog"]
hit → hot → dot → dog → cog          →   5

Words are nodes; two words are joined when they differ in exactly one letter. "Fewest steps" is BFS (lesson 11.1). The real work is building the edges cheaply: with 5,000 words, checking every pair is 12.5 million comparisons.

ML context. "Words one edit apart" is the neighbourhood structure behind spelling correction, candidate generation for fuzzy label matching (lesson 12.15 computes full edit distances), and data augmentation with near-miss tokens. The wildcard-bucket trick (Optimisation B) is a tiny version of how fuzzy search indexes group strings by shared patterns so that similar strings meet without comparing all pairs.


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 Ladder"

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