Bölüm 5 · Simülatör

String Similarity: Levenshtein Distance

← Bölüm 5

Ready.

Dynamic Programming Table

Distance —
Similarity —
Progress 0%

Step Explanation

String Similarity: Levenshtein Distance

Fill the dynamic programming matrix step by step and see how insertion, deletion, and substitution costs determine edit distance.

How to use

  • Enter two strings (up to 12 characters each) and press Build Matrix.
  • Step Forward computes one cell, Auto Run fills the rest of the table, Reset rebuilds the matrix.
  • The yellow cell is being computed; the three blue cells are the values it is derived from.

Recurrence

D[i][j] is the edit distance between the first i characters of A and the first j characters of B. The first row and first column represent edit distance from or to the empty string (ε): D[i][0] = i, D[0][j] = j.

D[i][j] = min(D[i−1][j] + 1, D[i][j−1] + 1, D[i−1][j−1] + cost), where cost = 0 if A[i−1] = B[j−1] and 1 otherwise.

  • Deletion (from above): delete A[i−1].
  • Insertion (from the left): insert B[j−1].
  • Substitution / match (diagonal): replace or keep the character.

The bottom-right cell is the Levenshtein distance. Normalized similarity = (1 − distance / max(|A|, |B|)) × 100%.

Complexity

O(|A|·|B|) time. The full table needs O(|A|·|B|) space; keeping only two rows reduces it to O(min(|A|, |B|)) when only the distance is needed.