Red-black trees - Department of Computer Science

advertisement
Red-black trees
Prof. Sin-Min Lee
Department of Computer Science
1. Red-black trees: a binary tree representation of 2-3-4
trees.
•
Definition: Red-black trees are binary search trees with
each node colored red or black and satisfying the
following properties:
i.
Root property: The root is black.
ii. External property: All external nodes are black.
iii. Internal property: The children of red nodes are black.
iv. Depth property: All external nodes have the same black
depth. The black depth is the number of black ancestors
minus one, or the number of black links from the root to
the node.
Red-black trees
• Red-black trees are an important data
structure but their combinatorial properties
are not much studied. They were introduced
by R. Bayer ("Symmetric binary B-trees:
Data structures and maintenance
algorithms", Acta Informatica, 1 (1972)
290-306).
• From a combinatorial point of view, a red-black
tree is an extended binary tree (every node has two
children or is a leaf) which satisfies the following
properties.
• Every node is colored either red or black.
• Every leaf node is colored black.
• If a node is red, then both of its children are black.
• Every path from the root to a leaf contains the
same number of black nodes. This number is
called the black-height of the tree.
Example
If Th(x) is the ordinary generating function of the number of
red-black trees of black-height h, classified by the number of
leaves, then T1(x) = x + x2 and for h > 0,
Th+1(x) = [Th(x)]2 + [Th(x)]4.
If T(x) is the ordinary generating function of the number of red-black
trees, then T(x) = x + x2 + T(x2(1+x)2). If rb(n) is the
number of red-black trees with n leaves then rb(1) = 1, rb(2) = 2,
and for n > 2,
--\ / 2m \
rb(n) = | |
| rb(m)
/ \ n-2m /
--n/4 <= m <= n/2
The number of red-rooted and black-rooted trees satisfies the same
recurrence relation, but the initial conditions are different.
For red-rooted trees, r(1) = r(3) = 0, and r(2) = 1. For black-rooted
trees, b(1) = 1.
Download