← Back

Red-Black Tree Simulator

What is a Red-Black Tree?

A Red-Black Tree is a self-balancing Binary Search Tree. Node colors and local rotations keep every root-to-leaf path within a constant factor of the shortest path, guaranteeing logarithmic search, insertion, and deletion.

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 the 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, a compact form equivalent to a 2–3 tree.

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.