Computer ScienceData StructuresMedium

Red-Black Tree

Also known as:RB-treeSymmetric binary B-tree

A red-black tree is a self-balancing binary search tree in which each node carries an extra bit of information — its color (red or black) — and the tree satisfies a set of coloring rules that ensure the tree remains approximately balanced. Introduced by Rudolf Bayer in 1972 and further developed by Leonidas Guibas and Robert Sedgewick in 1978, it guarantees O(log n) worst-case performance for search, insert, and delete. Red-black trees are widely used in language standard libraries, including C++ STL's map and Java's TreeMap.

Red-Black Tree Properties and Rules

RuleDescriptionImplication
Rule 1Every node is red or blackBinary coloring constraint
Rule 2Root is always blackEstablishes tree anchor
Rule 3Red nodes cannot have red childrenNo two consecutive reds
Rule 4All paths from node to leaves have equal black-heightEnsures balance
Rule 5Null leaves are considered blackSimplifies rule 4 checking

Interactive Tools

CS USF — Red-Black Tree Visualization

Open Tool

Visualgo — Red-Black Tree

Open Tool

Brilliant.org — Red-Black Trees

Open Tool
A red-black tree with nodes colored red or black following the balancing rules

Wikimedia Commons, CC BY-SA

Related Terms

The term "red-black tree" was coined by Leonidas Guibas and Robert Sedgewick in 1978. The choice of colors is said to be due to the red and black pens available on a laser printer at the time, though some sources attribute it to aesthetic preference. Rudolf Bayer originally called the structure a "symmetric binary B-tree" in 1972.

red-blackbalanced-treeself-balancingdata-structurebstalgorithms