O'Reilly logo

Learning Functional Data Structures and Algorithms by Raju Kumar Mishra, Atul Khot

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required