Complexity of edit distance (Levenshtein distance) recursion top down implementation

霸气de小男生 提交于 2019-12-04 15:01:27
AbcAeffchen

Your recursion formula:

T(m,n) = T(m-1,n-1) + T(m-1,n) + T(m,n-1) + 1
T(0,n) = n
T(m,0) = m

is right.

You can see, that every T(m,n) splits of into three paths. Due to every node runs in O(1) we only have to count the nodes.

A shortest path has the length min(m,n), so the tree has at least 3min(m,n) nodes. But there are some path that are longer. You get the longest path by alternately reduce the first and the second string. This path will have the length m+n-1, so the whole tree has at most 3m+n-1 nodes.

Let m = min(m,n). The tree contains also at least

different paths, one for each possible order of reducing n.

So Ω(2max(m,n)) and Ω(3min(m,n)) are lower bounds and O(3m+n-1) is an upper bound.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!