I've looked at different papers and here is the information that I've gathered:
- SGI implementation and C cords neither guarantee O(1) time concatenation for long ropes nor ~log N depth for shorter ones.
- Different sources contradict each other. Wikipedia claims O(1) concatenation. This page says that concatenation is O(1) only when one operand is small and O(log N) otherwise.
So, what is the time complexity of concatenation? When exactly rebalancing is performed to ensure this concatenation complexity while maintaining tree balance? Are some specific usage patterns assumed when talking about this complexity?
log(N)
time complexity. Rope essentially is a Binary Search Tree composed of implicit keys, which are in nature refer to the size of the subtree. That allows powerful operations such concat/split. One of the possible implementations is using a Treap data structure, which is purposefully made to work with implicit keys and with high probability keeping the height of the tree withing4*log(n)
range, which isO(log n)
. I have done some simple implementation of it using Treap: ideone.com/uMt0Mi. – Understructurelog N
complexity. It appears thatO(1)
concatenation is a misconception spread by some people, doing it inO(log N)
is trivial. I've glanced at your code, but it doesn't seem to fit rope implementations: if you use parent pointers you must clone the whole tree (inO(N)
time) when doing local changes. The point of ropes is that they avoid that. – Orlanthaprocess
method. – Understructure