Red-Black Tree Insertion
Inserting a new node into a red-black tree is considerably more complicated than inserting a node into a classic BST. We can’t just plop the node into its correct spot; we also need to ensure that the tree follows the Red-Black Rules.
The first thing to know about red-black tree insertion is that the node we insert always starts out colored red. The reason for this will become apparent soon.
The second thing to know is that we insert a new node into a red-black tree in up to two phases. The first phase is virtually identical to a classic BST insertion. That is, we start at the root and move down through the tree searching for the correct spot to insert the new node based on its value. This follows the BST rule previously ...
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