13-2 Join operation on red-black trees
The join operation takes two dynamic sets and and an element such that for any and , we have . It returns a set . In this problem, we investigate how to implement the join operation on red-black trees.
a. Given a red-black tree , let us store its black-height as the new attribute . Argue that and can maintain the attribute without requiring extra storage in the nodes of the tree and without increasing the asymptotic running times. Show that while descending through , we can determine the black-height of each node we visit in time per node visited.
We wish to implement the operation , which destroys and and returns a red-black tree . Let be the total number of nodes in and .
b. Assume that . Describe an -time algorithm that finds a black node in with the largest key from among those nodes whose black-height is .
c. Let be the subtree rooted at . Describe how can replace in time without destroying the binary-search-tree property.
d. What color should we make so that red-black properties 1, 3, and 5 are maintained? Describe how to enforce properties 2 and 4 in time.
e. Argue that no generality is lost by making the assumption in part (b). Describe the symmetric situation that arises when .
f. Argue that the running time of is .
a.
- Initialize: .
- : if in the last step the root is red, we increase by .
- : if is root, we decrease by .
- Each node: in the simple path, decrease by each time we find a black node.
b. Move to the right child if the node has a right child, otherwise move to the left child. If the node is black, we decease by . Repeat the step until .
c. The time complexity is .
RB-JOIN'(T[y], x, T[2])
TRANSPLANT(T[y], x)
x.left = T[y]
x.right = T[2]
T[y].parent = x
T[2].parent = x
d. Red. Call .
The time complexity is .
e. Same, if , then we can use the above algorithm symmetrically.
f. .