You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When we calculate the distance of OSADamerau–Levenshtein, we actually calculate the matrix with dimension(m*n)
Suppose we have a matrix looks like
the value in (3,0) is always 3
the value in (3,1) depends on (3,0) (2,0) (2,1)
the value in (3,2) depends on (3,1) (2,1) (2,2) and (1,1)
we can found that the value in (row : i) only depends values in (row:i-1,i-2)
eg. the value in (row : 3) only depends values in (row:2,1)
So any row number >= 3, we could write it in (row %3, j),
eg.
write the value of (3,0) in (0,0) .... (3,j) in (0,j)
write the value of (4,0) in (1,0) .... (4,j) in (1,j)
write the value of (i,0) in (i%3,0) .... (i,j) in (i%3,j)
In this way, we only need the matrix with dimension(3, min(m,n)) to calculate OSADamerau–Levenshtein distance
Here is the code to illustrate my idea
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
When we calculate the distance of OSADamerau–Levenshtein, we actually calculate the matrix with dimension(m*n)
Suppose we have a matrix looks like
the value in (3,0) is always 3
the value in (3,1) depends on (3,0) (2,0) (2,1)
the value in (3,2) depends on (3,1) (2,1) (2,2) and (1,1)
we can found that the value in (row : i) only depends values in (row:i-1,i-2)
eg. the value in (row : 3) only depends values in (row:2,1)
So any row number >= 3, we could write it in (row %3, j),
eg.
write the value of (3,0) in (0,0) .... (3,j) in (0,j)
write the value of (4,0) in (1,0) .... (4,j) in (1,j)
write the value of (i,0) in (i%3,0) .... (i,j) in (i%3,j)
In this way, we only need the matrix with dimension(3, min(m,n)) to calculate OSADamerau–Levenshtein distance
Here is the code to illustrate my idea
Beta Was this translation helpful? Give feedback.
All reactions