Compare two strings to see the minimum number of edits needed to transform one into the other.
Levenshtein distance, named after Soviet mathematician Vladimir Levenshtein who introduced it in 1965, counts the minimum number of single-character edits (insertions, deletions, or substitutions) needed to transform one string into another. Transforming "kitten" into "sitting" requires 3 edits, substitute k→s, substitute e→i, and insert g, giving a Levenshtein distance of 3. A distance of 0 means the strings are identical.
The standard algorithm uses dynamic programming, building a table where each cell represents the edit distance between prefixes of the two strings. Rather than trying every possible sequence of edits (which would be computationally explosive for longer strings), the table builds up the answer incrementally from smaller subproblems, giving an efficient O(m×n) time complexity where m and n are the string lengths, this is the same fundamental technique (dynamic programming) used across many classic computer science problems.
Levenshtein distance operates purely on character-level edits, unaware of word meaning or semantic similarity, "cat" and "bat" have a small edit distance despite being unrelated animals, while "cat" and "feline" have a large edit distance despite meaning almost the same thing. For semantic similarity (comparing meaning rather than spelling), embedding-based methods using cosine similarity are the modern standard. Edit distance remains the right tool specifically when you care about surface-level character similarity, typos, near-duplicates, and fuzzy string matching, not conceptual meaning.