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
Example Red-Black Tree loaded. Choose an operation.
Nodes0
Height0
Black height0
Rotations0
Operation path
—
Balancing events
- 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
| Operation | Purpose |
|---|---|
| Rotate left | Convert a right-leaning red link into a left-leaning link. |
| Rotate right | Repair two consecutive left red links. |
| Flip colors | Split or combine a temporary 4-node. |
| Move red left/right | Prepare a minimally colored subtree for safe deletion. |