Math 2.0

Computer science Definition

Edit distance

Builds on AlphabetStringMetric spaceHamming distance

Definition

Let Σ\Sigma be a finite alphabet and let Σ∗\Sigma^* be the set of finite strings over Σ\Sigma. An edit operation changes a string x∈Σ∗x \in \Sigma^* in one of these ways:

  1. insertion of one symbol of Σ\Sigma at some place in xx;
  2. deletion of one symbol of xx;
  3. substitution of one symbol of xx by a different symbol of Σ\Sigma.

The edit distance, or Levenshtein distance, d(x,y)d(x, y) of x,y∈Σ∗x, y \in \Sigma^* is the least number of edit operations that turn xx into yy.

Remarks

Example: d(abc,acd)=2d(abc, acd) = 2. Deleting bb and then inserting dd at the end turns abcabc into acdacd, so d≤2d \le 2. A single operation either changes the length or changes exactly one position, while abcabc and acdacd have equal length and differ in two positions, so d≥2d \ge 2.

Non-example: if only substitutions are allowed, the strings abab and bb are at no finite distance, since substitution never changes the length. That restricted distance is the Hamming distance, defined only for strings of equal length.

Since each operation can be undone by one operation, dd is symmetric, and dd is a metric on Σ∗\Sigma^*. For x=x1⋯xmx = x_1 \cdots x_m and y=y1⋯yny = y_1 \cdots y_n, let D(i,j)D(i, j) be the edit distance of the prefixes x1⋯xix_1 \cdots x_i and y1⋯yjy_1 \cdots y_j. Then D(i,0)=iD(i, 0) = i, D(0,j)=jD(0, j) = j, and D(i,j)=min⁡(D(i−1,j)+1, D(i,j−1)+1, D(i−1,j−1)+[xi≠yj]),D(i, j) = \min\bigl(D(i - 1, j) + 1,\ D(i, j - 1) + 1,\ D(i - 1, j - 1) + [x_i \ne y_j]\bigr), where [xi≠yj][x_i \ne y_j] is 11 if xi≠yjx_i \ne y_j and 00 otherwise. This gives d(x,y)=D(m,n)d(x, y) = D(m, n) in time O(mn)O(mn). Other edit distances use other sets of operations, for example adding the transposition of two adjacent symbols.

Reading path

To understand this page from the ground up, read these 19 pages in order. The foundations come first.

Show the path as a graph
Each page uses the pages above it. The colour of the bar on a box shows how strong the evidence is, and the box also gives it as text. The list has the same pages.
  • no evidence level
  1. Alphabet concept
  2. Element definition
  3. Hamming distance concept
  4. Proposition concept
  5. Real numbers object
  6. String concept
  7. Set definition
  8. Implication definition
  9. Predicate definition
  10. Ordered pair definition
  11. Existential quantifier definition
  12. Universal quantifier definition
  13. Cartesian product definition
  14. Subset definition
  15. Uniqueness quantifier definition
  16. Binary relation definition
  17. Function definition
  18. Metric space definition
  19. Edit distance definition

Further reading

  1. Web https://en.wikipedia.org/wiki/Edit_distance
  2. Web https://en.wikipedia.org/wiki/Levenshtein_distance
About this page
Tag4E3R6ZAFV7
URIm2://4E3R6ZAFV7
Kinddefinition
WritingW0 stub
MSC68W32, 68R15, 68P30
DefinesEdit distance
UsesAlphabet, String, Metric space, Hamming distance
Changed3 November 2026

Markdown · JSON · Edit on GitHub

What this page needs for W1

  • an inventory row: the row of the inventory that the node accounts for (0 of 1)
  • a source with a locator (0 of 1)

The writing levels say how complete the text of a page is. They do not measure its truth.

What links here

No page links to this page yet.