For the complete documentation index, see llms.txt. This page is also available as Markdown.

13. Red-Black Trees

Exercises

13.1-1

Red-black tree with black-height 2. The image was produced with the Data Structure Visualizations tool.

If you color nodes 4 and 12 into black (children of the root node 8), then the resulting tree will have black-height of 3. If you color all nodes into black, then you will get a tree with black-height 4.

13.1-2

The node 36 would be placed as the right child of red node 35 in Figure 13.1 (see the book). Exercise 13.1-8 explains why this cannot be a legal red-black tree.

Correct red-back tree after inserting node 36 into the tree from Figure 13.1 (see Section 13.3 in the book). The image was produced with the Data Structure Visualizations tool.

13.1-3

Available in the latest revision of the IM.

13.1-4

Available in the latest revision of the IM.

13.1-5

Available in the latest revision of the IM.

13.1-6

Available in the latest revision of the IM.

13.1-7

Available in the latest revision of the IM.

13.1-8

Available in the latest revision of the IM.

13.2-1

Available in the latest revision of the IM.

13.2-2

Available in the latest revision of the IM.

13.2-3

Available in the latest revision of the IM.

13.2-4 🌟

Available in the latest revision of the IM.

★ 13.2-5

Available in the latest revision of the IM.

13.3-1

Available in the latest revision of the IM.

13.3-2

Use the Data Structure Visualizations tool and watch the resulting tree as you insert the nodes. You can adjust the animation speed to clearly see the re-colorings and rotations.

13.3-3

Available in the latest revision of the IM.

13.3-4

Available in the latest revision of the IM.

13.3-5

Available in the latest revision of the IM.

13.3-6

Observe that all nodes accessed via parent pointers in RB-Insert-Fixup are exactly those that are encountered by RB-Insert while finding the location for the new node. Therefore, RB-Insert should store them in a stack, initialized with the sentinel T.nil. RB-Insert-Fixup would pop and push nodes from this stack, as needed. The procedures for rotations would also need to have access to this stack.

The size of this stack will be commensurate with the height of the RB tree, which is O(lg⁡n)O(\lg n). Pushing and popping nodes execute in O(1)O(1) time, so the asymptotic runtime of RB-Insert would remain the same.

13.4-1

Available in the latest revision of the IM.

13.4-2

Available in the latest revision of the IM.

13.4-3

Available in the latest revision of the IM.

13.4-4

Create the initial red-black tree according to Exercise 13.3-2. Use the Data Structure Visualizations tool and watch the resulting tree as you successively delete nodes. You can adjust the animation speed to clearly see the re-colorings and rotations.

13.4-5

Available in the latest revision of the IM.

13.4-6

Each row (in order) designates the corresponding case 1-4 from Figure 13.7. Each count remains the same after the transformation (see also the book's explanation for case 2 about xx pointing to a node with color cc).

⍺
β
ɣ
𝛿
𝜀
𝜁

3

3

2

2

2

2

2+count(c)

2+count(c)

2+count(c)

2+count(c)

2+count(c)

2+count(c)

2+count(c)

2+count(c)

1+count(c)

1+count(c)

2+count(c)

2+count(c)

2+count(c)

2+count(c)

1+count(c) +count(c')

1+count(c) +count(c')

1+count(c)

1+count(c)

13.4-7

Available in the latest revision of the IM.

13.4-8

Available in the latest revision of the IM.

★ 13.4-9

Available in the latest revision of the IM.

Problems

13-1 Persistent dynamic sets

Available in the latest revision of the IM.

13-2 Join operation on red-black trees

Available in the latest revision of the IM.

13-3 AVL trees

Available in the latest revision of the IM.

Last updated