Left-Leaning 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 edges to indicate two nodes that would be in the same 3-node (node with 2 keys and 3 non-null children). In a left-leaning red-black tree, we arbitrarily enforce that the tree is left-leaning.

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

LLRB Operations. Always recursively insert with a red edge at the correct location. Then use the following three operations to fix the LLRB tree before leaving each recursive call.

  1. If there is a right red edge and a left black edge, rotate that node left.
  2. If there are two consecutive right left edges, rotate right on the top node.
  3. If there is a node with two red edges to both children, flip the colors of all edges touching that node.
  1. Q3b, Q3d from CSE 373 19au MT (Solution)
  2. Q2d from CSE 373 19au Final (Solution)
  3. Q1b, Q1d from CS 61B 18sp MT2 (Solution)