The Efficiency of Red-Black Trees
Because a red-black tree is a type of binary search tree, the search operation is O(log N), as is true for all BSTs. As I discussed in Volume 1, Chapter 15, this is because there are log N levels in a BST, and at most, we will search one node from each level in the BST until we find the value we’re searching for. I also discussed there that insertion for a regular BST is O(log N), as we must first perform a search to find the appropriate spot to insert the new node, and the actual insertion is one step.
It turns out that insertion in a red-black tree is also O(log N). Now, there are certainly more steps involved with insertion into a red-black tree than there are with a regular BST. However, it’ll add up to ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access