A red-black tree is a binary search tree with one extra attribute for each node:Red-Black Trees: These are binary trees with the following properties.
the colour, which is either red or black.
An n node red/black tree has the property that its height is O(lg(n)).
- Every node has a value.
- The value of any node is greater than the value of its left child and less than the value of its right child.
- Every node is colored either red or black.
- The root is black.
- Every leaf (NULL) is black.
- If a node is red, then both its children are black.
- Every path from the root to a leaf contains the same number of black nodes.
There are some other balanced tree structures: AVL-trees, and B-trees.
Maintaining the storage and keeping balance of tree:
CODES from Ford & Topp:
Using the RBTREE Class RBTREE
Class
Exercise from Ford & Topp:
Consider the following insertion sequence:
15, 55, 28, 45, 32, 40, 35, 38, 36, 37
(a) Draw the corresponding binary search tree
(b) Draw a red-black tree that corresponds to the data.
Click here for the solution.