I have been looking at this simple python implementation of Levenshtein Edit Distance for all day now.
def lev(a, b):
"""Recursively calculate the Levenshtein edit distance between two strings, a and b.
Returns the edit distance.
"""
if("" == a):
return len(b) # returns if a is an empty string
if("" == b):
return len(a) # returns if b is an empty string
return min(lev(a[:-1], b[:-1])+(a[-1] != b[-1]), lev(a[:-1], b)+1, lev(a, b[:-1])+1)
From: http://www.clear.rice.edu/comp130/12spring/editdist/
I know it has an exponential complexity, but how would I proceed to calculate that complexity from scratch?
I have been searching all over the internet but haven't found any explainations only statements that it is exponential.
Thanks.