Skip to main content
Log in

Revisiting 2–3 red–black trees with a pedagogically sound yet efficient deletion algorithm: parity-seeking

  • Original Article
  • Published:
Acta Informatica Aims and scope Submit manuscript

Abstract

Red–black (RB) trees are one of the most efficient variants of balanced binary search trees. However, they have often been criticized for being too complicated, hard to explain, and unsuitable for pedagogical purposes, particularly their delete operation. Sedgewick (in: Dagstuhl Workshop on Data Structures, 2008. https://sedgewick.io/wp-content/themes/sedgewick/papers/2008LLRB.pdf) identified the length of code as the root of the problems and introduced left-leaning red–black (LLRB) trees. The delete operation of LLRB trees has a compact recursive code. Unfortunately, it may perform many unnecessary operations. The crux of the deletion algorithm is dealing with a “deficient” subtree, that is one whose black-height has become one less than that of its sibling subtree. In this paper, we revisit 2–3 red–black trees and propose a parity-seeking delete algorithm with the basic idea of making a 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 also works for 2–3–4 RB trees. Our experiments show that the proposed parity-seeking delete algorithm is as efficient as the best preceding RB trees. The proposed parity-seeking delete algorithm is easily understandable and suitable for pedagogical and practical purposes.

This is a preview of subscription content, log in via an institution to check access.

Access this article

Price excludes VAT (USA)
Tax calculation will be finalised during checkout.

Instant access to the full article PDF.

Fig. 1
Fig. 2
Fig. 3
Fig. 4
Fig. 5
Fig. 6
Fig. 7
Fig. 8
Fig. 9
Fig. 10
Fig. 11
Fig. 12
Fig. 13
Fig. 14
Fig. 15
Fig. 16
Fig. 17
Fig. 18
Fig. 19
Fig. 20
Fig. 21

Similar content being viewed by others

Notes

  1. Before, with the same goal of having simple code, Andersson [1] had considered “right-leaning” binary versions of 2–3 trees, in which only right links can connect nodes of the same level.

  2. We have visualized the steps taken by each variant of RB trees on randomly inserting and deleting 30 numbers. This visualization is available at https://k-ghiasi.github.io/RedBlackTrees/doc/index.html.

  3. We can also define the root deficient when its black-height has become one less than its value before deletion started. However, the two definitions are equivalent since the root would be red at that time.

  4. We borrowed this view from Sedgewick [17].

  5. Alternatively, one can choose the smallest value in the right subtree.

  6. In place of a deficient node, [9] introduced the notion of an “extra” black for the node x. Here, we use the notion of a deficient subtree to state the same concept.

  7. We remind the reader that the root node, or the whole tree, is defined to be deficient if the tree is balanced and the root is red.

  8. Note: Case (b) might look complicated, but conceptually it is simple. The path “g-p-x” has four subtrees of the same black-height, all with black roots (see Fig. 18b.1, b.2). Applying one or two rotations changes this path into a configuration with one root, two children, and the four subtrees. The root is colored black, and its two children are colored red, and we are done.

  9. Note: Again, case (b) might look complicated, but conceptually it is simple. The path “g-p-x” has four subtrees of the same black-height, all with black roots (Fig. 20b.1, b.2). Applying one or two rotations changes this path into a configuration with one root, two children, and the four subtrees. The root and its two children are colored black, and the root is the new overfull node with which the iteration is continued.

  10. The equality of the number of top–down visits is clear.

  11. https://algs4.cs.princeton.edu/33balanced/RedBlackBST.java.html.

  12. To see how this happens in an example, compare page 66 of https://k-ghiasi.github.io/RedBlackTrees/doc/2-3-psrbt-insert-images.pdf and page 62 of https://k-ghiasi.github.io/RedBlackTrees/doc/clrs-insert-images.pdf.

References

  1. Andersson, A.: Balanced search trees made simple. In: Workshop on Algorithms and Data Structures. Springer, pp. 60–71 (1993) https://doi.org/10.1007/3-540-57155-8_236

  2. Andersson, A., Icking, C., Klein, R., et al.: Binary search trees of almost optimal height. Acta Inform. 28(2), 165–178 (1990). https://doi.org/10.1007/BF01237235

    Article  MathSciNet  Google Scholar 

  3. Bayer, R,: Binary B-trees for virtual memory. In: Proceedings of the 1971 ACM SIGFIDET (now SIGMOD) Workshop on Data Description, Access and Control, pp. 219–235 (1971). https://doi.org/10.1145/1734714.1734731

  4. Bayer, R.: Symmetric binary B-trees: Data structure and maintenance algorithms. Acta Inform. 1(4), 290–306 (1972). https://doi.org/10.1007/BF00289509

    Article  MathSciNet  Google Scholar 

  5. Bayer, R., McCreight, E.: Organization and maintenance of large ordered indices. In: Proceedings of the 1970 ACM SIGFIDET (now SIGMOD) Workshop on Data Description, Access and Control, pp. 107–141 (1970). https://doi.org/10.1145/1734663.1734671

  6. Bayer, R., McCreight, E.: Organization and maintenance of large ordered indexes. Acta Inform. 1(3), 173–189 (1972). https://doi.org/10.1007/BF00288683

    Article  Google Scholar 

  7. Besa, J., Eterovic, Y.: A concurrent red–black tree. J. Parallel Distrib. Comput. 73(4), 434–449 (2013). https://doi.org/10.1016/j.jpdc.2012.12.010

    Article  Google Scholar 

  8. Boyar, J., Larsen, K.S.: Efficient rebalancing of chromatic search trees. J. Comput. Syst. Sci. 49(3), 667–682 (1994). https://doi.org/10.1016/S0022-0000(05)80075-3

    Article  MathSciNet  Google Scholar 

  9. Cormen, T.H., Leiserson, C.E., Rivest, R.L., et al.: Introduction to Algorithms. MIT Press, Cambridge (2009)

    Google Scholar 

  10. Germane, K., Might, M.: Deletion: the curse of the red–black tree. J. Funct. Program. 24(4), 423–433 (2014). https://doi.org/10.1017/S0956796814000227

    Article  MathSciNet  Google Scholar 

  11. Guibas, LJ., Sedgewick, R.: A dichromatic framework for balanced trees. In: 19th Annual Symposium on Foundations of Computer Science (1979), IEEE, pp. 8–21 (1978). https://doi.org/10.1109/SFCS.1978.3

  12. Howard, P.W., Walpole, J.: Relativistic red–black trees. Concurr. Comput. Pract. Exp. 26(16), 2684–2712 (2014). https://doi.org/10.1002/cpe.3157

    Article  Google Scholar 

  13. Larsen, K.S.: Relaxed red–black trees with group updates. Acta Inform. 38(8), 565–586 (2002). https://doi.org/10.1007/s00236-002-0086-3

    Article  MathSciNet  Google Scholar 

  14. Okasaki, C.: Red–black trees in a functional setting. J. Funct. Program. 9(4), 471–477 (1999). https://doi.org/10.1017/S0956796899003494

    Article  Google Scholar 

  15. Park, H., Park, K.: Parallel algorithms for red–black trees. Theor. Comput. Sci. 262(1–2), 415–435 (2001). https://doi.org/10.1016/S0304-3975(00)00287-5

    Article  MathSciNet  Google Scholar 

  16. Roura, S.: Fibonacci BSTs: a new balancing method for binary search trees. Theor. Comput. Sci. 482, 48–59 (2013). https://doi.org/10.1016/j.tcs.2012.11.027

    Article  MathSciNet  Google Scholar 

  17. Sedgewick, R.: Left-leaning red–black trees. In: Dagstuhl Workshop on Data Structures, p. 17 (2008). https://sedgewick.io/wp-content/themes/sedgewick/papers/2008LLRB.pdf

  18. Sen, S., Tarjan, R.E., Kim, D.H.K.: Deletion without rebalancing in binary search trees. ACM Trans. Algorithms 12(4), 1–31 (2016). https://doi.org/10.1145/2903142

    Article  MathSciNet  Google Scholar 

  19. Wayne, K., Sedgewick, R.: Algorithms, part I. (2012). https://www.coursera.org/learn/algorithms-part1

Download references

Acknowledgements

The authors are deeply grateful to the anonymous reviewers for generously devoting their precious time to improving this paper and giving constructive valuable comments that highly improved the quality of the manuscript.

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Kamaledin Ghiasi-Shirazi.

Ethics declarations

Conflict of interest

The authors have no relevant financial or non-financial interests to disclose.

Additional information

Publisher's Note

Springer Nature remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.

Rights and permissions

Springer Nature or its licensor (e.g. a society or other partner) holds exclusive rights to this article under a publishing agreement with the author(s) or other rightsholder(s); author self-archiving of the accepted manuscript version of this article is solely governed by the terms of such publishing agreement and applicable law.

Reprints and permissions

About this article

Check for updates. Verify currency and authenticity via CrossMark

Cite this article

Ghiasi-Shirazi, K., Ghandi, T., Taghizadeh, A. et al. Revisiting 2–3 red–black trees with a pedagogically sound yet efficient deletion algorithm: parity-seeking. Acta Informatica (2024). https://doi.org/10.1007/s00236-023-00452-6

Download citation

  • Received:

  • Accepted:

  • Published:

  • DOI: https://doi.org/10.1007/s00236-023-00452-6

Navigation