3

I don't have proof but i have gut feeling that , suppose s1 is string which needs to be converted to s2 then we can keep the largest common subsequence in s1 as it is and edit distance is number of elements we need to replace/remove/insert.

For example : s1 = "adjsjvnejnv"
              s2 = "djpppne"

Here LCS is "djne" , now we need to remove 3 element string "jnv" at right side of "djne" ,we can replace "sjv" with "ppp" in s1 and and we can delete "a" from s1. so total edit distance is 3+3+1 = 7 .

Idea is to replace or delete elements inbetween the elements of LCS and add or remove elements from right and left part of LCS .

I am not able to prove it . Can someone provide counterexample or proof ?

Note that i am not talking about LCS distance (which involves deletion and insertion) , i am talking about LCS and saying can we fill / replace / remove in between the sequence and left and right side of sequence .

user776627
  • 41
  • 2

1 Answers1

2

Yes, it is.
Both the Levenshtein and the LCS distances are part of a group of distances called edit distances.

  • LCS distance allows for insertion and deletions in the strings.
  • Levenshtein distance allows for insertion, deletion and substitution in the strings.

Both of them can be computed using the Wagner-Fischer algorithm (originally published by Damerau in 1964) which is a dynamic programming algorithm that computes the edit distance between two strings.
The only difference between the LCS distance and the Levenshtein distance will then be the 'cost function' to minimize used in the dynamic programming.

Nevertheless, the LCS is easier to compute than the Levenshtein distances, and there exists several LCS algorithms taking adavantage of properties of the cost function to improve dramatically the performances of LCS algorithms.

m.raynal
  • 2,983
  • 2
  • 21
  • 34