Most efficient way to calculate Levenshtein distance

后端 未结 6 427
傲寒
傲寒 2020-11-28 08:37

I just implemented a best match file search algorithm to find the closest match to a string in a dictionary. After profiling my code, I found out that the overwhelming major

6条回答
  •  粉色の甜心
    2020-11-28 09:14

    The Wikipedia article discusses your algorithm, and various improvements. However, it appears that at least in the general case, O(n^2) is the best you can get.

    There are however some improvements if you can restrict your problem (e.g. if you are only interested in the distance if it's smaller than d, complexity is O(dn) - this might make sense as a match whose distance is close to the string length is probably not very interesting ). See if you can exploit the specifics of your problem...

提交回复
热议问题