Jump to content

Levenshtein distance: Difference between revisions

m
(added RPL)
Line 5,658:
|}
"kitten" "sitting" <span style="color:blue">LEV</span>
"Summer" "Winter" <span style="color:blue">LEV</span>
"Levenshtein" "Levenshtein" <span style="color:blue">LEV</span>
{{out}}
<pre>
Line 5,670:
===Iterative implementation (Wagner-Fischer algorithm)===
 
index of arrays and strings start with 1 in RPL, so the main trick in translating the algorithm given by Wikipedia was to manage the offsets properly. The distance between "rosettacode" and "raisethysword" is within the reach of a HP-28Scalculator (emulated or not), unlike the above recursive approach.
{{works with|HP|48}}
{| class="wikitable"
Line 5,697:
<span style="color:blue">LEV2</span> ''( "a" "b" → distance )''
declare int d[0..m, 0..n] and set each element in d to zero
for h from 1 to m: <span style="color:grey>"// h replaces i, which is √-1 in RPL</span>
d[h, 0] := i <span style="color:grey>"// RPL array indexes start with 1</span>
for j from 1 to n:
d[0, j] := j
1,151

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.