Every time you type "recieve" and your phone quietly fixes it to "receive", something elegant has run in the background. That something is rooted in edit distance — the minimum number of single-character insertions, deletions, and substitutions needed to turn one string into another.
Edit distance was formalized by the Soviet mathematician Vladimir Levenshtein in 1965. Computing it for two strings of length takes time via dynamic programming — perfectly fine for one pair, but potentially slow when you need to check a query against a dictionary of millions of words.
The key insight is that you don't need to compute edit distance one pair at a time. Instead, you can build a nondeterministic finite automaton (NFA) from the query word such that the automaton accepts exactly the set of all strings within edit distance . That automaton can be run over every dictionary word in linear time in the word's length — no matter how long or complex the query. The result is fuzzy search that scales like a regular expression, not like an all-pairs distance matrix.
Comments
Loading comments...