" Red Black Trees

Definition

A Red Black Tree is a self-balancing binary search tree where each node is designated as either red or black.

Properties

Visual Representation

Red Black Tree Example

Example of a valid Red-Black Tree

Basic Operations

Insertion

When inserting a node:

  1. Insert like a regular BST
  2. Color the new node red
  3. Recolor and rotate as needed to rebalance

Deletion

When deleting a node:

  1. Perform a standard BST deletion
  2. Perfom color repairs
  3. Rebalance the tree based on new colors

A more in-depth tutorial of performing operations on a Red-Black Tree can be found here.

Time Complexities

Operation Average Case Worst Case
Access O(log n) O(log n)
Insert O(log n) O(log n)
Delete O(log n) O(log n)