Red-Black Tree Simulator

A Red-Black Tree is a self-balancing Binary Search Tree. This simulator uses the Left-Leaning Red-Black (LLRB) representation, where red links encode 3-nodes and local rotations plus color flips preserve logarithmic height.

SearchO(log n)
InsertO(log n)
DeleteO(log n)
Maximum height≤ 2 log₂(n + 1)

Tree operations

400 ms

Example Red-Black Tree loaded. Choose an operation.

Nodes0
Height0
Black height0
Rotations0

Operation path

—

Balancing events

  1. No balancing event yet.

Left-Leaning Red-Black repair rules

if right link is red:
  rotate left

if node and left child are red:
  rotate right

if both children are red:
  flip colors

during deletion:
  move a red link toward the target
  delete using BST order
  restore invariants on return

Red-Black properties

Black root

The root is always black. The simulator enforces this after every insertion and deletion.

No red-red edge

A red node cannot have a red child. Rotations and color flips remove consecutive red links.

Equal black height

Every path from a node to a missing child contains the same number of black nodes.

Left-leaning representation

This implementation represents 3-nodes using left-leaning red links, which is equivalent to a 2–3 tree representation.

Balancing operations

OperationPurpose
Rotate leftConvert a right-leaning red link into a left-leaning link.
Rotate rightRepair two consecutive left red links.
Flip colorsSplit or combine a temporary 4-node.
Move red left/rightPrepare a minimally colored subtree for safe deletion.