Introduction
This set of notes in intended to clarify (possibly simplify) some of our previous
discussions about redblack trees.
Clearly, the most difficult concept regarding
redblack trees is the rebalancing that occurs after insertion or deletion in the
tree.
This set of notes will focus only on these aspects of redblack trees; see
the original set of notes for other details regarding this data structure.
Definition and Example for Reference
A redblack tree is defined as:
1.
A binary search tree.
2.
The root and all external nodes are colored black.
3.
No roottoexternalnode path has two consecutive red nodes.
4.
All roottoexternalnode paths have the same number of black nodes.
Figure 1 illustrates an example redblack tree.
Figure 1 – A redblack tree
Notice that the tree in Figure 1 satisfies all of the properties of a redblack tree.
Namely, (1) it is a BST, (2) the root and all external nodes are colored black, (3)
no roottoexternalnode path has two consecutive red nodes, and (4) all rootto
externalnodes paths contain the same number of black nodes; two in this
RedBlack Trees Revisited 
1
Advanced Tree Structures – RedBlack Trees Revisited (8)
6
5
5
0
8
0
7
0
6
0
1
0
5
6
2
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
example.
(Applying the alternate definition we have:
every path from the root to
an external node has exactly two black pointers and three black nodes
(including the root and the external node); and no such path has two
consecutive red pointers.)
Insertion into a RedBlack Tree
Recall from our earlier discussions that a new node, upon insertion, is colored
red
.
This is because insertion of a new black node is guaranteed to cause a
violation of property #3.
Since all new nodes are initially red nodes, this leads
to a total of eight different insertion situation in which an imbalance in the tree
can occur.
Recall that not all insertions of red node will cause an imbalance.
The imbalances that can occur due to an insertion can be categorized into two
categories depending upon the configuration of the existing tree into which the
insertion occurs.
Let’s assume that
u
is the newly inserted red node,
pu
is its
parent, and
gu
is the grandparent of
u
and the parent of
pu
.
Since we know that
the tree in which the insertion is to take place is a valid redblack tree we know
that all four of the properties for redblack trees hold.
We also know that any
insertion is occurring as a new leaf node (not counting the external nodes).
This
means that the subtree in which the insertion is occurring is already balanced
and if the insertion causes it to become imbalanced it can do so no further than
two levels above the new node in the tree, i.e., at its grandparent level.
Therefore, since the imbalance occurs (if it occurs at all) within the subtree
rooted at the grandparent then we need to be concerned with the color of the
grandparents’ other child (the child of
gu
which is not
pu
).
If the other child of
gu
is
red
there are four cases to consider:
LRr, LLr, RRr,
and
RLr
.
Each of
these four types of imbalances is shown in Figure 2.
This is the end of the preview.
Sign up
to
access the rest of the document.
 Summer '09
 Computer Science, Redblack tree, Selfbalancing binary search tree, imbalance

Click to edit the document details