Red Black Trees
Insertion
Red Aunt
- Swap the colors of the parent, aunt, & grandparent
- Check for red-child violations
Black Aunt Aligned
- Rotate parent & grandparent
- Swap colors of parent & grandparent
Black Aunt Not Aligned
- Rotate parent & grandparent (don't recolor)
- Rotate new parent & grandparent
- Recolor parent & grandparent
Deletion
Black Sibling & Black Niece
- Recolor sibling
- Move Black Marker up one
- If the parent is red, recolor and resolve Black Marker
- If the parent is black, continue resolving (looking at the parent node's sibling)
- If the parent is the root, resolve the Black Marker
Black Sibling & Red Niece
- If Sibling and Red Niece are NOT aligned then rotate & recolor them
- Rotate the parent & sibling
- Recolor the parent, sibling, & niece
Red Sibling
- Rotate & recolor the parent & sibling
- Continue to resolve the Black Marker with the new tree configuration
For more information, visit UW Madison's page on Red Black Trees