Search code examples
algorithmlevenshtein-distance

Levenshtein distance combination


LD = Levenshtein Distance

Just doing a few examples on paper, this seems to work, but does anyone know if this is always true?

Lets say I have 3 strings

BOT

BOB

BOM

LD(BOT,BOB) = 1

and

LD(BOB,BOM)=1

then

LD(BOT,BOM)=max(LD(BOT,BOB) , LD(BOB,DOM))=1

OR

BAAB

BBAB

BCCD

LD(BBAB,BAAB) = 1

and

LD(BBAB,BCCD)=3

then

LD(BAAB,BCCD)=max(LD(BBAB,BAAB), LD(BBAB,BCCD))=3

I'd like to know if this always applies.

That is,

LD(B,C) = max (LD(A,C),LD(A,B))


EDIT -- Added at 10/22/2009 7:08PM PST

I'm starting to think this holds for words of the same length, otherwise you can still do it but you have to add the absolute value of the difference in word length.

In essence LD(B,C) = max(LD(A,C),LD(A,B)) + abs(length(B)-length(C))


Solution

  • Doesn't work.

    LD("BOB", "BOT") == 1
    LD("BOT", "BOB") == 1
    
    LD("BOB", "BOB") == 0
    max(LD("BOB", "BOT"), LD("BOT", "BOB")) == 1
    
    0 != 1
    

    there are probably harder examples also...