问题
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