chap13-solutions - Selected Solutions for Chapter 13:...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Selected Solutions for Chapter 13: Red-Black Trees Solution to Exercise 13.1-4 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.1-5 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.3-3 In Figure 13.5, nodes A , B , and D have black-height k C 1 in all cases, because each of their subtrees has black-height k and a black root. Node C has black- height k C 1 on the left (because its red children have black-height k C 1 ) and black-height k C 2 on the right (because its black children have black-height k C 1 ).
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
13-2 Selected Solutions for Chapter 13: Red-Black 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 black-height k C 1 in all cases. At left and in the middle, each of A ’s and B ’s subtrees has black-height k and a black root, while C has one such subtree and a red child with black-height k C 1 . At the right, each of A ’s and C ’s subtrees has black-height k and a black root, while B ’s red children each have black-height 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 black-height is well-defined 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 k C 2 black nodes.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 5

chap13-solutions - Selected Solutions for Chapter 13:...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online