What is Levenshtein Distance (Fuzzy Search)?
Count the fewest single-letter edits needed to turn one word into another.
Type a tool name, format or task
Count the fewest single-letter edits needed to turn one word into another. Interactive step-by-step animation with JavaScript code, complexity and front-end use cases.
Loading animation...
Count the fewest single-letter edits needed to turn one word into another. Build a table whose edges are the cost of inserting or deleting all letters. Each cell is the cheapest of delete, insert or replace/keep from its neighbours. The bottom-right cell is the distance. Time complexity: O(m × n). Space complexity: O(m × n). Typo-tolerant search, 'did you mean', form validation and diff tools.
Count the fewest single-letter edits needed to turn one word into another.
Time: O(m × n). Space: O(m × n).
Typo-tolerant search, 'did you mean', form validation and diff tools.
No. This converter runs in your browser for ordinary use, so the input is not sent to a backend by this tool.
Keep working without searching again.
| s | i | t | t | i | n | g | ||
|---|---|---|---|---|---|---|---|---|
| k | ||||||||
| i | ||||||||
| t | ||||||||
| t | ||||||||
| e | ||||||||
| n |
Levenshtein distance counts the fewest single-letter edits (insert, delete, replace) to turn "kitten" into "sitting". It powers typo-tolerant ("fuzzy") search.
function levenshtein(a, b) {const dp = Array.from({ length: a.length + 1 }, (_, i) => [i]);for (let j = 1; j <= b.length; j++) dp[0][j] = j;for (let i = 1; i <= a.length; i++) {for (let j = 1; j <= b.length; j++) {const cost = a[i - 1] === b[j - 1] ? 0 : 1;dp[i][j] = Math.min(dp[i - 1][j] + 1,dp[i][j - 1] + 1,dp[i - 1][j - 1] + cost);}}return dp[a.length][b.length];}
Tip: use the arrow keys to step and the space bar to play or pause.