TechRian
TechRian

Reputation: 1

Merging two Augmented Red Black Trees (Order Statistics Trees) in optimal time

I've been having trouble figuring out an optimal algorithm to match the lower bound on the following problem: merging 2 red-black trees, sizes m and n respectively, n > m. The red black trees here are assumed to be granted an augmentation, having the subtree sizes as stored information.

Using the decision tree approach, I can obtain a lower bound of m*log(n/m + 1), yet coming up with an elegant algorithm has surfaced many issues.

I have tried the following procedure, but came up with issues when analyzing its time complexity:

First, using the augmentation, select in the tree n the n/m, 2n/m, ..., (m-1)n/m values and store them in an array.

Then, split tree n using those values to obtain n/m different trees.

Then, merge each of the selected values to the smaller tree m inside a new list.

Using that new list, decide in which split subtree of size n/m to insert each element of tree m.

Finally, merge all n/m subtrees back in the original tree.

The main idea is that the middle process of inserting each element in a subtree yields precisely time O(m*log(n/m + 1)), and the merging of the selected elements to the smaller tree takes time O(m)

The big issues appear in the other 3 steps. Using the standard basic implementations in red black trees of select, split, join, it seems that I can't reduce the time complexity of those to anything smaller than O(n).

My question is whether there would be a property of RB trees I am missing in order to obtain the proper bound on the algorithm.

Upvotes: 0

Views: 37

Answers (0)

Related Questions