Red-Black tree: Split/Concatenate in log(n) time

我的未来我决定 提交于 2021-02-19 07:38:59

问题


According to Ron Wein your able to do split and concatenation of red-black tree's in O(log(n)) time. See his artikle: Efficient Implementation of Red-Black Trees with Split and Catenate Operations

However I'm still not convinced that the running time of split really is true.

The idea is that split uses worst-case log(n) concatenatations. These concat's is done fast as we can find the node, p, by remembering the p, from last concatenate.

The problem is that concatenation starts the fix-up (balancing) algorithm, which as far as I know takes O(log n) (see step 5 in the pseudo-code for concatenation). This gives me a running time of log(n)*log(n), as split will make worst-case log(n) concatenations.

Ron Wein, does not take the fix-up algorithm into count in his argumentation. What have i missed in my analysis, or is the algorithm wrong?


回答1:


In future. If any have the same problem again: Tarjan have some important differences in the algorithm compared to what Ron Wein does. I still haven't been able to see that Wein is correct in his algoritm, but Tarjan is. So I suggest you use his instead.

First important point is that the balancing algorithm cost O(log(d)) where d is the depth for which you start the balacing from. Tarjan's algorithm then differs by starting at the split-key and moving on the path to root. By do this, you will see that the the subtree's you concatenate have about same depth. Thus will "d" always be small. Thus it is can be done much faster.

A second thing is that Tarjan suggest that all nodes is augmented such that they know their rank (black depth of its subtrees+it self). By doing this, we are able to know which tree is biggest in O(1) time. It is also possible to find the difference in there height in O(1) time.

I suggest all to read Tarjans paper instead of Wein's



来源:https://stackoverflow.com/questions/29029894/red-black-tree-split-concatenate-in-logn-time

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