CONSTRUCTING RED-BLACK TREE SHAPES
Cormen et al. describe efficient algorithms for inserting nodes into and deleting nodes from red-black trees. If some binary trees satisfying the definition of red-black trees cannot be built by these algorithms, then theoretical analyses of red-black trees that consider all binary trees satisfying the definition of red-black trees may not accurately describe the behavior of red-black trees in practice. We show that any binary tree shape that satisfies the definition of red-black trees can be built using only the insertion algorithm, RB-INSERT, of Cormen et al. We first describe an algorithm, RB-SHAPE, which, given any red-black tree T, will construct an insertion sequence for T. When the constructed sequence of insertions is performed on the empty tree using RB-INSERT, the result is a red-black tree with the same shape as T. We then prove the correctness of algorithm RB-SHAPE.