next up previous
Next: Up: Previous:

Maintaining Size Field

RB Tree Insertion

1.
Traverse tree from root to leaf and insert the new node.
Add one to the size of each node visited during the traversal.
The size of the new node is 1.
Time: O(lg n)

2.
Traverse back up the tree changing colors and performing rotations (at most 2).
Only operation affecting sizes is rotation.
Time: O(lg n)


next up previous
Next: Up: Previous: