Your phone fixes "teh" to "the". git diff shows exactly which lines you changed. A biologist lines up two DNA strands to see where they differ. All three are the same question: what is the cheapest way to turn one string into another, using insertions, deletions and substitutions?
That minimum cost is the edit distance, and the matching it implies is a sequence alignment. Line the two strings up, slide in gaps where one has letters the other doesn't, and count the mismatches. Among all the ways to do it, you want the one with the fewest edits.
It sounds like you'd have to try a dizzying number of gap placements — and naively, you would. But this is one of the friendly problems: a small grid solves it exactly and fast. The twist comes later, when you try to align not two strings but many.
Comments
Loading comments...