Selected Solutions for Chapter 13:
RedBlack Trees
Solution to Exercise 13.14
After absorbing each red node into its black parent, the degree of each node black
node is
±
2, if both children were already black,
±
3, if one child was black and one was red, or
±
4, if both children were red.
All leaves of the resulting tree have the same depth.
Solution to Exercise 13.15
In the longest path, at least every other node is black. In the shortest path, at most
every node is black. Since the two paths contain equal numbers of black nodes, the
length of the longest path is at most twice the length of the shortest path.
We can say this more precisely, as follows:
Since every path contains bh
.x/
black nodes, even the shortest path from
x
to a
descendant leaf has length at least bh
.x/
. By definition, the longest path from
x
to a descendant leaf has length height
.x/
. Since the longest path has bh
.x/
black
nodes and at least half the nodes on the longest path are black (by property 4),
bh
.x/
±
height
.x/=2
, so
length of longest path
D
height
.x/
²
2
³
bh
.x/
²
twice length of shortest path
:
Solution to Exercise 13.33
In Figure 13.5, nodes
A
,
B
, and
D
have blackheight
k
C
1
in all cases, because
each of their subtrees has blackheight
k
and a black root.
Node
C
has black
height
k
C
1
on the left (because its red children have blackheight
k
C
1
) and
blackheight
k
C
2
on the right (because its black children have blackheight
k
C
1
).
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
132
Selected Solutions for Chapter 13: RedBlack Trees
C
D
A
B
α
β
γ
δ
ε
(a)
C
D
A
B
α
β
γ
δ
ε
C
D
B
δ
ε
C
D
B
A
α
β
γ
δ
ε
(b)
A
α
β
γ
k
+1
k
+1
k
+1
k
+1
k
+1
k
+2
k
+1
k
+1
k
+1
k
+1
k
+1
k
+1
k
+1
k
+1
k
+2
k
+1
z
y
z
y
In Figure 13.6, nodes
A
,
B
, and
C
have blackheight
k
C
1
in all cases. At left and
in the middle, each of
A
’s and
B
’s subtrees has blackheight
k
and a black root,
while
C
has one such subtree and a red child with blackheight
k
C
1
. At the right,
each of
A
’s and
C
’s subtrees has blackheight
k
and a black root, while
B
’s red
children each have blackheight
k
C
1
.
C
A
B
α
β
γ
δ
Case 2
B
A
α
β
γ
δ
Case 3
A
B
C
α
β
γ
δ
C
k
+1
k
+1
k
+1
k
+1
k
+1
k
+1
k
+1
k
+1
k
+1
z
y
z
y
Property 5 is preserved by the transformations.
We have shown above that the
blackheight is welldefined within the subtrees pictured, so property 5 is preserved
within those subtrees. Property 5 is preserved for the tree containing the subtrees
pictured, because every path through these subtrees to a leaf contributes
This is the end of the preview.
Sign up
to
access the rest of the document.
 Spring '10
 .
 Redblack tree, Persistent data structure

Click to edit the document details