Link

Red-Black Trees Study Guide

Tree rotations. We rotateLeft or rotateRight on a node, creating a different but valid BST with the same elements. Notice when we rotateLeft(G), the node G becomes the left child of the new root.

Left-Leaning Red Black Tree. Implements a 2-3 Tree as a BST with rotations and recoloring. Be able to convert between a 2-3 Tree and a LLRB tree. We use red links to indicate two nodes that would be in the same 2-3 Node. In a left-leaning red-black tree, we arbitrarily enforce that the tree is left-leaning.

  • Perfect black balance. Every root-to-leaf path has the same number of black links.
  • Left-leaning. Red links lean left.
  • Color invariant. No node has two red links connected to it, either above/below or left/right.

1-1 correspondence between LLRBs and 2-3 trees. Understand how to map a 2-3 tree to an LLRB and vice versa.

LLRB Operations. Always insert with a red link at the correct location. Then use the following three operations to fix the LLRB tree.

  1. If there is a right leaning red link, rotate that node left.
  2. If there are two consecutive left leaning links, rotate right on the top node.
  3. If there is a node with two red links to children, flip all links with that node.
  1. Given an LLRB, is there exactly one corresponding 2-3 tree? Given a 2-3 tree, is the exactly one corresponding LLRB?
  2. Draw a 2-3 tree with all 3 nodes. Why is the height log3(N)?
  3. How many compares does it take in the worst case to decide whether to take the left, middle, or right link from a 3 node?
  4. For a 2-3 tree of height H, what is the best case number of compares to find a key? The worst case?
  5. Show that in the worst case, we need to perform order log N LLRB operations (rotation and color flipping) after an insert. Give an example of a tree which requires log N LLRB operations after a single insert.

  6. Q4b from CS 61B 15sp MT2
  7. Q5 from CS 61BL 16su MT2 (LLRB Tree only)
  8. Q1b, Q1d from CS 61B 18sp MT2
  9. Q3a from CS 61BL 18su MT3
  10. Q4 from CS 61B 19sp MT2
  11. Q1 from CS 61BL 19su MT2