Levenshtein distance "Editing distance algorithm" string similarity algorithm

Source: Internet
Author: User

Refers to the number of times between two strings that have a minimum of edit operations required to turn into another.

Algorithm process

  1. 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;
  2. Initialize (n+1) * (m+1) of the Matrix D, and let the first row and column values grow from 0 onwards.
  3. 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.
  4. After the scan is complete, return the last value of the matrix D[n][m] that is their distance
  5. Calculate similarity formula: 1-The maximum value of their distance/two string length.

Levenshtein distance "Editing distance algorithm" string similarity algorithm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.