Red-black (RB) trees are one of the most efficient variants of balanced binary search trees. However, they have always been blamed for being too complicated, hard to explain, and not suitable for pedagogical purposes. In the pioneering work of Guibas & Sedgewick (1978), both 2-3 and 2-3-4 variants of RB trees had been considered, but further study of the former had been abandoned due to the higher number of rotations in the insert algorithm. Sedgewick (2008) proposed a variant of 2-3 RB trees, viz. left-leaning red-black (LLRB) trees, in which red links are restricted to left children. He proposed recursive concise insert and delete algorithms. However, the top-down deletion algorithm of LLRB is still very complicated and highly inefficient. In this paper, we reconsider 2-3 red-black trees in which both children of a node cannot be red. We propose a parity-seeking delete algorithm with the basic idea of making the deficient subtree on a par with its sibling: either by fixing the deficient subtree or by turning the sibling deficient as well, ascending deficiency to the parent node. Interestingly, the proposed parity-seeking delete algorithm works for 2-3-4 RB trees as well. Our experiments show that, despite having more rotations, 2-3 RB trees are almost as efficient as RB trees and twice faster than LLRB trees. Besides, RB trees with the proposed parity-seeking delete algorithm have the same number of rotations and almost identical running time as the classical delete algorithm. While being extremely efficient, the proposed parity-seeking delete algorithm is easily understandable and suitable for pedagogical purposes.
翻译:红黑色树( RB) 是平衡双层搜索树中最高效的变体之一。 但是, 红黑色树总是被指责过于复杂、 难以解释、 不适合教学目的。 但是, 在Guibas & Sedgewick (1978)的开创性工作中, 考虑了RB树的2-3 和 2-3-4 的变体, 但是由于插入算法中的轮换次数较多, 对红黑色树的进一步研究已经放弃了。 Sedgewick (2008) 提议了一个2-3 RB树的变体, 即左斜红黑色树, 红树的变种仅限于留子。 他提议将红树的变种直线插入和删除算法。 但是, 将LLLRBB的自上而下的删除算法仍然非常复杂和低效率。 在本文中, 我们重新考虑了2-3 红树的变种树的变种, 我们提议的一种求对等的算法, 其基本想法是将精细的子变换为平式的 RBR, : 要么是修补不全的子, 或将精细的递减为平级的平级的平级的平级,,, 将平级的平级的平级的平级的平级的平级的平级的平级的平级的平级,,,, 以正级的平级的平级的平级的平级的平级的平级, 的平级的树是双级的平级, 的平级的平级的平级的平级 的平级 。