Back to Academy
dynamic programming
Edit Distance
Edit Distance (Levenshtein Distance) computes the minimum number of single-character operations (insertions, deletions, and substitutions) required to transform one string into another. A 2D DP table is built where dp[i][j] represents the edit distance between the first i characters of word1 and the first j characters of word2. This is fundamental to many string comparison applications.
Use Cases
- •Spell checkers and autocorrect systems for suggesting corrections
- •DNA sequence comparison and mutation analysis in bioinformatics
- •Fuzzy string matching in search engines and record linkage
Complexity Analysis
| Metric | Best | Average | Worst |
|---|---|---|---|
| Time | O(mn) | O(mn) | O(mn) |
| Space | O(mn) | ||
Visualization
| B | D | C | A | B | ||
|---|---|---|---|---|---|---|
0 | 0 | 0 | 0 | 0 | 0 | |
| A | 0 | 0 | 0 | 0 | 0 | 0 |
| B | 0 | 0 | 0 | 0 | 0 | 0 |
| C | 0 | 0 | 0 | 0 | 0 | 0 |
| B | 0 | 0 | 0 | 0 | 0 | 0 |
| D | 0 | 0 | 0 | 0 | 0 | 0 |
Implementation
Output
Click "Run Code" to see output...