Chapter 11.  Red-Black Trees

In the previous chapter, we touched upon concepts such as amortization and balance in data structures. We need to balance the data structure so it does not degenerate. For example, in a Binary Search Tree (BST), if we insert elements that are already sorted, we get a tree, which is a linked list.

Red-Black Trees

This is highly undesirable if we need a strong guarantee with respect to lookup complexity. Note that the insertion complexity is also O(n).

The solution is to balance the tree so things don't get out of hand. For example, if we could somehow ensure that the height of our tree is O(logn) for any data set, then we will have ...

Get Learning Functional Data Structures and Algorithms now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.