Levenshtein Distance Algorithm better than O(n*m)?

前端 未结 4 641
说谎
说谎 2020-11-28 22:49

I have been looking for an advanced levenshtein distance algorithm, and the best I have found so far is O(n*m) where n and m are the lengths of the two strings. The reason w

4条回答
  •  自闭症患者
    2020-11-28 23:13

    If you only want the threshold function - eg, to test if the distance is under a certain threshold - you can reduce the time and space complexity by only calculating the n values either side of the main diagonal in the array. You can also use Levenshtein Automata to evaluate many words against a single base word in O(n) time - and the construction of the automatons can be done in O(m) time, too.

提交回复
热议问题