How to resolve the algorithm Levenshtein distance step by step in the 11l programming language
How to resolve the algorithm Levenshtein distance step by step in the 11l programming language
Table of Contents
Problem Statement
In information theory and computer science, the Levenshtein distance is a metric for measuring the amount of difference between two sequences (i.e. an edit distance). The Levenshtein distance between two strings is defined as the minimum number of edits needed to transform one string into the other, with the allowable edit operations being insertion, deletion, or substitution of a single character.
The Levenshtein distance between "kitten" and "sitting" is 3, since the following three edits change one into the other, and there isn't a way to do it with fewer than three edits:
The Levenshtein distance between "rosettacode", "raisethysword" is 8. The distance between two strings is same as that when both strings are reversed.
Implements a Levenshtein distance function, or uses a library function, to show the Levenshtein distance between "kitten" and "sitting".
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Levenshtein distance step by step in the 11l programming language
Source code in the 11l programming language
F minimumEditDistance(=s1, =s2)
I s1.len > s2.len
(s1, s2) = (s2, s1)
V distances = Array(0 .. s1.len)
L(char2) s2
V newDistances = [L.index + 1]
L(char1) s1
I char1 == char2
newDistances.append(distances[L.index])
E
newDistances.append(1 + min((distances[L.index], distances[L.index + 1], newDistances.last)))
distances = newDistances
R distances.last
print(minimumEditDistance(‘kitten’, ‘sitting’))
print(minimumEditDistance(‘rosettacode’, ‘raisethysword’))
You may also check:How to resolve the algorithm Delegates step by step in the TXR programming language
You may also check:How to resolve the algorithm File size step by step in the 8086 Assembly programming language
You may also check:How to resolve the algorithm Execute HQ9+ step by step in the Perl programming language
You may also check:How to resolve the algorithm Enumerations step by step in the zkl programming language
You may also check:How to resolve the algorithm Sorting algorithms/Heapsort step by step in the Draco programming language