red-black trees prof. sin-min lee department of computer science

26
Red-black trees Prof. Sin-Min Lee Department of Computer Science

Upload: byron-richard

Post on 31-Dec-2015

212 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Red-black trees Prof. Sin-Min Lee Department of Computer Science

Red-black trees

Prof. Sin-Min Lee

Department of Computer Science

Page 2: Red-black trees Prof. Sin-Min Lee Department of Computer Science
Page 3: 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.

Page 4: Red-black trees Prof. Sin-Min Lee Department of Computer Science

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).

Page 5: Red-black trees Prof. Sin-Min Lee Department of Computer Science

• 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.

Page 6: Red-black trees Prof. Sin-Min Lee Department of Computer Science

Example

Page 7: Red-black trees Prof. Sin-Min Lee Department of Computer Science
Page 8: Red-black trees Prof. Sin-Min Lee Department of Computer Science
Page 9: Red-black trees Prof. Sin-Min Lee Department of Computer Science
Page 10: Red-black trees Prof. Sin-Min Lee Department of Computer Science
Page 11: Red-black trees Prof. Sin-Min Lee Department of Computer Science
Page 12: Red-black trees Prof. Sin-Min Lee Department of Computer Science
Page 13: Red-black trees Prof. Sin-Min Lee Department of Computer Science
Page 14: Red-black trees Prof. Sin-Min Lee Department of Computer Science
Page 15: Red-black trees Prof. Sin-Min Lee Department of Computer Science
Page 16: Red-black trees Prof. Sin-Min Lee Department of Computer Science

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 thenumber 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/2The 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.

Page 17: Red-black trees Prof. Sin-Min Lee Department of Computer Science
Page 18: Red-black trees Prof. Sin-Min Lee Department of Computer Science
Page 19: Red-black trees Prof. Sin-Min Lee Department of Computer Science
Page 20: Red-black trees Prof. Sin-Min Lee Department of Computer Science
Page 21: Red-black trees Prof. Sin-Min Lee Department of Computer Science
Page 22: Red-black trees Prof. Sin-Min Lee Department of Computer Science
Page 23: Red-black trees Prof. Sin-Min Lee Department of Computer Science
Page 24: Red-black trees Prof. Sin-Min Lee Department of Computer Science
Page 25: Red-black trees Prof. Sin-Min Lee Department of Computer Science
Page 26: Red-black trees Prof. Sin-Min Lee Department of Computer Science