Skip to content

[FEATURE REQUEST] Levenshtein Distance #5195

@yurifilgueira

Description

@yurifilgueira

What would you like to Propose?

The Levenshtein distance algorithm calculates the minimum number of edits (insertions, deletions, or substitutions) needed to transform one string into another. It utilizes a matrix to store the distances between all prefixes of the two strings, and iteratively fills this matrix using dynamic programming. The final value in the matrix represents the Levenshtein distance between the two original strings.

Issue details

  • Implement the algorithm: Write a function levenshtein_distance(string1, string2) that accurately calculates the Levenshtein distance between two input strings.
  • Write tests: Develop comprehensive test cases to ensure the correctness of the implementation for various scenarios, including empty strings, identical strings, and strings with different lengths.
  • Provide documentation: Document the function's purpose, input parameters, return value, and time/space complexity. Include examples of usage and explanations of the algorithm's underlying principles.

Additional Information

The Levenshtein distance between two strings, a and b, of length |a| and |b|, respectively, is denoted as lev_{a,b}(i, j), where i and j represent the lengths of the prefixes of a and b being considered.

The equation is defined recursively as follows:

image

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions