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 and proposed concise recursive 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 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-3RB树的变体,即左leleleing red-black(LLLRB)树,其中红树仅限于左翼儿童,并提议简洁的循环插入和删除算法。然而,LLRBR的自上而下的删除算法仍然非常复杂和低效率。 在本文中,我们重新考虑了2-3的红树,因为插入算法中的两个子都不能红色。我们提出了一种对等式的算法,其基本想法是将不完善的删除子树与比平级(RB)数字相近:要么是修补小树,要么将精细的递减为精选为精细的平级的平级的平级算, 将树的递增为正值,作为正正统的正统的树的比为正统的正统的正统的两倍。