Refers to the number of times between two strings that have a minimum of edit operations required to turn into another.
Algorithm process
- A length of str1 or str2 of 0 returns the length of another string. if (str1.length==0) return str2.length; if (str2.length==0) return str1.length;
- Initialize (n+1) * (m+1) of the Matrix D, and let the first row and column values grow from 0 onwards.
- Scan two strings (N*m level), if: str1[i] = = Str2[j], record it with temp, 0. Otherwise, temp is recorded as 1. Then in the Matrix D[i,j] is assigned to D[i-1,j]+1, d[i,j-1]+1, d[i-1,j-1]+temp the minimum value.
- After the scan is complete, return the last value of the matrix D[n][m] that is their distance
- Calculate similarity formula: 1-The maximum value of their distance/two string length.
Levenshtein distance "Editing distance algorithm" string similarity algorithm