VFlash: Fast, Accurate Visual Planning via Flash Primitive Decoding
u_Unrolled
DSA for AI/ML · Module 12: Dynamic programming

Lesson 12.12 of 16 in this module Unrolled Pro

Edit Distance

The minimum number of insertions, deletions and substitutions that turn one string into another (Levenshtein distance). From recursing on the last characters with three choices (3^(m+n) without memory), to the (i, j) table where each cell takes the cheapest of delete, insert and substitute (O(m · n)), two rolling rows, and the list of edits by walking back. Then early exit when only small distances matter, custom costs, and word error rate, the edit distance over words used to evaluate speech recognition and OCR.

about 10 min 3 Python examples 2 quick checks

Problem. Given strings a and b, return the minimum number of operations to turn a into b, where an operation is insert a character, delete a character, or substitute one character for another.

text
a = "horse",      b = "ros"          →   3      (horse → rorse → rose → ros)
a = "intention",  b = "execution"    →   5

Like lesson 12.11's LCS, it's a two-sequence DP over prefixes. Look at the last characters: if they're equal, they cost nothing; otherwise the last operation was a deletion (of a's last char), an insertion (of b's last char) or a substitution.

ML context. Edit distance is the standard similarity for short strings: spelling correction and fuzzy label matching (lesson 12.15), deduplicating near-identical names, and evaluation: word error rate (WER) for speech recognition and character error rate (CER) for OCR are edit distances over words or characters, divided by the reference length (Change D).


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 "Edit Distance"

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