A red–black tree is a type of self-balancing binary search tree, a data structure used in computer science. It is complex, but has good worst-case running time for its operations and is efficient in practice: it can search, insert, and delete in
- every node is either red or black;
- the root is black;
- every leaf (
$NIL$ ) is black; - if a node is red, then its children are black;
- for each node
$x$ , all the simple paths from x to descendant leaves contains the same number of black nodes.