How to resolve the algorithm Levenshtein distance step by step in the EasyLang programming language
How to resolve the algorithm Levenshtein distance step by step in the EasyLang 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 EasyLang programming language
Source code in the easylang programming language
func dist s1$ s2$ .
if len s1$ = 0
return len s2$
.
if len s2$ = 0
return len s1$
.
c1$ = substr s1$ 1 1
c2$ = substr s2$ 1 1
s1rest$ = substr s1$ 2 len s1$
s2rest$ = substr s2$ 2 len s2$
#
if c1$ = c2$
return dist s1rest$ s2rest$
.
min = lower dist s1rest$ s2rest$ dist s1$ s2rest$
min = lower min dist s1rest$ s2rest$
return min + 1
.
print dist "kitten" "sitting"
print dist "rosettacode" "raisethysword"
You may also check:How to resolve the algorithm Filter step by step in the jq programming language
You may also check:How to resolve the algorithm Extreme floating point values step by step in the Raku programming language
You may also check:How to resolve the algorithm Chernick's Carmichael numbers step by step in the Mathematica / Wolfram Language programming language
You may also check:How to resolve the algorithm Create a file on magnetic tape step by step in the Phix programming language
You may also check:How to resolve the algorithm World Cup group stage step by step in the Perl programming language