跳到主要内容

资源 · 指南或文章

Levenshtein Distance

讲解最小编辑距离(插入、删除和替换),以及如何用自底向上的动态规划表计算它。适合在包含经典字符串动态规划题的面试之前学习。

审核日期

打开原站: Levenshtein Distance (在新标签页中打开原网站)

练习这个主题以 技术 / 编程 模式打开练习面试官,然后在那里选择题目。

添加到路线图

把这个资源放进你正在跟进的路线图。它会作为你自己的补充资源显示;路线图的步骤不会改变,也不计入你已记录的步骤。

来源内容语言:英语

The Levenshtein distance is a string metric for measuring the difference between two sequences. Informally, the Levenshtein distance between two words is the minimum number of single-character edits (insertions, deletions or substitutions) required to change one word into the other. Mathematically, the Levenshtein distance between two strings a and b (of length |a| and |b| respectively) is given by where where is the indicator function equal to 0 when and equal to 1 otherwise, and is the distance between the first i characters of a and the first j characters of b.

PrepKit 概览

本概览由 PrepKit 编辑根据源代码仓库撰写并审核,并非资源本身的文字。

适合人群
来源未说明适用级别
形式
课程

涵盖内容

  • 给出递归的数学定义,以公式图片形式展示
  • 演算 kitten 到 sitting 的示例,需要三次编辑
  • 逐格解读 ME 到 MY 的 3x3 矩阵,区分删除与插入
  • 解释每个格子依赖三个相邻格子,并点出表格法(tabulation)这一技术
  • 展示一张含重叠子问题的决策图,以及一个更大的 Saturday 到 Sunday 矩阵

使用建议

这是 PrepKit 的学习建议,并非来源的说法。

在看图之前,先在纸上填写 Saturday 到 Sunday 的表格,然后编写代码并核对结果。之后大声解释三个相邻格子各自代表什么。

范围与局限

关键公式和矩阵都是外部图片,图片加载失败时单看文字很难理解。没有给出复杂度,除演算示例外也没有练习。

获取方式与形式

GitHub 上 trekhleb/javascript-algorithms(MIT)中的 README,图片托管在其他地方。英文,免费。

PrepKit 于 2026年10月2日 审核。 资源来源提交: 85293e3e2b88

本概览的依据
  • src/algorithms/string/levenshtein-distance/README.md

收录此条目的页面

订阅 PrepKit 通讯

可选。使用 PrepKit 并不需要订阅。

我们如何处理你的邮箱